Rspec novice: quick example test of a nested controller?

I am just starting to work with RSpec and have difficulty writing controller tests for embedded resources. I tried this, but without much success.

Can someone suggest a basic example of the test test "PUT update", will provide an update of the attached resource? To clarify, I have an equivalent (non-nested) resource, tested as follows:

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 have been trying for some time to correctly drown out a similar test for the "Comment" model, which is embedded in Post, but without joy. Any suggestions appreciated.

+7
source share
1 answer

You will need to pass both identifiers to put method

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

All Articles