Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix permit matcher for multiple instances of params #902

Merged
merged 1 commit into from
Nov 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/shoulda/matchers/action_controller/permit_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def parameter_names_as_sentence
# @private
class CompositeParametersDoubleRegistry
def initialize
@parameters_double_registries_by_params = {}
@parameters_double_registries = []
end

def register
Expand All @@ -347,20 +347,19 @@ def register
params = call.return_value
parameters_double_registry = ParametersDoubleRegistry.new(params)
parameters_double_registry.register
parameters_double_registries_by_params[params] =
parameters_double_registry
parameters_double_registries << parameters_double_registry
end
end

def permitted_parameter_names(options = {})
parameters_double_registries_by_params.flat_map do |params, double_registry|
parameters_double_registries.flat_map do |double_registry|
double_registry.permitted_parameter_names(options)
end
end

protected

attr_reader :parameters_double_registries_by_params
attr_reader :parameters_double_registries
end

# @private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ def params_with_conditional_require(params, *filters)
for(:update, params: { id: 1 })
end

it 'works when multiple ActionController::Parameters were instantiated' do
define_controller_with_strong_parameters(action: :create) do
params.permit(:name)
params.dup
end

expect(controller).to permit(:name).for(:create)
end

describe '#matches?' do
it 'does not raise an error when #fetch was used instead of #require (issue #495)' do
matcher = permit(:eta, :diner_id).for(:create)
Expand Down