开发者

Rspec newbie: Quick example of nested controller test?

I'm just starting out with RSpec and having a little difficulty writing up controller tests for nested resources. I've tried googling this, but without much luck.

Could someone offer a basic example of a "PUT update" test test ensures a nested resource is updated? Just to elaborate, I have the equivalent (non-nested) resource tested like this:

  def mock_post(stubs={})
    @mock_post ||= mock_model(Post, stubs).as_null_object
  end
  ...

  describe "PUT update" do
      describe "with valid parameters" do
        it "updates the requested post" do
          Post.stub(:find).with("14") { mock_post }
          mock_post.should_receive(:update_attributes).with({'these' => 'params'})
          put :update, :id => "14", :post => {'these' => 'params'}
    开发者_如何学编程    end
      end
  end

I've been trying for some time to correctly stub a similar test for a 'Comment' model which is nested under Post, but no joy. Any suggestions appreciated.


You'll need to have both id's passed to your put method

put :update, :id => "14", :post_id=> "1", :comment => {'these' => 'params'}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜