Sha256: 042f8814165121e1748cbb26e1095910e017484d2d066d3b89a7081bc45ab4f7

Contents?: true

Size: 1008 Bytes

Versions: 18

Compression:

Stored size: 1008 Bytes

Contents

require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
require 'active_model'
require 'phonie/railties/validator'

class SomeModel < Struct.new(:phone_number)
  include ActiveModel::Validations
  validates :phone_number, phone: true
end

class SomeOtherModel < Struct.new(:phone_number)
  include ActiveModel::Validations
  validates :phone_number, phone: true, allow_blank: true
end

class PhoneValidatorTest < Phonie::TestCase
  def test_blank_phone
    assert SomeModel.new(nil).invalid?
    assert SomeModel.new('').invalid?
    assert SomeOtherModel.new(nil).valid?
    assert SomeOtherModel.new('').valid?
  end

  def test_valid_model
    model = SomeModel.new('+1 251 123 4567')
    assert model.valid?
  end

  def test_valid_number_with_extension
    model = SomeModel.new('+1 251 123 4567 ex 1234')
    assert model.valid?
  end

  def test_invalid_model
    model = SomeModel.new('+1 251 123 456')
    assert model.invalid?

    assert !model.errors[:phone_number].empty?
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
phonie-3.2.0 test/railties/validator_test.rb
phonie-3.1.15 test/railties/validator_test.rb
phonie-3.1.14 test/railties/validator_test.rb
phonie-3.1.13 test/railties/validator_test.rb
phonie-3.1.12 test/railties/validator_test.rb
phonie-3.1.11 test/railties/validator_test.rb
phonie-3.1.10 test/railties/validator_test.rb
phonie-3.1.9 test/railties/validator_test.rb
phonie-3.1.8 test/railties/validator_test.rb
phonie-3.1.7 test/railties/validator_test.rb
phonie-3.1.6 test/railties/validator_test.rb
phonie-3.1.5 test/railties/validator_test.rb
phonie-3.1.4 test/railties/validator_test.rb
phonie-3.1.3 test/railties/validator_test.rb
phonie-3.1.2 test/railties/validator_test.rb
phonie-3.1.1 test/railties/validator_test.rb
phonie-3.1.0 test/railties/validator_test.rb
phonie-3.0.0 test/railties/validator_test.rb