validates_telephone 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +21 -6
- data/lib/validates_telephone.rb +5 -1
- data/lib/validates_telephone/remarkable/{validate_as_telephone_matcher.rb → validate_as_br_telephone_matcher.rb} +3 -3
- data/lib/validates_telephone/remarkable/validate_as_usa_telephone_matcher.rb +34 -0
- data/lib/validates_telephone/shoulda-matchers/{validate_as_telephone_matcher.rb → validate_as_br_telephone_matcher.rb} +5 -5
- data/lib/validates_telephone/shoulda-matchers/validate_as_usa_telephone_matcher.rb +45 -0
- data/lib/validates_telephone/telephone.rb +14 -4
- data/lib/validates_telephone/version.rb +1 -1
- data/spec/fake_app/db/create_users.rb +6 -2
- data/spec/fake_app/user.rb +5 -1
- data/spec/remarkable/{validate_as_telephone_matcher_spec.rb → validate_as_br_telephone_matcher_spec.rb} +6 -6
- data/spec/remarkable/validate_as_usa_telephone_matcher_spec.rb +26 -0
- data/spec/shoulda-matchers/{validate_as_telephone_matcher_spec.rb → validate_as_br_telephone_matcher_spec.rb} +6 -6
- data/spec/shoulda-matchers/validate_as_usa_telephone_matcher_spec.rb +26 -0
- data/spec/validates_telephone/telephone_spec.rb +81 -29
- data/spec/validates_telephone_spec.rb +61 -21
- metadata +21 -17
data/README.rdoc
CHANGED
@@ -8,21 +8,36 @@ gem install validates_telephone
|
|
8
8
|
|
9
9
|
== Usage
|
10
10
|
|
11
|
-
Lets say you have a model with "telephone" string column that you want to be a valid telephone. Just add this to your model:
|
11
|
+
Lets say you have a model with "telephone" string column that you want to be a valid telephone for Brazil. Just add this to your model:
|
12
12
|
|
13
13
|
class User < ActiveRecord::Base
|
14
14
|
validates :telephone, :telephone => true
|
15
15
|
end
|
16
16
|
|
17
|
+
In case you want it to be a valid telephone for United States, just pass the locale as en:
|
18
|
+
|
19
|
+
class User < ActiveRecord::Base
|
20
|
+
validates :telephone, :telephone => { :locale => :usa }
|
21
|
+
end
|
22
|
+
|
17
23
|
== Test
|
18
24
|
|
19
25
|
This gem has matchers for shoulda-matchers and remarkable.
|
20
26
|
|
21
|
-
If you are using shoulda-matchers, add this line to your spec_helper.rb :
|
22
|
-
require "validates_telephone/shoulda-matchers/
|
23
|
-
If you are using remarkable, add this line to your spec_helper.rb :
|
24
|
-
require "validates_telephone/remarkable/
|
27
|
+
If you want the matchers for Brazil and you are using shoulda-matchers, add this line to your spec_helper.rb :
|
28
|
+
require "validates_telephone/shoulda-matchers/validate_as_br_telephone_matcher"
|
29
|
+
If you want the matchers for Brazil and you are using remarkable, add this line to your spec_helper.rb :
|
30
|
+
require "validates_telephone/remarkable/validate_as_br_telephone_matcher"
|
31
|
+
|
32
|
+
If you want the matchers for United States and you are using shoulda-matchers, add this line to your spec_helper.rb :
|
33
|
+
require "validates_telephone/shoulda-matchers/validate_as_usa_telephone_matcher"
|
34
|
+
If you want the matchers for United States and you are using remarkable, add this line to your spec_helper.rb :
|
35
|
+
require "validates_telephone/remarkable/validate_as_usa_telephone_matcher"
|
36
|
+
|
37
|
+
=== How?
|
38
|
+
|
39
|
+
You should use validates_as_telephone(:attribute) just like any other shoulda or remarkable matcher.
|
25
40
|
|
26
41
|
== Future
|
27
42
|
|
28
|
-
Add Support for other countries. For now it only supports Brazil telephones.
|
43
|
+
Add Support for other countries. For now it only supports Brazil and United States telephones.
|
data/lib/validates_telephone.rb
CHANGED
@@ -3,6 +3,10 @@ require "validates_telephone/telephone"
|
|
3
3
|
|
4
4
|
class TelephoneValidator < ActiveModel::EachValidator
|
5
5
|
def validate_each(record, attribute, value)
|
6
|
-
|
6
|
+
if options[:locale].nil?
|
7
|
+
record.errors[attribute] << I18n.t("errors.messages.invalid") unless Telephone.new(value, :br).valid?
|
8
|
+
else
|
9
|
+
record.errors[attribute] << I18n.t("errors.messages.invalid") unless Telephone.new(value, options[:location]).valid?
|
10
|
+
end
|
7
11
|
end
|
8
12
|
end
|
@@ -3,7 +3,7 @@ require 'remarkable/active_record'
|
|
3
3
|
module Remarkable
|
4
4
|
module ActiveRecord
|
5
5
|
module Matchers
|
6
|
-
class
|
6
|
+
class ValidateAsBrTelephoneMatcher < Remarkable::ActiveRecord::Base
|
7
7
|
arguments :telephone
|
8
8
|
|
9
9
|
collection_assertions :telephone_valid?, :allow_nil?, :formatted_number?
|
@@ -26,8 +26,8 @@ module Remarkable
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
|
29
|
+
def validate_as_br_telephone(*args, &block)
|
30
|
+
ValidateAsBrTelephoneMatcher.new(*args, &block).spec(self)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -0,0 +1,34 @@
|
|
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
|
@@ -3,21 +3,21 @@ require "shoulda-matchers"
|
|
3
3
|
module Shoulda
|
4
4
|
module Matchers
|
5
5
|
module ActiveModel
|
6
|
-
def
|
7
|
-
|
6
|
+
def validate_as_br_telephone(attr)
|
7
|
+
ValidateAsBrTelephoneMatcher.new(attr)
|
8
8
|
end
|
9
9
|
|
10
|
-
class
|
10
|
+
class ValidateAsBrTelephoneMatcher < ValidationMatcher
|
11
11
|
def initialize(attribute)
|
12
12
|
@attribute = attribute
|
13
13
|
end
|
14
14
|
|
15
15
|
def description
|
16
|
-
"validate #{@attribute} as a valid Telephone number"
|
16
|
+
"validate #{@attribute} as a valid Telephone number for Brazil"
|
17
17
|
end
|
18
18
|
|
19
19
|
def failure_message
|
20
|
-
"expected #{@attribute} to be validated as a valid Telephone number"
|
20
|
+
"expected #{@attribute} to be validated as a valid Telephone number for Brazil"
|
21
21
|
end
|
22
22
|
|
23
23
|
def matches?(subject)
|
@@ -0,0 +1,45 @@
|
|
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,7 +1,12 @@
|
|
1
1
|
class Telephone
|
2
|
-
def initialize(number)
|
3
|
-
@match = number =~ /^(\(?\d{2}\)?)(\d{4})-?(\d{4})$/
|
2
|
+
def initialize(number, locale)
|
4
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
|
5
10
|
@cleaned_number = $1.nil? ? nil : @number.gsub(/[\(\)-]/, "")
|
6
11
|
format_number! if @cleaned_number
|
7
12
|
end
|
@@ -18,7 +23,12 @@ class Telephone
|
|
18
23
|
private
|
19
24
|
|
20
25
|
def format_number!
|
21
|
-
@
|
22
|
-
|
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
|
23
33
|
end
|
24
34
|
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
class CreateUsers < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
|
-
create_table :
|
3
|
+
create_table :br_users do |u|
|
4
|
+
u.string :telephone
|
5
|
+
end
|
6
|
+
create_table :en_users do |u|
|
4
7
|
u.string :telephone
|
5
8
|
end
|
6
9
|
end
|
7
10
|
|
8
11
|
def self.down
|
9
|
-
drop_table :
|
12
|
+
drop_table :br_users
|
13
|
+
drop_table :en_users
|
10
14
|
end
|
11
15
|
end
|
data/spec/fake_app/user.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'remarkable/active_record'
|
3
3
|
|
4
|
-
describe Remarkable::ActiveRecord::Matchers::
|
4
|
+
describe Remarkable::ActiveRecord::Matchers::ValidateAsBrTelephoneMatcher do
|
5
5
|
context "on a attribute which validates telephone" do
|
6
6
|
it "should require a valid telephone" do
|
7
|
-
@user =
|
8
|
-
@user.should
|
7
|
+
@user = BrUser.new(:telephone => '123456')
|
8
|
+
@user.should validate_as_br_telephone(:telephone)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should allow a nil value" do
|
12
|
-
@user =
|
13
|
-
@user.should
|
12
|
+
@user = BrUser.new(:telephone => nil)
|
13
|
+
@user.should validate_as_br_telephone(:telephone)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -20,7 +20,7 @@ describe Remarkable::ActiveRecord::Matchers::ValidateAsTelephoneMatcher do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should not require a valid telephone" do
|
23
|
-
@user.should_not
|
23
|
+
@user.should_not validate_as_br_telephone(:telephone)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -0,0 +1,26 @@
|
|
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,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'shoulda-matchers'
|
3
3
|
|
4
|
-
describe Shoulda::Matchers::ActiveModel::
|
4
|
+
describe Shoulda::Matchers::ActiveModel::ValidateAsBrTelephoneMatcher do
|
5
5
|
context "on a attribute which validates telephone" do
|
6
6
|
it "should require a valid telephone" do
|
7
|
-
@user =
|
8
|
-
@user.should
|
7
|
+
@user = BrUser.new(:telephone => '123456')
|
8
|
+
@user.should validate_as_br_telephone(:telephone)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should allow a nil value" do
|
12
|
-
@user =
|
13
|
-
@user.should
|
12
|
+
@user = BrUser.new(:telephone => nil)
|
13
|
+
@user.should validate_as_br_telephone(:telephone)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -20,7 +20,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateAsTelephoneMatcher do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should not require a valid telephone" do
|
23
|
-
@user.should_not
|
23
|
+
@user.should_not validate_as_br_telephone(:telephone)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -0,0 +1,26 @@
|
|
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
|
@@ -1,51 +1,103 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Telephone do
|
4
|
-
context "
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
context "with br as locale" do
|
5
|
+
context "should be invalid with" do
|
6
|
+
it "blank number" do
|
7
|
+
Telephone.new('', :br).should_not be_valid
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
it "123456 as number" do
|
11
|
+
Telephone.new('123456', :br).should_not be_valid
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
it "12345678910 as number" do
|
15
|
+
Telephone.new('12345678910', :br).should_not be_valid
|
16
|
+
end
|
15
17
|
end
|
16
|
-
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
context "should be valid with" do
|
20
|
+
it "nil as number" do
|
21
|
+
Telephone.new(nil, :br).should be_valid
|
22
|
+
end
|
23
|
+
|
24
|
+
it "1111111111 as number" do
|
25
|
+
Telephone.new('1111111111', :br).should be_valid
|
26
|
+
end
|
27
|
+
|
28
|
+
it "(11)11111111 as number" do
|
29
|
+
Telephone.new('(11)11111111', :br).should be_valid
|
30
|
+
end
|
31
|
+
|
32
|
+
it "111111-1111 as number" do
|
33
|
+
Telephone.new('111111-1111', :br).should be_valid
|
34
|
+
end
|
35
|
+
|
36
|
+
it "(11)1111-1111 as number" do
|
37
|
+
Telephone.new('(11)1111-1111', :br).should be_valid
|
38
|
+
end
|
21
39
|
end
|
22
40
|
|
23
|
-
|
24
|
-
|
41
|
+
context "with a valid value" do
|
42
|
+
it "should return it formatted" do
|
43
|
+
Telephone.new('1111111111', :br).number.should == '(11)1111-1111'
|
44
|
+
end
|
25
45
|
end
|
26
46
|
|
27
|
-
|
28
|
-
|
47
|
+
context "with an invalid value" do
|
48
|
+
it "should return as it was" do
|
49
|
+
Telephone.new('123456', :br).number.should == '123456'
|
50
|
+
end
|
29
51
|
end
|
52
|
+
end
|
30
53
|
|
31
|
-
|
32
|
-
|
54
|
+
context "with usa as locale" do
|
55
|
+
context "should be invalid with" do
|
56
|
+
it "blank number" do
|
57
|
+
Telephone.new('', :en).should_not be_valid
|
58
|
+
end
|
59
|
+
|
60
|
+
it "123456 as number" do
|
61
|
+
Telephone.new('123456', :en).should_not be_valid
|
62
|
+
end
|
63
|
+
|
64
|
+
it "12345678910 as number" do
|
65
|
+
Telephone.new('12345678910', :en).should_not be_valid
|
66
|
+
end
|
33
67
|
end
|
34
68
|
|
35
|
-
|
36
|
-
|
69
|
+
context "should be valid with" do
|
70
|
+
it "nil as number" do
|
71
|
+
Telephone.new(nil, :en).should be_valid
|
72
|
+
end
|
73
|
+
|
74
|
+
it "1111111111 as number" do
|
75
|
+
Telephone.new('1111111111', :en).should be_valid
|
76
|
+
end
|
77
|
+
|
78
|
+
it "(11)11111111 as number" do
|
79
|
+
Telephone.new('(111)1111111', :en).should be_valid
|
80
|
+
end
|
81
|
+
|
82
|
+
it "111111-1111 as number" do
|
83
|
+
Telephone.new('111111-1111', :en).should be_valid
|
84
|
+
end
|
85
|
+
|
86
|
+
it "(11)1111-1111 as number" do
|
87
|
+
Telephone.new('(111)111-1111', :en).should be_valid
|
88
|
+
end
|
37
89
|
end
|
38
|
-
end
|
39
90
|
|
40
|
-
|
41
|
-
|
42
|
-
|
91
|
+
context "with a valid value" do
|
92
|
+
it "should return it formatted" do
|
93
|
+
Telephone.new('1111111111', :en).number.should == '(111)111-1111'
|
94
|
+
end
|
43
95
|
end
|
44
|
-
end
|
45
96
|
|
46
|
-
|
47
|
-
|
48
|
-
|
97
|
+
context "with an invalid value" do
|
98
|
+
it "should return as it was" do
|
99
|
+
Telephone.new('123456', :en).number.should == '123456'
|
100
|
+
end
|
49
101
|
end
|
50
102
|
end
|
51
103
|
end
|
@@ -1,38 +1,78 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe TelephoneValidator do
|
4
|
-
context "
|
5
|
-
|
6
|
-
|
4
|
+
context "with br as locale" do
|
5
|
+
context "when telephone is invalid" do
|
6
|
+
before :each do
|
7
|
+
@user = BrUser.new(:telephone => "12345")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should set object as invalid" do
|
11
|
+
@user.valid?.should be_false
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should set an error on attribute" do
|
15
|
+
@user.valid?
|
16
|
+
@user.errors[:telephone].should == ['is invalid']
|
17
|
+
end
|
7
18
|
end
|
8
19
|
|
9
|
-
|
10
|
-
|
20
|
+
context "when telephone is valid" do
|
21
|
+
before :each do
|
22
|
+
@user = BrUser.new(:telephone => "(11)1111-1111")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should set object as valid" do
|
26
|
+
@user.valid?.should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not set an error on attribute" do
|
30
|
+
@user.valid?
|
31
|
+
@user.errors[:telephone].should be_blank
|
32
|
+
end
|
11
33
|
end
|
12
34
|
|
13
|
-
it "should
|
14
|
-
@user.
|
15
|
-
@user.
|
35
|
+
it "should accept a nil value" do
|
36
|
+
@user = BrUser.new(:telephone => nil)
|
37
|
+
@user.valid?.should be_true
|
16
38
|
end
|
17
39
|
end
|
18
40
|
|
19
|
-
context "
|
20
|
-
|
21
|
-
|
22
|
-
|
41
|
+
context "with usa as locale" do
|
42
|
+
context "when telephone is invalid" do
|
43
|
+
before :each do
|
44
|
+
@user = EnUser.new(:telephone => "12345")
|
45
|
+
end
|
23
46
|
|
24
|
-
|
25
|
-
|
47
|
+
it "should set object as invalid" do
|
48
|
+
@user.valid?.should be_false
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should set an error on attribute" do
|
52
|
+
@user.valid?
|
53
|
+
@user.errors[:telephone].should == ['is invalid']
|
54
|
+
end
|
26
55
|
end
|
27
56
|
|
28
|
-
|
29
|
-
|
30
|
-
|
57
|
+
context "when telephone is valid" do
|
58
|
+
before :each do
|
59
|
+
@user = EnUser.new(:telephone => "(111)111-1111")
|
60
|
+
@user.valid?
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should set object as valid" do
|
64
|
+
@user.valid?.should be_true
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should not set an error on attribute" do
|
68
|
+
@user.valid?
|
69
|
+
@user.errors[:telephone].should be_blank
|
70
|
+
end
|
31
71
|
end
|
32
|
-
end
|
33
72
|
|
34
|
-
|
35
|
-
|
36
|
-
|
73
|
+
it "should accept a nil value" do
|
74
|
+
@user = EnUser.new(:telephone => nil)
|
75
|
+
@user.valid?.should be_true
|
76
|
+
end
|
37
77
|
end
|
38
78
|
end
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-02-21 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &16238060 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *16238060
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &16236300 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *16236300
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &16235760 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.0.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *16235760
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: shoulda-matchers
|
49
|
-
requirement: &
|
49
|
+
requirement: &16235240 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.0.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *16235240
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: remarkable_activerecord
|
60
|
-
requirement: &
|
60
|
+
requirement: &16234660 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - =
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 4.0.0.alpha4
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *16234660
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: sqlite3
|
71
|
-
requirement: &
|
71
|
+
requirement: &16234240 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *16234240
|
80
80
|
description: Validates Telephone and test it with macros in a simple way.
|
81
81
|
email: plribeiro3000@gmail.com
|
82
82
|
executables: []
|
@@ -90,16 +90,20 @@ files:
|
|
90
90
|
- README.rdoc
|
91
91
|
- Rakefile
|
92
92
|
- lib/validates_telephone.rb
|
93
|
-
- lib/validates_telephone/remarkable/
|
94
|
-
- lib/validates_telephone/
|
93
|
+
- lib/validates_telephone/remarkable/validate_as_br_telephone_matcher.rb
|
94
|
+
- lib/validates_telephone/remarkable/validate_as_usa_telephone_matcher.rb
|
95
|
+
- lib/validates_telephone/shoulda-matchers/validate_as_br_telephone_matcher.rb
|
96
|
+
- lib/validates_telephone/shoulda-matchers/validate_as_usa_telephone_matcher.rb
|
95
97
|
- lib/validates_telephone/telephone.rb
|
96
98
|
- lib/validates_telephone/version.rb
|
97
99
|
- spec/fake_app/admin.rb
|
98
100
|
- spec/fake_app/db/create_admins.rb
|
99
101
|
- spec/fake_app/db/create_users.rb
|
100
102
|
- spec/fake_app/user.rb
|
101
|
-
- spec/remarkable/
|
102
|
-
- spec/
|
103
|
+
- spec/remarkable/validate_as_br_telephone_matcher_spec.rb
|
104
|
+
- spec/remarkable/validate_as_usa_telephone_matcher_spec.rb
|
105
|
+
- spec/shoulda-matchers/validate_as_br_telephone_matcher_spec.rb
|
106
|
+
- spec/shoulda-matchers/validate_as_usa_telephone_matcher_spec.rb
|
103
107
|
- spec/spec_helper.rb
|
104
108
|
- spec/validates_telephone/telephone_spec.rb
|
105
109
|
- spec/validates_telephone_spec.rb
|