validates_telephone 0.2.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/.travis.yml +4 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +28 -23
  4. data/lib/validates_telephone/formatter.rb +21 -0
  5. data/lib/validates_telephone/regex.rb +15 -0
  6. data/lib/validates_telephone/remarkable/require_a_valid_telephone_matcher.rb +43 -0
  7. data/lib/validates_telephone/shoulda-matchers/require_a_valid_telephone_matcher.rb +47 -0
  8. data/lib/validates_telephone/telephone_validator.rb +7 -0
  9. data/lib/validates_telephone/validator.rb +18 -0
  10. data/lib/validates_telephone/version.rb +1 -1
  11. data/lib/validates_telephone.rb +10 -10
  12. data/spec/fake_app/db/create_users.rb +4 -6
  13. data/spec/fake_app/user.rb +3 -5
  14. data/spec/spec_helper.rb +1 -2
  15. data/spec/validates_telephone/formatter_spec.rb +49 -0
  16. data/spec/validates_telephone/regex_spec.rb +51 -0
  17. data/spec/validates_telephone/remarkable/require_a_valid_telephone_matcher_spec.rb +40 -0
  18. data/spec/validates_telephone/shoulda-matchers/require_a_valid_telephone_matcher_spec.rb +40 -0
  19. data/spec/validates_telephone/validator_spec.rb +145 -0
  20. data/spec/validates_telephone_spec.rb +75 -14
  21. data/validates_telephone.gemspec +0 -2
  22. metadata +60 -29
  23. data/lib/validates_telephone/remarkable/validate_as_br_telephone_matcher.rb +0 -34
  24. data/lib/validates_telephone/remarkable/validate_as_usa_telephone_matcher.rb +0 -34
  25. data/lib/validates_telephone/shoulda-matchers/validate_as_br_telephone_matcher.rb +0 -45
  26. data/lib/validates_telephone/shoulda-matchers/validate_as_usa_telephone_matcher.rb +0 -45
  27. data/lib/validates_telephone/telephone.rb +0 -34
  28. data/spec/fake_app/admin.rb +0 -2
  29. data/spec/fake_app/db/create_admins.rb +0 -11
  30. data/spec/remarkable/validate_as_br_telephone_matcher_spec.rb +0 -26
  31. data/spec/remarkable/validate_as_usa_telephone_matcher_spec.rb +0 -26
  32. data/spec/shoulda-matchers/validate_as_br_telephone_matcher_spec.rb +0 -26
  33. data/spec/shoulda-matchers/validate_as_usa_telephone_matcher_spec.rb +0 -26
  34. data/spec/validates_telephone/telephone_spec.rb +0 -103
@@ -1,10 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe TelephoneValidator do
4
- context "with br as locale" do
5
- context "when telephone is invalid" do
4
+ let(:valid_numbers) { { :br_telephone => "(11)1111-1111",
5
+ :usa_telephone => "(111)111-1111",
6
+ :telephone => "(111)111-1111" } }
7
+
8
+ context "on a field validated as a valid telephone from Brazil" do
9
+ context "with an invalid number" do
6
10
  before :each do
7
- @user = BrUser.new(:telephone => "12345")
11
+ @user = User.new(valid_numbers.merge(:br_telephone => "12345"))
12
+ I18n.stub(:t).with(:"activerecord.errors.models.user.attributes.br_telephone.invalid",
13
+ :default => :"activerecord.errors.messages.invalid").and_return("is invalid")
8
14
  end
9
15
 
10
16
  it "should set object as invalid" do
@@ -13,13 +19,13 @@ describe TelephoneValidator do
13
19
 
14
20
  it "should set an error on attribute" do
15
21
  @user.valid?
16
- @user.errors[:telephone].should == ['is invalid']
22
+ @user.errors[:br_telephone].should == ['is invalid']
17
23
  end
18
24
  end
19
25
 
20
- context "when telephone is valid" do
26
+ context "with a valid number" do
21
27
  before :each do
22
- @user = BrUser.new(:telephone => "(11)1111-1111")
28
+ @user = User.new(valid_numbers)
23
29
  end
24
30
 
25
31
  it "should set object as valid" do
@@ -28,20 +34,61 @@ describe TelephoneValidator do
28
34
 
29
35
  it "should not set an error on attribute" do
30
36
  @user.valid?
31
- @user.errors[:telephone].should be_blank
37
+ @user.errors[:br_telephone].should be_blank
38
+ end
39
+ end
40
+
41
+ it "should accept a nil value" do
42
+ @user = User.new(valid_numbers.merge(:br_telephone => nil))
43
+ @user.valid?.should be_true
44
+ end
45
+ end
46
+
47
+ context "on a field validated as a valid telephone from United States" do
48
+ context "with an invalid number" do
49
+ before :each do
50
+ @user = User.new(valid_numbers.merge(:usa_telephone => "12345"))
51
+ I18n.stub(:t).with(:"activerecord.errors.models.user.attributes.usa_telephone.invalid",
52
+ :default => :"activerecord.errors.messages.invalid").and_return("is invalid")
53
+ end
54
+
55
+ it "should set object as invalid" do
56
+ @user.valid?.should be_false
57
+ end
58
+
59
+ it "should set an error on attribute" do
60
+ @user.valid?
61
+ @user.errors[:usa_telephone].should == ['is invalid']
62
+ end
63
+ end
64
+
65
+ context "with a valid number" do
66
+ before :each do
67
+ @user = User.new(valid_numbers)
68
+ end
69
+
70
+ it "should set object as valid" do
71
+ @user.valid?.should be_true
72
+ end
73
+
74
+ it "should not set an error on attribute" do
75
+ @user.valid?
76
+ @user.errors[:usa_telephone].should be_blank
32
77
  end
33
78
  end
34
79
 
35
80
  it "should accept a nil value" do
36
- @user = BrUser.new(:telephone => nil)
81
+ @user = User.new(valid_numbers.merge(:usa_telephone => nil))
37
82
  @user.valid?.should be_true
38
83
  end
39
84
  end
40
85
 
41
- context "with usa as locale" do
42
- context "when telephone is invalid" do
86
+ context "on a field validated as a valid telephone" do
87
+ context "with an invalid number" do
43
88
  before :each do
44
- @user = EnUser.new(:telephone => "12345")
89
+ @user = User.new(valid_numbers.merge(:telephone => "12345"))
90
+ I18n.stub(:t).with(:"activerecord.errors.models.user.attributes.telephone.invalid",
91
+ :default => :"activerecord.errors.messages.invalid").and_return("is invalid")
45
92
  end
46
93
 
47
94
  it "should set object as invalid" do
@@ -54,10 +101,24 @@ describe TelephoneValidator do
54
101
  end
55
102
  end
56
103
 
57
- context "when telephone is valid" do
104
+ context "with a valid number from Brazil" do
58
105
  before :each do
59
- @user = EnUser.new(:telephone => "(111)111-1111")
106
+ @user = User.new(valid_numbers.merge(:telephone => "(11)1111-1111"))
107
+ end
108
+
109
+ it "should set object as valid" do
110
+ @user.valid?.should be_true
111
+ end
112
+
113
+ it "should not set an error on attribute" do
60
114
  @user.valid?
115
+ @user.errors[:telephone].should be_blank
116
+ end
117
+ end
118
+
119
+ context "with a valid number from United States" do
120
+ before :each do
121
+ @user = User.new(valid_numbers.merge(:telephone => "(111)111-1111"))
61
122
  end
62
123
 
63
124
  it "should set object as valid" do
@@ -71,7 +132,7 @@ describe TelephoneValidator do
71
132
  end
72
133
 
73
134
  it "should accept a nil value" do
74
- @user = EnUser.new(:telephone => nil)
135
+ @user = User.new(valid_numbers.merge(:usa_telephone => nil))
75
136
  @user.valid?.should be_true
76
137
  end
77
138
  end
@@ -13,8 +13,6 @@ Gem::Specification.new do |s|
13
13
 
14
14
  s.add_dependency("activerecord", ">= 3.0.0")
15
15
 
16
- s.rubyforge_project = "validates_cpf"
17
-
18
16
  s.files = `git ls-files`.split("\n")
19
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_telephone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-21 00:00:00.000000000 Z
12
+ date: 2012-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &6809500 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *6809500
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rake
27
- requirement: &6807740 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *6807740
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rspec
38
- requirement: &6807200 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: 2.0.0
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *6807200
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.0
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: shoulda-matchers
49
- requirement: &6806680 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,21 +69,31 @@ dependencies:
54
69
  version: 1.0.0
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *6806680
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.0.0
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: remarkable_activerecord
60
- requirement: &6806100 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
- - - =
83
+ - - '='
64
84
  - !ruby/object:Gem::Version
65
85
  version: 4.0.0.alpha4
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *6806100
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - '='
92
+ - !ruby/object:Gem::Version
93
+ version: 4.0.0.alpha4
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: sqlite3
71
- requirement: &6805640 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,7 +101,12 @@ dependencies:
76
101
  version: '0'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *6805640
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  description: Validates Telephone for Brazil and United States and test it with matchers
81
111
  in a simple way.
82
112
  email: plribeiro3000@gmail.com
@@ -87,26 +117,27 @@ files:
87
117
  - .gitignore
88
118
  - .rspec
89
119
  - .rvmrc
120
+ - .travis.yml
90
121
  - Gemfile
122
+ - LICENSE
91
123
  - README.rdoc
92
124
  - Rakefile
93
125
  - lib/validates_telephone.rb
94
- - lib/validates_telephone/remarkable/validate_as_br_telephone_matcher.rb
95
- - lib/validates_telephone/remarkable/validate_as_usa_telephone_matcher.rb
96
- - lib/validates_telephone/shoulda-matchers/validate_as_br_telephone_matcher.rb
97
- - lib/validates_telephone/shoulda-matchers/validate_as_usa_telephone_matcher.rb
98
- - lib/validates_telephone/telephone.rb
126
+ - lib/validates_telephone/formatter.rb
127
+ - lib/validates_telephone/regex.rb
128
+ - lib/validates_telephone/remarkable/require_a_valid_telephone_matcher.rb
129
+ - lib/validates_telephone/shoulda-matchers/require_a_valid_telephone_matcher.rb
130
+ - lib/validates_telephone/telephone_validator.rb
131
+ - lib/validates_telephone/validator.rb
99
132
  - lib/validates_telephone/version.rb
100
- - spec/fake_app/admin.rb
101
- - spec/fake_app/db/create_admins.rb
102
133
  - spec/fake_app/db/create_users.rb
103
134
  - spec/fake_app/user.rb
104
- - spec/remarkable/validate_as_br_telephone_matcher_spec.rb
105
- - spec/remarkable/validate_as_usa_telephone_matcher_spec.rb
106
- - spec/shoulda-matchers/validate_as_br_telephone_matcher_spec.rb
107
- - spec/shoulda-matchers/validate_as_usa_telephone_matcher_spec.rb
108
135
  - spec/spec_helper.rb
109
- - spec/validates_telephone/telephone_spec.rb
136
+ - spec/validates_telephone/formatter_spec.rb
137
+ - spec/validates_telephone/regex_spec.rb
138
+ - spec/validates_telephone/remarkable/require_a_valid_telephone_matcher_spec.rb
139
+ - spec/validates_telephone/shoulda-matchers/require_a_valid_telephone_matcher_spec.rb
140
+ - spec/validates_telephone/validator_spec.rb
110
141
  - spec/validates_telephone_spec.rb
111
142
  - validates_telephone.gemspec
112
143
  homepage: ''
@@ -128,8 +159,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
159
  - !ruby/object:Gem::Version
129
160
  version: '0'
130
161
  requirements: []
131
- rubyforge_project: validates_cpf
132
- rubygems_version: 1.8.10
162
+ rubyforge_project:
163
+ rubygems_version: 1.8.24
133
164
  signing_key:
134
165
  specification_version: 3
135
166
  summary: Telephone Validation GEM
@@ -1,34 +0,0 @@
1
- require 'remarkable/active_record'
2
-
3
- module Remarkable
4
- module ActiveRecord
5
- module Matchers
6
- class ValidateAsBrTelephoneMatcher < Remarkable::ActiveRecord::Base
7
- arguments :telephone
8
-
9
- collection_assertions :telephone_valid?, :allow_nil?, :formatted_number?
10
-
11
- protected
12
-
13
- def telephone_valid?
14
- @subject.telephone = '123456'
15
- @subject.valid?.errors[:telephone].should == ['is invalid']
16
- end
17
-
18
- def allow_nil?
19
- @subject.telephone = nil
20
- @subject.valid?.errors[:telephone].should == []
21
- end
22
-
23
- def formatted_number?
24
- @subject.telephone = '1122223333'
25
- @subject.valid?.telephone.should == '(11)2222-3333'
26
- end
27
- end
28
-
29
- def validate_as_br_telephone(*args, &block)
30
- ValidateAsBrTelephoneMatcher.new(*args, &block).spec(self)
31
- end
32
- end
33
- end
34
- end
@@ -1,34 +0,0 @@
1
- require 'remarkable/active_record'
2
-
3
- module Remarkable
4
- module ActiveRecord
5
- module Matchers
6
- class ValidateAsUsaTelephoneMatcher < Remarkable::ActiveRecord::Base
7
- arguments :telephone
8
-
9
- collection_assertions :telephone_valid?, :allow_nil?, :formatted_number?
10
-
11
- protected
12
-
13
- def telephone_valid?
14
- @subject.telephone = '123456'
15
- @subject.valid?.errors[:telephone].should == ['is invalid']
16
- end
17
-
18
- def allow_nil?
19
- @subject.telephone = nil
20
- @subject.valid?.errors[:telephone].should == []
21
- end
22
-
23
- def formatted_number?
24
- @subject.telephone = '1112223333'
25
- @subject.valid?.telephone.should == '(111)222-3333'
26
- end
27
- end
28
-
29
- def validate_as_usa_telephone(*args, &block)
30
- ValidateAsUsaTelephoneMatcher.new(*args, &block).spec(self)
31
- end
32
- end
33
- end
34
- end
@@ -1,45 +0,0 @@
1
- require "shoulda-matchers"
2
-
3
- module Shoulda
4
- module Matchers
5
- module ActiveModel
6
- def validate_as_br_telephone(attr)
7
- ValidateAsBrTelephoneMatcher.new(attr)
8
- end
9
-
10
- class ValidateAsBrTelephoneMatcher < ValidationMatcher
11
- def initialize(attribute)
12
- @attribute = attribute
13
- end
14
-
15
- def description
16
- "validate #{@attribute} as a valid Telephone number for Brazil"
17
- end
18
-
19
- def failure_message
20
- "expected #{@attribute} to be validated as a valid Telephone number for Brazil"
21
- end
22
-
23
- def matches?(subject)
24
- super(subject)
25
-
26
- disallows_invalid_value and allows_valid_value and allows_nil_value
27
- end
28
-
29
- private
30
-
31
- def disallows_invalid_value
32
- disallows_value_of("123456")
33
- end
34
-
35
- def allows_valid_value
36
- allows_value_of("(11)2222-3333")
37
- end
38
-
39
- def allows_nil_value
40
- allows_value_of(nil)
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,45 +0,0 @@
1
- require "shoulda-matchers"
2
-
3
- module Shoulda
4
- module Matchers
5
- module ActiveModel
6
- def validate_as_usa_telephone(attr)
7
- ValidateAsUsaTelephoneMatcher.new(attr)
8
- end
9
-
10
- class ValidateAsUsaTelephoneMatcher < ValidationMatcher
11
- def initialize(attribute)
12
- @attribute = attribute
13
- end
14
-
15
- def description
16
- "validate #{@attribute} as a valid Telephone number for United States"
17
- end
18
-
19
- def failure_message
20
- "expected #{@attribute} to be validated as a valid Telephone number for United States"
21
- end
22
-
23
- def matches?(subject)
24
- super(subject)
25
-
26
- disallows_invalid_value and allows_valid_value and allows_nil_value
27
- end
28
-
29
- private
30
-
31
- def disallows_invalid_value
32
- disallows_value_of("123456")
33
- end
34
-
35
- def allows_valid_value
36
- allows_value_of("(111)222-3333")
37
- end
38
-
39
- def allows_nil_value
40
- allows_value_of(nil)
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,34 +0,0 @@
1
- class Telephone
2
- def initialize(number, locale)
3
- @number = number
4
- @locale = locale
5
- if @locale == :br
6
- @match = number =~ /^(\(?\d{2}\)?)(\d{4})-?(\d{4})$/
7
- else
8
- @match = number =~ /^(\(?[^2-9]\d{2}\)?)(\d{3})-?(\d{4})$/
9
- end
10
- @cleaned_number = $1.nil? ? nil : @number.gsub(/[\(\)-]/, "")
11
- format_number! if @cleaned_number
12
- end
13
-
14
- def valid?
15
- return false unless @number.nil? or @match
16
- true
17
- end
18
-
19
- def number
20
- @number
21
- end
22
-
23
- private
24
-
25
- def format_number!
26
- if @locale == :br
27
- @cleaned_number =~ /^(\d{2})(\d{4})(\d{4})$/
28
- @number = "(#{$1})#{$2}-#{$3}"
29
- else
30
- @cleaned_number =~ /^(\d{3})(\d{3})(\d{4})$/
31
- @number = "(#{$1})#{$2}-#{$3}"
32
- end
33
- end
34
- end
@@ -1,2 +0,0 @@
1
- class Admin < ActiveRecord::Base
2
- end
@@ -1,11 +0,0 @@
1
- class CreateAdmins < ActiveRecord::Migration
2
- def self.up
3
- create_table :admins do |u|
4
- u.string :telephone
5
- end
6
- end
7
-
8
- def self.down
9
- drop_table :admins
10
- end
11
- end
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
- require 'remarkable/active_record'
3
-
4
- describe Remarkable::ActiveRecord::Matchers::ValidateAsBrTelephoneMatcher do
5
- context "on a attribute which validates telephone" do
6
- it "should require a valid telephone" do
7
- @user = BrUser.new(:telephone => '123456')
8
- @user.should validate_as_br_telephone(:telephone)
9
- end
10
-
11
- it "should allow a nil value" do
12
- @user = BrUser.new(:telephone => nil)
13
- @user.should validate_as_br_telephone(:telephone)
14
- end
15
- end
16
-
17
- context "on a attribute which not validates telephone" do
18
- before do
19
- @user = Admin.new(:telephone => '123456')
20
- end
21
-
22
- it "should not require a valid telephone" do
23
- @user.should_not validate_as_br_telephone(:telephone)
24
- end
25
- end
26
- end
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
- require 'remarkable/active_record'
3
-
4
- describe Remarkable::ActiveRecord::Matchers::ValidateAsUsaTelephoneMatcher do
5
- context "on a attribute which validates telephone" do
6
- it "should require a valid telephone" do
7
- @user = EnUser.new(:telephone => '123456')
8
- @user.should validate_as_usa_telephone(:telephone)
9
- end
10
-
11
- it "should allow a nil value" do
12
- @user = EnUser.new(:telephone => nil)
13
- @user.should validate_as_usa_telephone(:telephone)
14
- end
15
- end
16
-
17
- context "on a attribute which not validates telephone" do
18
- before do
19
- @user = Admin.new(:telephone => '123456')
20
- end
21
-
22
- it "should not require a valid telephone" do
23
- @user.should_not validate_as_usa_telephone(:telephone)
24
- end
25
- end
26
- end
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
- require 'shoulda-matchers'
3
-
4
- describe Shoulda::Matchers::ActiveModel::ValidateAsBrTelephoneMatcher do
5
- context "on a attribute which validates telephone" do
6
- it "should require a valid telephone" do
7
- @user = BrUser.new(:telephone => '123456')
8
- @user.should validate_as_br_telephone(:telephone)
9
- end
10
-
11
- it "should allow a nil value" do
12
- @user = BrUser.new(:telephone => nil)
13
- @user.should validate_as_br_telephone(:telephone)
14
- end
15
- end
16
-
17
- context "on a attribute which not validates telephone" do
18
- before do
19
- @user = Admin.new(:telephone => '123456')
20
- end
21
-
22
- it "should not require a valid telephone" do
23
- @user.should_not validate_as_br_telephone(:telephone)
24
- end
25
- end
26
- end
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
- require 'shoulda-matchers'
3
-
4
- describe Shoulda::Matchers::ActiveModel::ValidateAsUsaTelephoneMatcher do
5
- context "on a attribute which validates telephone" do
6
- it "should require a valid telephone" do
7
- @user = EnUser.new(:telephone => '123456')
8
- @user.should validate_as_usa_telephone(:telephone)
9
- end
10
-
11
- it "should allow a nil value" do
12
- @user = EnUser.new(:telephone => nil)
13
- @user.should validate_as_usa_telephone(:telephone)
14
- end
15
- end
16
-
17
- context "on a attribute which not validates telephone" do
18
- before do
19
- @user = Admin.new(:telephone => '123456')
20
- end
21
-
22
- it "should not require a valid telephone" do
23
- @user.should_not validate_as_usa_telephone(:telephone)
24
- end
25
- end
26
- end