What is the actual strategy to test strong params filtering in Rails controller with Rspec? (Except shoulda matchers) How to write failing test and then make it green?
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Strong parameter override for DeviseTokenAuth cont
- Mechanize getting “Errno::ECONNRESET: Connection r
- Eager-loading association count with Arel (Rails 3
相关文章
- Ruby using wrong version of openssl
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
Create 2 hashes with expected and all (with unsatisfied) parameters. Then pass all params to action and check that you object model receiving only expected params. It will not if you are not using strong parameter filters. Than add permissions to params and check test again.
For example, this:
will pass all params to User and test will fail. And when you filter them:
and change action with
User.create(user_params)
, test will pass.I personally use shoulda-matcher from thoughtbot.
With something like:
Here is how I did it:
end
Controller code:
as like you create or update object using strong parameters,it is also similar except one thing that normal you do like this:
But in strong parameter you have to do like this:
you have to pass in nested parameters.