Sha256: af033aadff7385b54f3074dec87182d82da113eca49cbea4dbc67f9144665779

Contents?: true

Size: 1.52 KB

Versions: 3

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
grape-1.8.0 spec/grape/validations/validators/same_as_spec.rb
grape-1.7.1 spec/grape/validations/validators/same_as_spec.rb
grape-1.7.0 spec/grape/validations/validators/same_as_spec.rb