Sha256: 9e9d60c71e8dc10e877f49c828f3ae73e8331f3730d65020ed93e0b397bdae7f

Contents?: true

Size: 1.58 KB

Versions: 17

Compression:

Stored size: 1.58 KB

Contents

require 'spec_helper'

describe PhoneValidator do

  context "has a valid value" do
    let(:klass) do
      Class.new do
        include ActiveModel::Validations
        attr_accessor :phone, :name
        validates :phone, phone: true
      end
    end

    subject { klass.new }

    it { should allow_value("1234567").for(:phone) }
    it { should allow_value("123-4567").for(:phone) }
    it { should allow_value("123 4567").for(:phone) }
    it { should allow_value("5551234567").for(:phone) }
    it { should allow_value("555-123-4567").for(:phone) }
    it { should allow_value("555 123 4567").for(:phone) }
    it { should allow_value("(555) 123-4567").for(:phone) }
    it { should allow_value("(555) 123-4567 ext 1234").for(:phone) }
    it { should allow_value("(555) 123-4567 ext1234").for(:phone) }
    it { should allow_value("(555) 123-4567 ext-1234").for(:phone) }
    it { should allow_value("1-555-123-4567").for(:phone) }
    it { should allow_value("+1-555-123-4567").for(:phone) }
    it { should allow_value("+1 (555) 123-4567 ext-1234").for(:phone) }

    it { should_not allow_value('').for(:phone) }
    it { should_not allow_value(nil).for(:phone) }
    it { should_not allow_value("123_4567").for(:phone) }
    it { should_not allow_value("(555) 123-4567 ext:1234").for(:phone) }
    it { should_not allow_value("(555) 123-4567 ext_1234").for(:phone) }
    it { should_not allow_value("! \#$%\`|").for(:phone) }
    it { should_not allow_value("<>@[]\`|").for(:phone) }

    it { should ensure_valid_phone_format_of(:phone) }
    it { should_not ensure_valid_phone_format_of(:name) }
  end

end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
active_validation-1.0.0 spec/lib/phone_validator_spec.rb
yukonisuru-1.0.0 spec/lib/phone_validator_spec.rb
yukonisuru-0.0.1 spec/lib/phone_validator_spec.rb
flash_validators-3.0.12 spec/lib/phone_validator_spec.rb
flash_validators-3.0.11 spec/lib/phone_validator_spec.rb
flash_validators-3.0.10 spec/lib/phone_validator_spec.rb
flash_validators-3.0.9 spec/lib/phone_validator_spec.rb
flash_validators-3.0.8 spec/lib/phone_validator_spec.rb
flash_validators-3.0.7 spec/lib/phone_validator_spec.rb
flash_validators-3.0.6 spec/lib/phone_validator_spec.rb
flash_validators-3.0.5 spec/lib/phone_validator_spec.rb
flash_validators-3.0.4 spec/lib/phone_validator_spec.rb
flash_validators-3.0.3 spec/lib/phone_validator_spec.rb
flash_validators-3.0.2 spec/lib/phone_validator_spec.rb
flash_validators-3.0.1 spec/lib/phone_validator_spec.rb
flash_validators-3.0.0 spec/lib/phone_validator_spec.rb
flash_validators-1.1.0 spec/lib/phone_validator_spec.rb