From c98379d4a0e8b58ff2096c6a2fadf1d768409986 Mon Sep 17 00:00:00 2001 From: Braktar Date: Thu, 20 Aug 2020 10:20:40 +0200 Subject: [PATCH] more elaborate spec --- spec/grape/validations/params_scope_spec.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/spec/grape/validations/params_scope_spec.rb b/spec/grape/validations/params_scope_spec.rb index 374efb2560..9ef14af9ff 100644 --- a/spec/grape/validations/params_scope_spec.rb +++ b/spec/grape/validations/params_scope_spec.rb @@ -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