Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test to demonstrate validation issue #2474

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions spec/grape/validations/params_scope_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,41 @@ def initialize(value)
expect(last_response.body).to eq 'inner3[0][baz][0][baz_category] is missing'
end

it 'test to demonstrait the validation issue' do
subject.params do

requires :items, type: Array, allow_blank: false do
requires :item_type, type: String, allow_blank: false

given item_type: ->(val) { val == 'type_a' } do
requires :inner_items, type: Array do
requires :prop_a, type: String
end
end

given item_type: ->(val) { val == 'type_b' } do
requires :inner_items, type: Array do
requires :prop_b, type: String
end
end
end
end
subject.post('/nested-dependency') { declared(params, evaluate_given: true).to_json }

test = {
items: [
{ item_type: 'type_a', inner_items: [{ prop_a: 'value' }] },
{ item_type: 'type_b', inner_items: [{ prop_b: 'value' }] }
]
}

post '/nested-dependency', **test

p last_response.body
expect(last_response.status).to eq(200)
# expect(last_response.body).to eq ''
end

it 'includes the parameter within #declared(params)' do
get '/test', a: true, b: true

Expand Down
Loading