Sha256: 5852f953aa10b87d4906f3fea017145cd8df4096378215a9543f9d00b53e4ed4

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

require 'test_helper'

class RailsPhoneTest < ActiveSupport::TestCase
  setup do
    @jim = Person.new name: "Jim"
    @corp = Company.new name: "Acme Entertainment"
    @outcast = Outcast.new name: "Jon Snow", phone: "ABC-123-456"
  end

  test "does not affect classes without has_phone_number" do
    assert @outcast.valid?
  end

  test "custom phone attributes must be valid" do
    @corp.customer_support_phone = "123-123-1233"
    assert @corp.valid?
    @corp.customer_support_phone = "A23-123-1233"
    assert !@corp.valid?
  end

  test "uses :phone by default" do
    assert_equal [:phone], Person.phone_number_attributes
  end

  test "accepts phone attributes as arguments" do
    assert_equal [:customer_support_phone, :phone], Company.phone_number_attributes
  end

  test "unformatted phone is ok" do
    @jim.phone = 1123456789
    assert @jim.valid?, "1123456789 should be valid"
  end

  test "blank phone is ok" do
    assert @jim.valid?
  end

  %w{0123456789 012-345-6789 (012)-345-6789}.each do |valid_phone|
    define_method "test_#{valid_phone}" do
      @jim.phone = valid_phone
      assert @jim.valid?, "#{valid_phone} should be valid"
    end
  end

  %w{123456789 1234 012-A45-6789 (B12)-345-6789}.each do |valid_phone|
    define_method "test_#{valid_phone}" do
      @jim.phone = valid_phone
      assert !@jim.valid?, "#{valid_phone} should be invalid"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rails_phone-1.1.1 test/rails_phone_test.rb
rails_phone-1.1.0 test/rails_phone_test.rb
rails_phone-1.0.0 test/rails_phone_test.rb