Skip to content

Commit c98379d

Browse files
author
Braktar
committed
more elaborate spec
1 parent 3dea5eb commit c98379d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

spec/grape/validations/params_scope_spec.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,16 +638,23 @@ def initialize(value)
638638
requires :a, type: String, allow_blank: false, values: %w[x y z]
639639
given a: ->(val) { val == 'z' } do
640640
requires :inner3, type: Array, allow_blank: false do
641-
requires :bar, type: Integer, allow_blank: false
642-
requires :baz, type: Array do
643-
requires :baz_category, type: String
641+
requires :bar, type: String, allow_blank: false
642+
given bar: ->(val) { val == 'b' } do
643+
requires :baz, type: Array do
644+
optional :baz_category, type: String
645+
end
646+
end
647+
given bar: ->(val) { val == 'c' } do
648+
requires :baz, type: Array do
649+
requires :baz_category, type: String
650+
end
644651
end
645652
end
646653
end
647654
end
648655
subject.get('/nested-dependency') { declared(params).to_json }
649656

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

0 commit comments

Comments
 (0)