Sha256: d5544ccdee0e85ecd5977025413cf4f48a1695a9093a00050422019ab618d92c

Contents?: true

Size: 778 Bytes

Versions: 5

Compression:

Stored size: 778 Bytes

Contents

require "validates_phone_format_of"

describe ValidatesPhoneFormatOf do

  before(:each) do
    @user_class = Class.new do

      include ActiveModel::Validations

      attr_reader :phone

      def initialize(phone)
        @phone = phone.freeze
      end

      def self.model_name
        ActiveModel::Name.new(self, nil, "user")
      end
      
      validates_phone_format_of :phone
    end
  end

  ['+12223335555', '+33123456789', '+13125551212'].each do |phone|
    it "#{phone} is valid" do
      user = @user_class.new(phone)
      expect(user.valid?).to be_truthy
    end
  end

  ['test', '0000', '(312) 555-1212'].each do |phone|
    it "#{phone} is not valid" do
      user = @user_class.new(phone)
      expect(user.valid?).to_not be_truthy
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
validates_phone_format_of-2.0.1 spec/validates_phone_format_of_spec.rb
validates_phone_format_of-2.0.0 spec/validates_phone_format_of_spec.rb
validates_phone_format_of-1.0.5 spec/validates_phone_format_of_spec.rb
validates_phone_format_of-1.0.4 spec/validates_phone_format_of_spec.rb
validates_phone_format_of-1.0.3 spec/validates_phone_format_of_spec.rb