thoughtbot--shoulda-matchers/spec/unit/shoulda/matchers
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
..
action_controller Permit matcher now supports subparameters 2015-03-01 01:32:00 -07:00
active_model allow_value: Raise error if attr sets value differently 2015-02-17 23:09:56 -07:00
active_record Uniqueness: Fix default behavior for case-insensitive models 2015-02-17 10:40:31 -07:00
doublespeak Doublespeak: Proxies store return value in MethodCall 2015-03-01 00:39:51 -07:00
independent Add with_prefix to delegate_method 2014-12-15 22:38:27 -07:00
doublespeak_spec.rb Make Doublespeak specs runnable without Rails 2015-02-28 23:41:28 -07:00