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

fix: validators checking aliased param instead of original one #1852

Merged
merged 3 commits into from Dec 21, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions spec/grape/validations/params_scope_spec.rb
Expand Up @@ -155,6 +155,16 @@ def initialize(value)
expect(last_response.status).to eq(400)
expect(last_response.body).to eq('foo is empty')
end

it do
subject.params do
requires :foo, as: :bar, allow_blank: false
end
subject.get('/alias-not-blank-with-value') {}
get '/alias-not-blank-with-value', foo: 'any'

expect(last_response.status).to eq(200)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get status 400 here with the last_response.body = foo is empty.

As the alias (as) is called before the allow_blank, it deletes the foo key from params and sets params[:bar] with its value.

Given that alias is just for internal usage (inside get block I mean), I think this should not fail, cause the foo param was given as expected. Do you agree?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd tend to agree that this looks like a bug to me. Could you open an issue for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Thanks for looking at this!)

end
end

context 'array without coerce type explicitly given' do
Expand Down