validates_telephone 1.1.0 → 2.0.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/.gitignore +16 -1
- data/.rspec +1 -1
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +14 -1
- data/README.md +8 -7
- data/gemfiles/Gemfile.rails3 +5 -0
- data/gemfiles/Gemfile.rails4 +5 -0
- data/lib/{validates_telephone/shoulda-matchers/require_a_valid_telephone_matcher.rb → require_a_valid_telephone_matcher.rb} +2 -1
- data/lib/telephone_validator.rb +5 -0
- data/lib/validates_telephone.rb +5 -9
- data/lib/validates_telephone/validator.rb +2 -1
- data/lib/validates_telephone/version.rb +2 -2
- data/spec/fake_app/locales/br.yml +8 -0
- data/spec/fake_app/locales/usa.yml +8 -0
- data/spec/fake_app/user.rb +13 -1
- data/spec/{validates_telephone/shoulda-matchers/require_a_valid_telephone_matcher_spec.rb → require_a_valid_telephone_matcher_spec.rb} +0 -0
- data/spec/spec_helper.rb +9 -8
- data/spec/validates_telephone/validator_spec.rb +51 -51
- data/spec/validates_telephone_spec.rb +37 -41
- data/validates_telephone.gemspec +20 -22
- metadata +42 -62
- data/.rvmrc +0 -1
- data/lib/validates_telephone/remarkable/require_a_valid_telephone_matcher.rb +0 -43
- data/lib/validates_telephone/telephone_validator.rb +0 -7
- data/spec/fake_app/db/create_users.rb +0 -13
- data/spec/validates_telephone/remarkable/require_a_valid_telephone_matcher_spec.rb +0 -40
data/.gitignore
CHANGED
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--colour --format documentation
|
1
|
+
--colour --format documentation --profile
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
validates_telephone
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3
|
data/.travis.yml
CHANGED
@@ -1,4 +1,17 @@
|
|
1
1
|
rvm:
|
2
2
|
- 1.8.7
|
3
3
|
- 1.9.2
|
4
|
-
- 1.9.3
|
4
|
+
- 1.9.3
|
5
|
+
- jruby
|
6
|
+
- ree
|
7
|
+
gemfile:
|
8
|
+
- gemfiles/Gemfile.rails3
|
9
|
+
- gemfiles/Gemfile.rails4
|
10
|
+
matrix:
|
11
|
+
exclude:
|
12
|
+
- rvm: 1.8.7
|
13
|
+
gemfile: gemfiles/Gemfile.rails4
|
14
|
+
- rvm: 1.9.2
|
15
|
+
gemfile: gemfiles/Gemfile.rails4
|
16
|
+
- rvm: ree
|
17
|
+
gemfile: gemfiles/Gemfile.rails4
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
# ValidatesTelephone
|
1
|
+
# ValidatesTelephone
|
2
2
|
|
3
|
-
|
3
|
+
[](http://badge.fury.io/rb/validates_telephone) [](http://travis-ci.org/plribeiro3000/validates_telephone) [](https://gemnasium.com/plribeiro3000/validates_telephone) [](https://coveralls.io/r/plribeiro3000/validates_telephone) [](https://codeclimate.com/github/plribeiro3000/validates_telephone)
|
4
|
+
|
5
|
+
Validates telephone and test it in a simple way
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -35,13 +37,12 @@ class User < ActiveRecord::Base
|
|
35
37
|
end
|
36
38
|
```
|
37
39
|
|
38
|
-
## Test
|
39
|
-
|
40
|
-
This gem has builtin matchers for shoulda-matchers and remarkable.
|
41
|
-
|
42
40
|
## Notes
|
43
41
|
|
44
|
-
|
42
|
+
It will load a matcher to test automatically if the gem is defined after shoulda-matchers.
|
43
|
+
|
44
|
+
## Mantainers
|
45
|
+
[@plribeiro3000](https://github.com/plribeiro3000)
|
45
46
|
|
46
47
|
## Contributing
|
47
48
|
|
data/lib/validates_telephone.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
|
4
|
-
#Rspec Matchers
|
5
|
-
require "validates_telephone/shoulda-matchers/require_a_valid_telephone_matcher" if defined?(::Shoulda)
|
6
|
-
require "validates_telephone/remarkable/require_a_valid_telephone_matcher" if defined?(::Remarkable)
|
1
|
+
require 'telephone_validator'
|
2
|
+
require 'require_a_valid_telephone_matcher' if defined?(::Shoulda)
|
7
3
|
|
8
4
|
module ValidatesTelephone
|
9
|
-
autoload :Validator,
|
10
|
-
autoload :Regex,
|
11
|
-
autoload :Formatter,
|
5
|
+
autoload :Validator, 'validates_telephone/validator'
|
6
|
+
autoload :Regex, 'validates_telephone/regex'
|
7
|
+
autoload :Formatter, 'validates_telephone/formatter'
|
12
8
|
end
|
@@ -1,13 +1,14 @@
|
|
1
1
|
module ValidatesTelephone
|
2
2
|
class Validator
|
3
3
|
def initialize(number, locale = :any)
|
4
|
+
locale ||= :any
|
4
5
|
@number = number
|
5
6
|
@match = ValidatesTelephone::Regex.send(locale, @number)
|
6
7
|
@number = ValidatesTelephone::Formatter.send(locale, @number)
|
7
8
|
end
|
8
9
|
|
9
10
|
def valid?
|
10
|
-
return true if @number.
|
11
|
+
return true if @number.blank?
|
11
12
|
@match
|
12
13
|
end
|
13
14
|
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module ValidatesTelephone
|
2
|
-
VERSION =
|
3
|
-
end
|
2
|
+
VERSION = '2.0.0'
|
3
|
+
end
|
data/spec/fake_app/user.rb
CHANGED
@@ -1,5 +1,17 @@
|
|
1
|
-
class User
|
1
|
+
class User
|
2
|
+
include ActiveModel::Validations
|
3
|
+
include ActiveModel::Conversion
|
4
|
+
extend ActiveModel::Naming
|
5
|
+
|
6
|
+
attr_accessor :telephone, :br_telephone, :usa_telephone
|
7
|
+
|
2
8
|
validates :telephone, :telephone => true
|
3
9
|
validates :br_telephone, :telephone => { :locale => :br }
|
4
10
|
validates :usa_telephone, :telephone => { :locale => :usa }
|
11
|
+
|
12
|
+
def initialize(attributes = {})
|
13
|
+
attributes.each do |key, value|
|
14
|
+
instance_variable_set("@#{key}", value)
|
15
|
+
end
|
16
|
+
end
|
5
17
|
end
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'rspec'
|
2
|
+
require 'active_model'
|
3
|
+
require 'coveralls'
|
4
4
|
|
5
|
-
|
6
|
-
Dir.glob(File.dirname(__FILE__) + "/fake_app/**/*.rb").each { |file| require file }
|
5
|
+
Coveralls.wear!
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
Dir.glob(File.dirname(__FILE__) + '/../lib/**/*.rb').each { |file| require file }
|
8
|
+
Dir.glob(File.dirname(__FILE__) + '/fake_app/*.rb').each { |file| require file }
|
9
|
+
Dir.glob(File.dirname(__FILE__) + '/fake_app/locales/*.yml').each do |file|
|
10
|
+
I18n.load_path << file
|
11
|
+
end
|
@@ -1,17 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ValidatesTelephone::Validator do
|
4
|
-
context
|
5
|
-
context
|
6
|
-
it
|
7
|
-
ValidatesTelephone::Validator.new('', :br).should_not be_valid
|
8
|
-
end
|
9
|
-
|
10
|
-
it "123456 as number" do
|
4
|
+
context 'with br as locale' do
|
5
|
+
context 'should be invalid with' do
|
6
|
+
it '123456 as number' do
|
11
7
|
ValidatesTelephone::Validator.new('123456', :br).should_not be_valid
|
12
8
|
end
|
13
9
|
|
14
|
-
it
|
10
|
+
it '12345678910 as number' do
|
15
11
|
ValidatesTelephone::Validator.new('12345678910', :br).should_not be_valid
|
16
12
|
end
|
17
13
|
|
@@ -20,24 +16,28 @@ describe ValidatesTelephone::Validator do
|
|
20
16
|
end
|
21
17
|
end
|
22
18
|
|
23
|
-
context
|
24
|
-
it
|
19
|
+
context 'should be valid with' do
|
20
|
+
it 'blank number' do
|
21
|
+
ValidatesTelephone::Validator.new('', :br).should be_valid
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'nil as number' do
|
25
25
|
ValidatesTelephone::Validator.new(nil, :br).should be_valid
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
28
|
+
it '1111111111 as number' do
|
29
29
|
ValidatesTelephone::Validator.new('1111111111', :br).should be_valid
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
32
|
+
it '(11)11111111 as number' do
|
33
33
|
ValidatesTelephone::Validator.new('(11)11111111', :br).should be_valid
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
36
|
+
it '111111-1111 as number' do
|
37
37
|
ValidatesTelephone::Validator.new('111111-1111', :br).should be_valid
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
40
|
+
it '(11)1111-1111 as number' do
|
41
41
|
ValidatesTelephone::Validator.new('(11)1111-1111', :br).should be_valid
|
42
42
|
end
|
43
43
|
|
@@ -46,8 +46,8 @@ describe ValidatesTelephone::Validator do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
context
|
50
|
-
it
|
49
|
+
context 'with a valid value' do
|
50
|
+
it 'should return it formatted' do
|
51
51
|
ValidatesTelephone::Validator.new('1111111111', :br).number.should == '(11)1111-1111'
|
52
52
|
end
|
53
53
|
|
@@ -56,100 +56,100 @@ describe ValidatesTelephone::Validator do
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
context
|
60
|
-
it
|
59
|
+
context 'with an invalid value' do
|
60
|
+
it 'should return as it was' do
|
61
61
|
ValidatesTelephone::Validator.new('123456', :br).number.should == '123456'
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
context
|
67
|
-
context
|
68
|
-
it
|
69
|
-
ValidatesTelephone::Validator.new('', :usa).should_not be_valid
|
70
|
-
end
|
71
|
-
|
72
|
-
it "123456 as number" do
|
66
|
+
context 'with usa as locale' do
|
67
|
+
context 'should be invalid with' do
|
68
|
+
it '123456 as number' do
|
73
69
|
ValidatesTelephone::Validator.new('123456', :usa).should_not be_valid
|
74
70
|
end
|
75
71
|
|
76
|
-
it
|
72
|
+
it '12345678910 as number' do
|
77
73
|
ValidatesTelephone::Validator.new('12345678910', :usa).should_not be_valid
|
78
74
|
end
|
79
75
|
end
|
80
76
|
|
81
|
-
context
|
82
|
-
it
|
77
|
+
context 'should be valid with' do
|
78
|
+
it 'blank number' do
|
79
|
+
ValidatesTelephone::Validator.new('', :usa).should be_valid
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'nil as number' do
|
83
83
|
ValidatesTelephone::Validator.new(nil, :usa).should be_valid
|
84
84
|
end
|
85
85
|
|
86
|
-
it
|
86
|
+
it '1111111111 as number' do
|
87
87
|
ValidatesTelephone::Validator.new('1111111111', :usa).should be_valid
|
88
88
|
end
|
89
89
|
|
90
|
-
it
|
90
|
+
it '(11)11111111 as number' do
|
91
91
|
ValidatesTelephone::Validator.new('(111)1111111', :usa).should be_valid
|
92
92
|
end
|
93
93
|
|
94
|
-
it
|
94
|
+
it '111111-1111 as number' do
|
95
95
|
ValidatesTelephone::Validator.new('111111-1111', :usa).should be_valid
|
96
96
|
end
|
97
97
|
|
98
|
-
it
|
98
|
+
it '(111)111-1111 as number' do
|
99
99
|
ValidatesTelephone::Validator.new('(111)111-1111', :usa).should be_valid
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
-
context
|
104
|
-
it
|
103
|
+
context 'with a valid value' do
|
104
|
+
it 'should return it formatted' do
|
105
105
|
ValidatesTelephone::Validator.new('1111111111', :usa).number.should == '(111)111-1111'
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
context
|
110
|
-
it
|
109
|
+
context 'with an invalid value' do
|
110
|
+
it 'should return as it was' do
|
111
111
|
ValidatesTelephone::Validator.new('123456', :usa).number.should == '123456'
|
112
112
|
end
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
-
context
|
117
|
-
context
|
118
|
-
it
|
119
|
-
ValidatesTelephone::Validator.new('').should_not be_valid
|
120
|
-
end
|
121
|
-
|
122
|
-
it "123456 as number" do
|
116
|
+
context 'without locale' do
|
117
|
+
context 'should be invalid with' do
|
118
|
+
it '123456 as number' do
|
123
119
|
ValidatesTelephone::Validator.new('123456').should_not be_valid
|
124
120
|
end
|
125
121
|
|
126
|
-
it
|
122
|
+
it '12345678910 as number' do
|
127
123
|
ValidatesTelephone::Validator.new('12345678910').should_not be_valid
|
128
124
|
end
|
129
125
|
|
130
|
-
it
|
126
|
+
it '1111111111 as number' do
|
131
127
|
ValidatesTelephone::Validator.new('1111111111').should_not be_valid
|
132
128
|
end
|
133
129
|
|
134
|
-
it
|
130
|
+
it '(11)11111111 as number' do
|
135
131
|
ValidatesTelephone::Validator.new('(111)1111111').should_not be_valid
|
136
132
|
end
|
137
133
|
|
138
|
-
it
|
134
|
+
it '111111-1111 as number' do
|
139
135
|
ValidatesTelephone::Validator.new('111111-1111').should_not be_valid
|
140
136
|
end
|
141
137
|
end
|
142
138
|
|
143
|
-
context
|
144
|
-
it
|
139
|
+
context 'should be valid with' do
|
140
|
+
it 'blank number' do
|
141
|
+
ValidatesTelephone::Validator.new('').should be_valid
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'nil as number' do
|
145
145
|
ValidatesTelephone::Validator.new(nil).should be_valid
|
146
146
|
end
|
147
147
|
|
148
|
-
it
|
148
|
+
it '(11)1111-1111 as number' do
|
149
149
|
ValidatesTelephone::Validator.new('(11)1111-1111').should be_valid
|
150
150
|
end
|
151
151
|
|
152
|
-
it
|
152
|
+
it '(111)111-1111 as number' do
|
153
153
|
ValidatesTelephone::Validator.new('(111)111-1111').should be_valid
|
154
154
|
end
|
155
155
|
end
|
@@ -1,137 +1,133 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe TelephoneValidator do
|
4
|
-
let(:valid_numbers) { { :br_telephone =>
|
5
|
-
:usa_telephone =>
|
6
|
-
:telephone =>
|
4
|
+
let(:valid_numbers) { { :br_telephone => '(11)1111-1111',
|
5
|
+
:usa_telephone => '(111)111-1111',
|
6
|
+
:telephone => '(111)111-1111' } }
|
7
7
|
|
8
|
-
context
|
9
|
-
context
|
8
|
+
context 'on a field validated as a valid telephone from Brazil' do
|
9
|
+
context 'with an invalid number' do
|
10
10
|
before :each do
|
11
|
-
@user = User.new(valid_numbers.merge(:br_telephone =>
|
12
|
-
I18n.stub(:t).with(:"activerecord.errors.models.user.attributes.br_telephone.invalid",
|
13
|
-
:default => :"activerecord.errors.messages.invalid").and_return("is invalid")
|
11
|
+
@user = User.new(valid_numbers.merge(:br_telephone => '12345'))
|
14
12
|
end
|
15
13
|
|
16
|
-
it
|
14
|
+
it 'should set object as invalid' do
|
17
15
|
@user.valid?.should be_false
|
18
16
|
end
|
19
17
|
|
20
|
-
it
|
18
|
+
it 'should set an error on attribute' do
|
21
19
|
@user.valid?
|
22
20
|
@user.errors[:br_telephone].should == ['is invalid']
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
26
|
-
context
|
24
|
+
context 'with a valid number' do
|
27
25
|
before :each do
|
28
26
|
@user = User.new(valid_numbers)
|
29
27
|
end
|
30
28
|
|
31
|
-
it
|
29
|
+
it 'should set object as valid' do
|
32
30
|
@user.valid?.should be_true
|
33
31
|
end
|
34
32
|
|
35
|
-
it
|
33
|
+
it 'should not set an error on attribute' do
|
36
34
|
@user.valid?
|
37
35
|
@user.errors[:br_telephone].should be_blank
|
38
36
|
end
|
39
37
|
end
|
40
38
|
|
41
|
-
it
|
39
|
+
it 'should accept a nil value' do
|
42
40
|
@user = User.new(valid_numbers.merge(:br_telephone => nil))
|
43
41
|
@user.valid?.should be_true
|
44
42
|
end
|
45
43
|
end
|
46
44
|
|
47
|
-
context
|
48
|
-
context
|
45
|
+
context 'on a field validated as a valid telephone from United States' do
|
46
|
+
context 'with an invalid number' do
|
49
47
|
before :each do
|
50
|
-
@user = User.new(valid_numbers.merge(:usa_telephone =>
|
51
|
-
I18n.stub(:t).with(:"activerecord.errors.models.user.attributes.usa_telephone.invalid",
|
52
|
-
:default => :"activerecord.errors.messages.invalid").and_return("is invalid")
|
48
|
+
@user = User.new(valid_numbers.merge(:usa_telephone => '12345'))
|
53
49
|
end
|
54
50
|
|
55
|
-
it
|
51
|
+
it 'should set object as invalid' do
|
56
52
|
@user.valid?.should be_false
|
57
53
|
end
|
58
54
|
|
59
|
-
it
|
55
|
+
it 'should set an error on attribute' do
|
60
56
|
@user.valid?
|
61
57
|
@user.errors[:usa_telephone].should == ['is invalid']
|
62
58
|
end
|
63
59
|
end
|
64
60
|
|
65
|
-
context
|
61
|
+
context 'with a valid number' do
|
66
62
|
before :each do
|
67
63
|
@user = User.new(valid_numbers)
|
68
64
|
end
|
69
65
|
|
70
|
-
it
|
66
|
+
it 'should set object as valid' do
|
71
67
|
@user.valid?.should be_true
|
72
68
|
end
|
73
69
|
|
74
|
-
it
|
70
|
+
it 'should not set an error on attribute' do
|
75
71
|
@user.valid?
|
76
72
|
@user.errors[:usa_telephone].should be_blank
|
77
73
|
end
|
78
74
|
end
|
79
75
|
|
80
|
-
it
|
76
|
+
it 'should accept a nil value' do
|
81
77
|
@user = User.new(valid_numbers.merge(:usa_telephone => nil))
|
82
78
|
@user.valid?.should be_true
|
83
79
|
end
|
84
80
|
end
|
85
81
|
|
86
|
-
context
|
87
|
-
context
|
82
|
+
context 'on a field validated as a valid telephone' do
|
83
|
+
context 'with an invalid number' do
|
88
84
|
before :each do
|
89
|
-
@user = User.new(valid_numbers.merge(:telephone =>
|
90
|
-
I18n.stub(:t).with(:
|
91
|
-
:default => :
|
85
|
+
@user = User.new(valid_numbers.merge(:telephone => '12345'))
|
86
|
+
I18n.stub(:t).with(:'activerecord.errors.models.user.attributes.telephone.invalid',
|
87
|
+
:default => :'activerecord.errors.messages.invalid').and_return('is invalid')
|
92
88
|
end
|
93
89
|
|
94
|
-
it
|
90
|
+
it 'should set object as invalid' do
|
95
91
|
@user.valid?.should be_false
|
96
92
|
end
|
97
93
|
|
98
|
-
it
|
94
|
+
it 'should set an error on attribute' do
|
99
95
|
@user.valid?
|
100
96
|
@user.errors[:telephone].should == ['is invalid']
|
101
97
|
end
|
102
98
|
end
|
103
99
|
|
104
|
-
context
|
100
|
+
context 'with a valid number from Brazil' do
|
105
101
|
before :each do
|
106
|
-
@user = User.new(valid_numbers.merge(:telephone =>
|
102
|
+
@user = User.new(valid_numbers.merge(:telephone => '(11)1111-1111'))
|
107
103
|
end
|
108
104
|
|
109
|
-
it
|
105
|
+
it 'should set object as valid' do
|
110
106
|
@user.valid?.should be_true
|
111
107
|
end
|
112
108
|
|
113
|
-
it
|
109
|
+
it 'should not set an error on attribute' do
|
114
110
|
@user.valid?
|
115
111
|
@user.errors[:telephone].should be_blank
|
116
112
|
end
|
117
113
|
end
|
118
114
|
|
119
|
-
context
|
115
|
+
context 'with a valid number from United States' do
|
120
116
|
before :each do
|
121
|
-
@user = User.new(valid_numbers.merge(:telephone =>
|
117
|
+
@user = User.new(valid_numbers.merge(:telephone => '(111)111-1111'))
|
122
118
|
end
|
123
119
|
|
124
|
-
it
|
120
|
+
it 'should set object as valid' do
|
125
121
|
@user.valid?.should be_true
|
126
122
|
end
|
127
123
|
|
128
|
-
it
|
124
|
+
it 'should not set an error on attribute' do
|
129
125
|
@user.valid?
|
130
126
|
@user.errors[:telephone].should be_blank
|
131
127
|
end
|
132
128
|
end
|
133
129
|
|
134
|
-
it
|
130
|
+
it 'should accept a nil value' do
|
135
131
|
@user = User.new(valid_numbers.merge(:usa_telephone => nil))
|
136
132
|
@user.valid?.should be_true
|
137
133
|
end
|
data/validates_telephone.gemspec
CHANGED
@@ -1,26 +1,24 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require "validates_telephone/version"
|
2
|
+
require File.expand_path('../lib/validates_telephone/version', __FILE__)
|
4
3
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
s.summary = %q{Telephone Validation GEM}
|
12
|
-
s.description = %q{Validates Telephone for Brazil and United States and test it with matchers in a simple way.}
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "validates_telephone"
|
6
|
+
gem.version = ValidatesTelephone::VERSION
|
7
|
+
gem.authors = %q{Paulo Henrique Lopes Ribeiro}
|
8
|
+
gem.email = %q{plribeiro3000@gmail.com}
|
9
|
+
gem.summary = %q{Validates Telephone for Brazil and United States and test it with matchers in a simple way.}
|
13
10
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
gem.files = `git ls-files`.split("\n")
|
12
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
14
|
+
gem.require_paths = %w(lib)
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
16
|
+
gem.license = 'MIT'
|
17
|
+
|
18
|
+
gem.add_development_dependency 'rake'
|
19
|
+
gem.add_development_dependency 'rspec'
|
20
|
+
gem.add_development_dependency 'shoulda-matchers', '2.0.0'
|
21
|
+
gem.add_development_dependency 'coveralls'
|
22
|
+
|
23
|
+
gem.add_runtime_dependency 'activemodel'
|
24
|
+
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:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,32 +9,16 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-10-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 3.0.0
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 3.0.0
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: activerecord
|
15
|
+
name: rake
|
32
16
|
requirement: !ruby/object:Gem::Requirement
|
33
17
|
none: false
|
34
18
|
requirements:
|
35
19
|
- - ! '>='
|
36
20
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
21
|
+
version: '0'
|
38
22
|
type: :development
|
39
23
|
prerelease: false
|
40
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,9 +26,9 @@ dependencies:
|
|
42
26
|
requirements:
|
43
27
|
- - ! '>='
|
44
28
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
29
|
+
version: '0'
|
46
30
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
31
|
+
name: rspec
|
48
32
|
requirement: !ruby/object:Gem::Requirement
|
49
33
|
none: false
|
50
34
|
requirements:
|
@@ -60,11 +44,11 @@ dependencies:
|
|
60
44
|
- !ruby/object:Gem::Version
|
61
45
|
version: '0'
|
62
46
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
47
|
+
name: shoulda-matchers
|
64
48
|
requirement: !ruby/object:Gem::Requirement
|
65
49
|
none: false
|
66
50
|
requirements:
|
67
|
-
- -
|
51
|
+
- - '='
|
68
52
|
- !ruby/object:Gem::Version
|
69
53
|
version: 2.0.0
|
70
54
|
type: :development
|
@@ -72,17 +56,17 @@ dependencies:
|
|
72
56
|
version_requirements: !ruby/object:Gem::Requirement
|
73
57
|
none: false
|
74
58
|
requirements:
|
75
|
-
- -
|
59
|
+
- - '='
|
76
60
|
- !ruby/object:Gem::Version
|
77
61
|
version: 2.0.0
|
78
62
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
63
|
+
name: coveralls
|
80
64
|
requirement: !ruby/object:Gem::Requirement
|
81
65
|
none: false
|
82
66
|
requirements:
|
83
67
|
- - ! '>='
|
84
68
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
69
|
+
version: '0'
|
86
70
|
type: :development
|
87
71
|
prerelease: false
|
88
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -90,32 +74,16 @@ dependencies:
|
|
90
74
|
requirements:
|
91
75
|
- - ! '>='
|
92
76
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: remarkable_activerecord
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- - '='
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: 4.0.0.alpha4
|
102
|
-
type: :development
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - '='
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: 4.0.0.alpha4
|
77
|
+
version: '0'
|
110
78
|
- !ruby/object:Gem::Dependency
|
111
|
-
name:
|
79
|
+
name: activemodel
|
112
80
|
requirement: !ruby/object:Gem::Requirement
|
113
81
|
none: false
|
114
82
|
requirements:
|
115
83
|
- - ! '>='
|
116
84
|
- !ruby/object:Gem::Version
|
117
85
|
version: '0'
|
118
|
-
type: :
|
86
|
+
type: :runtime
|
119
87
|
prerelease: false
|
120
88
|
version_requirements: !ruby/object:Gem::Requirement
|
121
89
|
none: false
|
@@ -123,8 +91,7 @@ dependencies:
|
|
123
91
|
- - ! '>='
|
124
92
|
- !ruby/object:Gem::Version
|
125
93
|
version: '0'
|
126
|
-
description:
|
127
|
-
in a simple way.
|
94
|
+
description:
|
128
95
|
email: plribeiro3000@gmail.com
|
129
96
|
executables: []
|
130
97
|
extensions: []
|
@@ -132,32 +99,35 @@ extra_rdoc_files: []
|
|
132
99
|
files:
|
133
100
|
- .gitignore
|
134
101
|
- .rspec
|
135
|
-
- .
|
102
|
+
- .ruby-gemset
|
103
|
+
- .ruby-version
|
136
104
|
- .travis.yml
|
137
105
|
- Gemfile
|
138
106
|
- LICENSE
|
139
107
|
- README.md
|
140
108
|
- Rakefile
|
109
|
+
- gemfiles/Gemfile.rails3
|
110
|
+
- gemfiles/Gemfile.rails4
|
111
|
+
- lib/require_a_valid_telephone_matcher.rb
|
112
|
+
- lib/telephone_validator.rb
|
141
113
|
- lib/validates_telephone.rb
|
142
114
|
- lib/validates_telephone/formatter.rb
|
143
115
|
- lib/validates_telephone/regex.rb
|
144
|
-
- lib/validates_telephone/remarkable/require_a_valid_telephone_matcher.rb
|
145
|
-
- lib/validates_telephone/shoulda-matchers/require_a_valid_telephone_matcher.rb
|
146
|
-
- lib/validates_telephone/telephone_validator.rb
|
147
116
|
- lib/validates_telephone/validator.rb
|
148
117
|
- lib/validates_telephone/version.rb
|
149
|
-
- spec/fake_app/
|
118
|
+
- spec/fake_app/locales/br.yml
|
119
|
+
- spec/fake_app/locales/usa.yml
|
150
120
|
- spec/fake_app/user.rb
|
121
|
+
- spec/require_a_valid_telephone_matcher_spec.rb
|
151
122
|
- spec/spec_helper.rb
|
152
123
|
- spec/validates_telephone/formatter_spec.rb
|
153
124
|
- spec/validates_telephone/regex_spec.rb
|
154
|
-
- spec/validates_telephone/remarkable/require_a_valid_telephone_matcher_spec.rb
|
155
|
-
- spec/validates_telephone/shoulda-matchers/require_a_valid_telephone_matcher_spec.rb
|
156
125
|
- spec/validates_telephone/validator_spec.rb
|
157
126
|
- spec/validates_telephone_spec.rb
|
158
127
|
- validates_telephone.gemspec
|
159
|
-
homepage:
|
160
|
-
licenses:
|
128
|
+
homepage:
|
129
|
+
licenses:
|
130
|
+
- MIT
|
161
131
|
post_install_message:
|
162
132
|
rdoc_options: []
|
163
133
|
require_paths:
|
@@ -170,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
170
140
|
version: '0'
|
171
141
|
segments:
|
172
142
|
- 0
|
173
|
-
hash:
|
143
|
+
hash: 4137047763219948183
|
174
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
145
|
none: false
|
176
146
|
requirements:
|
@@ -179,11 +149,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
149
|
version: '0'
|
180
150
|
segments:
|
181
151
|
- 0
|
182
|
-
hash:
|
152
|
+
hash: 4137047763219948183
|
183
153
|
requirements: []
|
184
154
|
rubyforge_project:
|
185
|
-
rubygems_version: 1.8.
|
155
|
+
rubygems_version: 1.8.25
|
186
156
|
signing_key:
|
187
157
|
specification_version: 3
|
188
|
-
summary: Telephone
|
189
|
-
|
158
|
+
summary: Validates Telephone for Brazil and United States and test it with matchers
|
159
|
+
in a simple way.
|
160
|
+
test_files:
|
161
|
+
- spec/fake_app/locales/br.yml
|
162
|
+
- spec/fake_app/locales/usa.yml
|
163
|
+
- spec/fake_app/user.rb
|
164
|
+
- spec/require_a_valid_telephone_matcher_spec.rb
|
165
|
+
- spec/spec_helper.rb
|
166
|
+
- spec/validates_telephone/formatter_spec.rb
|
167
|
+
- spec/validates_telephone/regex_spec.rb
|
168
|
+
- spec/validates_telephone/validator_spec.rb
|
169
|
+
- spec/validates_telephone_spec.rb
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm use 1.9.3@validates_telephone
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'remarkable/active_model'
|
2
|
-
|
3
|
-
module Remarkable
|
4
|
-
module ActiveModel
|
5
|
-
module Matchers
|
6
|
-
class RequireAValidTelephoneMatcher < Remarkable::ActiveModel::Base
|
7
|
-
arguments :telephone
|
8
|
-
|
9
|
-
optional :locale
|
10
|
-
|
11
|
-
collection_assertions :telephone_valid?, :telephone_invalid?
|
12
|
-
|
13
|
-
protected
|
14
|
-
|
15
|
-
def telephone_valid?
|
16
|
-
return allows_value_of("(111)222-3333") if @options[:locale] == :usa
|
17
|
-
return (allows_value_of("(11)2222-3333") and allows_value_of("(11)91111-1111")) if @options[:locale] == :br
|
18
|
-
allows_value_of("(111)222-3333") and allows_value_of("(11)2222-3333")
|
19
|
-
end
|
20
|
-
|
21
|
-
def telephone_invalid?
|
22
|
-
return (disallows_value_of("123456") and disallows_value_of("(11)2222-3333")) if @options[:locale] == :usa
|
23
|
-
return (disallows_value_of("123456") and disallows_value_of("(111)222-3333") and disallows_value_of("(11)81111-1111")) if @options[:locale] == :br
|
24
|
-
disallows_value_of("123456")
|
25
|
-
end
|
26
|
-
|
27
|
-
def allows_value_of(telephone)
|
28
|
-
@subject.telephone = telephone
|
29
|
-
@subject.valid?.errors[:telephone].should be_blank
|
30
|
-
end
|
31
|
-
|
32
|
-
def disallows_value_of(telephone)
|
33
|
-
@subject.telephone = telephone
|
34
|
-
@subject.valid?.errors[:telephone].should == ['is invalid']
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def require_a_valid_telephone(*args, &block)
|
39
|
-
RequireAValidTelephoneMatcher.new(*args, &block).spec(self)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,7 +0,0 @@
|
|
1
|
-
class TelephoneValidator < ActiveModel::EachValidator
|
2
|
-
def validate_each(record, attribute, value)
|
3
|
-
key = :"activerecord.errors.models.#{record.class.name.downcase}.attributes.#{attribute.to_s}.invalid"
|
4
|
-
locale = (options[:locale] or :any)
|
5
|
-
record.errors[attribute] << I18n.t(key, :default => :"activerecord.errors.messages.invalid") unless ValidatesTelephone::Validator.new(value, locale).valid?
|
6
|
-
end
|
7
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'remarkable/active_model'
|
3
|
-
|
4
|
-
describe Remarkable::ActiveModel::Matchers::RequireAValidTelephoneMatcher do
|
5
|
-
before :each do
|
6
|
-
@user = User.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should accept on telephone" do
|
10
|
-
@user.should require_a_valid_telephone(:telephone)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should accept without a specified attribute" do
|
14
|
-
@user.should require_a_valid_telephone
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should reject on br_telephone" do
|
18
|
-
@user.should_not require_a_valid_telephone(:br_telephone)
|
19
|
-
end
|
20
|
-
|
21
|
-
context "with :br as locale" do
|
22
|
-
it "should accept on br_telephone" do
|
23
|
-
@user.should require_a_valid_telephone(:br_telephone).from(:br)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should reject on usa_telephone" do
|
27
|
-
@user.should_not require_a_valid_telephone(:usa_telephone).from(:br)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "with :usa as locale" do
|
32
|
-
it "should accept on usa_telephone" do
|
33
|
-
@user.should require_a_valid_telephone(:usa_telephone).from(:usa)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should reject on br_telephone" do
|
37
|
-
@user.should_not require_a_valid_telephone(:br_telephone).from(:usa)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|