thoughtbot--shoulda-matchers/spec
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
..
acceptance Add support for Postgres 2015-02-12 16:01:00 -07:00
support Rewrite the tests for #permit 2015-02-28 23:41:01 -07:00
unit/shoulda/matchers Permit matcher now supports subparameters 2015-03-01 01:32:00 -07:00
warnings_spy Be better about looking for warnings on Travis 2014-12-16 20:30:05 -07:00
acceptance_spec_helper.rb Add support for Postgres 2015-02-12 16:01:00 -07:00
doublespeak_spec_helper.rb Make Doublespeak specs runnable without Rails 2015-02-28 23:41:28 -07:00
report_warnings.rb Remove all Ruby-emitted warnings 2014-07-18 18:00:08 -06:00
unit_spec_helper.rb Add support for Postgres 2015-02-12 16:01:00 -07:00
warnings_spy.rb Fail build if there are warnings 2015-02-09 10:48:49 -07:00