Skip to content

Commit d85ff2a

Browse files
ksssbasjanssen
authored andcommitted
Fix NoMethodError with none Hash params
1 parent 8b83164 commit d85ff2a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/grape/validations/params_scope.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def meets_dependency?(params, request_params)
5252

5353
return true unless @dependent_on
5454
return params.any? { |param| meets_dependency?(param, request_params) } if params.is_a?(Array)
55+
return false unless params.respond_to?(:with_indifferent_access)
5556
params = params.with_indifferent_access
5657

5758
@dependent_on.each do |dependency|

spec/grape/validations/params_scope_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,26 @@ def initialize(value)
700700
end
701701

702702
context 'when validations are dependent on a parameter within an array param' do
703+
before do
704+
subject.params do
705+
requires :foos, type: Array do
706+
optional :foo
707+
given :foo do
708+
requires :bar
709+
end
710+
end
711+
end
712+
subject.get('/test') { 'ok' }
713+
end
714+
715+
it 'should pass none Hash params' do
716+
get '/test', foos: ['']
717+
expect(last_response.status).to eq(200)
718+
expect(last_response.body).to eq('ok')
719+
end
720+
end
721+
722+
context 'when validations are dependent on a parameter within an array param within #declared(params).to_json' do
703723
before do
704724
subject.params do
705725
requires :foos, type: Array do

0 commit comments

Comments
 (0)