validates_telephone 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,19 @@
1
1
  *.gem
2
+ *.rbc
2
3
  .bundle
4
+ .config
5
+ .yardoc
6
+ .coveralls.yml
7
+ *.swp
3
8
  Gemfile.lock
4
- pkg/*
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ tmp
18
+ .*~
19
+ *~
data/.rspec CHANGED
@@ -1 +1 @@
1
- --colour --format documentation
1
+ --colour --format documentation --profile
@@ -0,0 +1 @@
1
+ validates_telephone
@@ -0,0 +1 @@
1
+ 1.9.3
@@ -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 [![Build Status](https://secure.travis-ci.org/plribeiro3000/validates_telephone.png?branch=master)](http://travis-ci.org/plribeiro3000/validates_telephone)
1
+ # ValidatesTelephone
2
2
 
3
- Rails gem to validate Telephone.
3
+ [![Gem Version](https://badge.fury.io/rb/validates_telephone.png)](http://badge.fury.io/rb/validates_telephone) [![Build Status](https://secure.travis-ci.org/plribeiro3000/validates_telephone.png?branch=master)](http://travis-ci.org/plribeiro3000/validates_telephone) [![Dependency Status](https://gemnasium.com/plribeiro3000/validates_telephone.png)](https://gemnasium.com/plribeiro3000/validates_telephone) [![Coverage Status](https://coveralls.io/repos/plribeiro3000/validates_telephone/badge.png?branch=master)](https://coveralls.io/r/plribeiro3000/validates_telephone) [![Code Climate](https://codeclimate.com/github/plribeiro3000/validates_telephone.png)](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
- Since version 1.0.0, it isn’t necessary to load any file inside your spec_helper anymore.
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
 
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem 'activesupport', '3.2.14'
4
+
5
+ gemspec :path => '../'
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem 'activesupport', '>= 4.0.0'
4
+
5
+ gemspec :path => '../'
@@ -1,4 +1,5 @@
1
- require "shoulda-matchers"
1
+ require 'shoulda-matchers'
2
+ require 'active_support/core_ext/array/wrap'
2
3
 
3
4
  module Shoulda
4
5
  module Matchers
@@ -0,0 +1,5 @@
1
+ class TelephoneValidator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ record.errors.add(attribute, :invalid, options) unless ValidatesTelephone::Validator.new(value, options[:locale]).valid?
4
+ end
5
+ end
@@ -1,12 +1,8 @@
1
- #Validator
2
- require "validates_telephone/telephone_validator"
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, "validates_telephone/validator"
10
- autoload :Regex, "validates_telephone/regex"
11
- autoload :Formatter, "validates_telephone/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.nil?
11
+ return true if @number.blank?
11
12
  @match
12
13
  end
13
14
 
@@ -1,3 +1,3 @@
1
1
  module ValidatesTelephone
2
- VERSION = "1.1.0"
3
- end
2
+ VERSION = '2.0.0'
3
+ end
@@ -0,0 +1,8 @@
1
+ br:
2
+ activemodel:
3
+ errors:
4
+ models:
5
+ user:
6
+ attributes:
7
+ br_telephone:
8
+ invalid: 'is invalid'
@@ -0,0 +1,8 @@
1
+ usa:
2
+ activemodel:
3
+ errors:
4
+ models:
5
+ user:
6
+ attributes:
7
+ usa_telephone:
8
+ invalid: 'is invalid'
@@ -1,5 +1,17 @@
1
- class User < ActiveRecord::Base
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
@@ -1,10 +1,11 @@
1
- require "rubygems"
2
- require "rspec"
3
- require "active_record"
1
+ require 'rspec'
2
+ require 'active_model'
3
+ require 'coveralls'
4
4
 
5
- Dir.glob(File.dirname(__FILE__) + "/../lib/**/*.rb").each { |file| require file }
6
- Dir.glob(File.dirname(__FILE__) + "/fake_app/**/*.rb").each { |file| require file }
5
+ Coveralls.wear!
7
6
 
8
- ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
9
-
10
- CreateUsers.migrate(:up)
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 "with br as locale" do
5
- context "should be invalid with" do
6
- it "blank number" do
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 "12345678910 as number" do
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 "should be valid with" do
24
- it "nil as number" do
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 "1111111111 as number" do
28
+ it '1111111111 as number' do
29
29
  ValidatesTelephone::Validator.new('1111111111', :br).should be_valid
30
30
  end
31
31
 
32
- it "(11)11111111 as number" do
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 "111111-1111 as number" do
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 "(11)1111-1111 as number" do
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 "with a valid value" do
50
- it "should return it formatted" do
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 "with an invalid value" do
60
- it "should return as it was" do
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 "with usa as locale" do
67
- context "should be invalid with" do
68
- it "blank number" do
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 "12345678910 as number" do
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 "should be valid with" do
82
- it "nil as number" do
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 "1111111111 as number" do
86
+ it '1111111111 as number' do
87
87
  ValidatesTelephone::Validator.new('1111111111', :usa).should be_valid
88
88
  end
89
89
 
90
- it "(11)11111111 as number" do
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 "111111-1111 as number" do
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 "(111)111-1111 as number" do
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 "with a valid value" do
104
- it "should return it formatted" do
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 "with an invalid value" do
110
- it "should return as it was" do
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 "without locale" do
117
- context "should be invalid with" do
118
- it "blank number" do
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 "12345678910 as number" do
122
+ it '12345678910 as number' do
127
123
  ValidatesTelephone::Validator.new('12345678910').should_not be_valid
128
124
  end
129
125
 
130
- it "1111111111 as number" do
126
+ it '1111111111 as number' do
131
127
  ValidatesTelephone::Validator.new('1111111111').should_not be_valid
132
128
  end
133
129
 
134
- it "(11)11111111 as number" do
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 "111111-1111 as number" do
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 "should be valid with" do
144
- it "nil as number" do
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 "(11)1111-1111 as number" do
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 "(111)111-1111 as number" do
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 => "(11)1111-1111",
5
- :usa_telephone => "(111)111-1111",
6
- :telephone => "(111)111-1111" } }
4
+ let(:valid_numbers) { { :br_telephone => '(11)1111-1111',
5
+ :usa_telephone => '(111)111-1111',
6
+ :telephone => '(111)111-1111' } }
7
7
 
8
- context "on a field validated as a valid telephone from Brazil" do
9
- context "with an invalid number" do
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 => "12345"))
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 "should set object as invalid" do
14
+ it 'should set object as invalid' do
17
15
  @user.valid?.should be_false
18
16
  end
19
17
 
20
- it "should set an error on attribute" do
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 "with a valid number" do
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 "should set object as valid" do
29
+ it 'should set object as valid' do
32
30
  @user.valid?.should be_true
33
31
  end
34
32
 
35
- it "should not set an error on attribute" do
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 "should accept a nil value" do
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 "on a field validated as a valid telephone from United States" do
48
- context "with an invalid number" do
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 => "12345"))
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 "should set object as invalid" do
51
+ it 'should set object as invalid' do
56
52
  @user.valid?.should be_false
57
53
  end
58
54
 
59
- it "should set an error on attribute" do
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 "with a valid number" do
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 "should set object as valid" do
66
+ it 'should set object as valid' do
71
67
  @user.valid?.should be_true
72
68
  end
73
69
 
74
- it "should not set an error on attribute" do
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 "should accept a nil value" do
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 "on a field validated as a valid telephone" do
87
- context "with an invalid number" do
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 => "12345"))
90
- I18n.stub(:t).with(:"activerecord.errors.models.user.attributes.telephone.invalid",
91
- :default => :"activerecord.errors.messages.invalid").and_return("is invalid")
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 "should set object as invalid" do
90
+ it 'should set object as invalid' do
95
91
  @user.valid?.should be_false
96
92
  end
97
93
 
98
- it "should set an error on attribute" do
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 "with a valid number from Brazil" do
100
+ context 'with a valid number from Brazil' do
105
101
  before :each do
106
- @user = User.new(valid_numbers.merge(:telephone => "(11)1111-1111"))
102
+ @user = User.new(valid_numbers.merge(:telephone => '(11)1111-1111'))
107
103
  end
108
104
 
109
- it "should set object as valid" do
105
+ it 'should set object as valid' do
110
106
  @user.valid?.should be_true
111
107
  end
112
108
 
113
- it "should not set an error on attribute" do
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 "with a valid number from United States" do
115
+ context 'with a valid number from United States' do
120
116
  before :each do
121
- @user = User.new(valid_numbers.merge(:telephone => "(111)111-1111"))
117
+ @user = User.new(valid_numbers.merge(:telephone => '(111)111-1111'))
122
118
  end
123
119
 
124
- it "should set object as valid" do
120
+ it 'should set object as valid' do
125
121
  @user.valid?.should be_true
126
122
  end
127
123
 
128
- it "should not set an error on attribute" do
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 "should accept a nil value" do
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
@@ -1,26 +1,24 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "validates_telephone/version"
2
+ require File.expand_path('../lib/validates_telephone/version', __FILE__)
4
3
 
5
- Gem::Specification.new do |s|
6
- s.name = "validates_telephone"
7
- s.version = ValidatesTelephone::VERSION
8
- s.authors = ["Paulo Henrique Lopes Ribeiro"]
9
- s.email = %q{plribeiro3000@gmail.com}
10
- s.homepage = ""
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
- s.files = `git ls-files`.split("\n")
15
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
- s.require_paths = %w(lib)
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
- s.add_dependency "activemodel", ">= 3.0.0"
20
- s.add_development_dependency "activerecord", ">= 3.0.0"
21
- s.add_development_dependency "rake"
22
- s.add_development_dependency "rspec", ">= 2.0.0"
23
- s.add_development_dependency "shoulda-matchers", ">= 1.0.0"
24
- s.add_development_dependency "remarkable_activerecord", "= 4.0.0.alpha4"
25
- s.add_development_dependency "sqlite3"
26
- end
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: 1.1.0
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: 2012-08-27 00:00:00.000000000 Z
12
+ date: 2013-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: activemodel
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: 3.0.0
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: 3.0.0
29
+ version: '0'
46
30
  - !ruby/object:Gem::Dependency
47
- name: rake
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: rspec
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: shoulda-matchers
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: 1.0.0
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: 1.0.0
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: sqlite3
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: :development
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: Validates Telephone for Brazil and United States and test it with matchers
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
- - .rvmrc
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/db/create_users.rb
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: -3480777395687768892
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: -3480777395687768892
152
+ hash: 4137047763219948183
183
153
  requirements: []
184
154
  rubyforge_project:
185
- rubygems_version: 1.8.24
155
+ rubygems_version: 1.8.25
186
156
  signing_key:
187
157
  specification_version: 3
188
- summary: Telephone Validation GEM
189
- test_files: []
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,13 +0,0 @@
1
- class CreateUsers < ActiveRecord::Migration
2
- def self.up
3
- create_table :users do |u|
4
- u.string :telephone
5
- u.string :br_telephone
6
- u.string :usa_telephone
7
- end
8
- end
9
-
10
- def self.down
11
- drop_table :users
12
- end
13
- 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