Skip to content

Commit

Permalink
Add spec for default value in given block
Browse files Browse the repository at this point in the history
  • Loading branch information
darren987469 authored and basjanssen committed Feb 28, 2020
1 parent c78c331 commit a8c59bc
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions spec/grape/validations/params_scope_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,32 @@ def initialize(value)
end
end

context 'default value in given block' do
before do
subject.params do
optional :a, values: %w[a b]
given a: ->(val) { val == 'a' } do
optional :b, default: 'default'
end
end
subject.get('/') { params.to_json }
end

context 'when dependency meets' do
it 'sets default value for dependent parameter' do
get '/', a: 'a'
expect(last_response.body).to eq({ a: 'a', b: 'default' }.to_json)
end
end

context 'when dependency does not meet' do
it 'does not set default value for dependent parameter' do
get '/', a: 'b'
expect(last_response.body).to eq({ a: 'b' }.to_json)
end
end
end

context 'when validations are dependent on a parameter within an array param' do
before do
subject.params do
Expand Down

0 comments on commit a8c59bc

Please sign in to comment.