Rails 2.2.2, Shoulda 2.9.1, Factory Girl 1.2.0
The default test:
context 'PUT to update for existing survey' do
setup do
@survey = Factory(:survey)
put :update, :id => @survey.to_param,
:survey => Factory.attributes_for(:survey)
end
should_set_the_flash_to /updated/i
should_redirect_to 'surveys_path'
end
Fails with:
3) Failure:
test: PUT to update for existing survey should redirect to surveys_path. (SurveysControllerTest)
[/Library/WebServer/Documents/radmatch/vendor/plugins/shoulda/lib/shoulda/action_controller/macros.rb:239:in `__bind_1236625179_419089'
/Library/WebServer/Documents/radmatch/vendor/plugins/shoulda/lib/shoulda/context.rb:253:in `call'
/Library/WebServer/Documents/radmatch/vendor/plugins/shoulda/lib/shoulda/context.rb:253:in `test: PUT to update for existing survey should redirect to surveys_path. '
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/testing/setup_and_teardown.rb:60:in `__send__'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/testing/setup_and_teardown.rb:60:in `run']:
Expected response to be a redirect to <http://test.host/surveys> but was a redirect to <http://test.host/surveys/3000>.
It seems like the expected redirection url doesn't have the ID in it, where the returned URL does. But i may be missing something obvious!
An older version of Coulda generated this test for my staff controller a few days ago:
context 'PUT to update' do
setup do
@staff = Factory(:staff)
put :update, :id => @staff.staff_id, :staff => Factory.attributes_for(:staff)
end
should_redirect_to 'staff_path(@staff)'
end
This test runs fine (passes) in my environment.
And there the (@staff) is included leading me to believe it would also be needed in the tests of my survey controller.