0

I've just upgraded to Rails 4, and I have started using strong parameters over protected attributes. I typically tested a models protected attributes using unit tests, but I am unsure how to test now that this functionality has been moved to the controller.

I am using rspec for testing. Any advice would be great.

1 Answer 1

3

Why not just do

post :create, model: { someattrs }
response.response_code.should == 400

In your controller spec?

Sign up to request clarification or add additional context in comments.

2 Comments

This is what I will likely do. I am just curious if there are any established best practices out there. Thanks for the answer.
@Max Strong params are controller behavior, this is generally the best practice in testing response from controllers. Also check out edgeapi.rubyonrails.org/classes/ActionController/…, where it says that the strong params should return 400 errors. Seems like the best way to test it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.