1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
# frozen_string_literal: true
require 'spec_helper'
describe Grape::Validations::Validators::SameAsValidator do
let_it_be(:app) do
Class.new(Grape::API) do
params do
requires :password
requires :password_confirmation, same_as: :password
end
post do
end
params do
requires :password
requires :password_confirmation, same_as: { value: :password, message: 'not match' }
end
post '/custom-message' do
end
end
end
describe '/' do
context 'is the same' do
it do
post '/', password: '987654', password_confirmation: '987654'
expect(last_response.status).to eq(201)
expect(last_response.body).to eq('')
end
end
context 'is not the same' do
it do
post '/', password: '123456', password_confirmation: 'whatever'
expect(last_response.status).to eq(400)
expect(last_response.body).to eq('password_confirmation is not the same as password')
end
end
end
describe '/custom-message' do
context 'is the same' do
it do
post '/custom-message', password: '987654', password_confirmation: '987654'
expect(last_response.status).to eq(201)
expect(last_response.body).to eq('')
end
end
context 'is not the same' do
it do
post '/custom-message', password: '123456', password_confirmation: 'whatever'
expect(last_response.status).to eq(400)
expect(last_response.body).to eq('password_confirmation not match')
end
end
end
end
|