Sha256: b0708cbee350c6b248a611a4de2516a1cdf9604c0d52341a1039fa99c32d39ed

Contents?: true

Size: 1.78 KB

Versions: 8

Compression:

Stored size: 1.78 KB

Contents

require 'factories/profiles.rb'

describe NameFormatValidator do

  let(:subject) { NameFormatValidator }
  let (:object) { Profile.new }

  invalid_names = %w[A%^dam G∫ Ra©©øøl œ∑´®††a †††¬∆µ ©ƒ∂ßåΩ ≈ç√∫µ@]
  valid_names = %w[George Jerry Elaine Kramer Jean-François Noël étè]

  context 'Wrong name format' do
    context 'No message is sent on the options' do
      it 'it returns error message expecified on the validator' do
        n  = subject.new( { attributes: :first_name } )
        invalid_names.each do |invalid_name|
          expect(n.validate_each(object, :first_name, invalid_name)).to include("We're sorry your name cannot contain any special characters")
        end
      end
    end

    context 'Message is sent on the options' do
      it 'it returns error message expecified on the options' do
        n  = subject.new( { message: 'Test error message', attributes: :first_name } )
        invalid_names.each do |invalid_name|
          expect(n.validate_each(object, :first_name, invalid_name)).to include('Test error message')
        end
      end
    end
  end

  context 'Correct name format' do

    context 'No message is sent on the options' do
      it 'it does not return error message' do
        n  = subject.new( { attributes: :first_name } )
        valid_names.each do |valid_name|
          expect(n.validate_each(object, :first_name, valid_name)).to equal(nil)
        end
      end
    end

    context 'Message is sent on the options' do
      it 'it does not return error message' do
        n  = subject.new( { message: 'Test error message', attributes: :first_name } )
        valid_names.each do |valid_name|
          expect(n.validate_each(object, :first_name, valid_name)).to equal(nil)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ama_validators-0.0.13 spec/name_format_validator_spec.rb
ama_validators-0.0.12 spec/name_format_validator_spec.rb
ama_validators-0.0.11 spec/name_format_validator_spec.rb
ama_validators-0.0.10 spec/name_format_validator_spec.rb
ama_validators-0.0.9 spec/name_format_validator_spec.rb
ama_validators-0.0.8 spec/name_format_validator_spec.rb
ama_validators-0.0.7 spec/name_format_validator_spec.rb
ama_validators-0.0.6 spec/name_format_validator_spec.rb