Skip to content

Commit

Permalink
more elaborate spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Braktar committed Aug 20, 2020
1 parent 3dea5eb commit c98379d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions spec/grape/validations/params_scope_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -638,16 +638,23 @@ def initialize(value)
requires :a, type: String, allow_blank: false, values: %w[x y z]
given a: ->(val) { val == 'z' } do
requires :inner3, type: Array, allow_blank: false do
requires :bar, type: Integer, allow_blank: false
requires :baz, type: Array do
requires :baz_category, type: String
requires :bar, type: String, allow_blank: false
given bar: ->(val) { val == 'b' } do
requires :baz, type: Array do
optional :baz_category, type: String
end
end
given bar: ->(val) { val == 'c' } do
requires :baz, type: Array do
requires :baz_category, type: String
end
end
end
end
end
subject.get('/nested-dependency') { declared(params).to_json }

get '/nested-dependency', a: 'z', inner3: [{ bar: 3, baz: [{ unrelated: 'nope' }] }]
get '/nested-dependency', a: 'z', inner3: [{ bar: 'c', baz: [{ unrelated: 'nope' }] }]
expect(last_response.status).to eq(400)
expect(last_response.body).to eq 'inner3[0][baz][0][baz_category] is missing'
end
Expand Down

0 comments on commit c98379d

Please sign in to comment.