1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00
thoughtbot--shoulda-matchers/spec/unit/shoulda/matchers/action_controller
Elliot Winkler b33f5de55a Permit matcher now supports subparameters
Previously we were taking ActionController::Parameters and completely
overriding #require, forcing it to return `self`, i.e, the entire
ActionController::Parameters object. This meant that we broke its
functionality, which is to return a slice of the params hash instead.
The consequence of this is that attempting to call #permit on a slice of
the params hash obtained via #require would not work:

``` ruby
params = ActionController::Parameters.new(
  { "course" => { "foo" => "bar" } }
)
params.require(:course)
params.require(:course).permit(:foo)
```

This commit fixes the permit matcher so that #require is proxied
instead, retaining the existing behavior.

This commit also adds a qualifier, #on, for asserting that your action
places a restriction on a slice of the params hash. The `permit` matcher
will properly track calls on child `params` instances. For example:

``` ruby
class UsersController < ActionController::Base
  def create
    User.create!(user_params)
    ...
  end

  private

  def user_params
    params.require(:user).permit(:name, :age)
  end
end

describe UsersController do
  it { should permit(:name, :age).for(:create).on(:user) }
end
```

If this fails, you'll get the following error message:

```
Expected POST #create to restrict parameters for :user to :name and :age,
but restricted parameters were :first_name and :last_name.
```
2015-03-01 01:32:00 -07:00
..
callback_matcher_spec.rb Fix test suite to properly tag example groups 2014-12-25 00:44:53 -05:00
filter_param_matcher_spec.rb Fix test suite to properly tag example groups 2014-12-25 00:44:53 -05:00
permit_matcher_spec.rb Permit matcher now supports subparameters 2015-03-01 01:32:00 -07:00
redirect_to_matcher_spec.rb Fix AC matcher tests for Rails 4.2 2014-12-25 00:45:04 -05:00
render_template_matcher_spec.rb Ensure that we are req'd after rspec in tests 2014-12-25 00:44:54 -05:00
render_with_layout_matcher_spec.rb Remove Rails 3.x, Ruby 1.9.2, Ruby 1.9.3 2015-02-09 10:52:22 -07:00
rescue_from_matcher_spec.rb Fix test suite to properly tag example groups 2014-12-25 00:44:53 -05:00
respond_with_matcher_spec.rb Fix test suite to properly tag example groups 2014-12-25 00:44:53 -05:00
route_matcher_spec.rb Fix AC matcher tests for Rails 4.2 2014-12-25 00:45:04 -05:00
route_params_spec.rb Fix test suite to properly tag example groups 2014-12-25 00:44:53 -05:00
set_flash_matcher_spec.rb Consolidate set_session and set_flash APIs 2015-02-09 10:52:51 -07:00
set_session_matcher_spec.rb Consolidate set_session and set_flash APIs 2015-02-09 10:52:51 -07:00
set_session_or_flash_matcher_spec.rb Add SetSessionOrFlashMatcher 2015-02-09 10:52:51 -07:00