Sha256: 163189d63a3857176744045a1899d14a548136d581f056fbfe872aa53d65d37c

Contents?: true

Size: 1.66 KB

Versions: 11

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Grape::Validations::SameAsValidator do
  module ValidationsSpec
    module SameAsValidatorSpec
      class API < Grape::API
        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
  end

  def app
    ValidationsSpec::SameAsValidatorSpec::API
  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

11 entries across 11 versions & 2 rubygems

Version Path
grape-1.6.0 spec/grape/validations/validators/same_as_spec.rb
grape-1.5.3 spec/grape/validations/validators/same_as_spec.rb
grape-1.5.2 spec/grape/validations/validators/same_as_spec.rb
grape-1.5.1 spec/grape/validations/validators/same_as_spec.rb
grape-1.5.0 spec/grape/validations/validators/same_as_spec.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.4.0/spec/grape/validations/validators/same_as_spec.rb
grape-1.4.0 spec/grape/validations/validators/same_as_spec.rb
grape-1.3.3 spec/grape/validations/validators/same_as_spec.rb
grape-1.3.2 spec/grape/validations/validators/same_as_spec.rb
grape-1.3.1 spec/grape/validations/validators/same_as_spec.rb
grape-1.3.0 spec/grape/validations/validators/same_as_spec.rb