Merge pull request #126 from houdiniproject/validation_is_equal_to

Add useful validation message for is_equal_to
This commit is contained in:
Eric Schultz 2018-12-13 13:07:08 -06:00 committed by GitHub
commit a792562e92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View file

@ -2,7 +2,7 @@
class Houdini::V1::Validators::IsEqualTo < Grape::Validations::Base
def validate_param!(attr_name, params)
if params[attr_name] != params[@option]
fail Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: 'MESSAGE'
fail Grape::Exceptions::Validation, params: [@scope.full_name(attr_name), @scope.full_name(@option)], message: message(:is_equal_to)
end
end
end

View file

@ -0,0 +1,7 @@
# License: CC0-1.0
# grape validation errors require a very specific format for their translation messages. Why? *shrug*
en:
grape:
errors:
messages:
is_equal_to: "must be the same"

View file

@ -82,6 +82,22 @@ describe Houdini::V1::Nonprofit, :type => :controller do
expect_validation_errors(JSON.parse(response.body), expected)
end
it 'should reject unmatching passwords ' do
input = {
user: {
email: "wmeil@email.com",
name: "name",
password: 'password',
password_confirmation: 'doesn\'t match'
}
}
xhr :post, '/api/v1/nonprofit', input
expect(response.code).to eq "400"
expect(JSON.parse(response.body)['errors']).to include(h(params:["user[password]", "user[password_confirmation]"], messages: gr_e("is_equal_to")))
end
it 'attempts to make a slug copy and returns the proper errors' do
force_create(:nonprofit, slug: "n", state_code_slug: "wi", city_slug: "appleton")
input = {