activevalidators 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
1
+ require 'test_helper.rb'
2
+
3
+ describe "Url Validation" do
4
+ def build_url_record
5
+ TestRecord.reset_callbacks(:validate)
6
+ TestRecord.validates :url, :url => true
7
+ TestRecord.new
8
+ end
9
+
10
+ it "accepts valid urls" do
11
+ subject = build_url_record
12
+ subject.url = 'http://www.verrot.fr'
13
+ subject.valid?.must_equal true
14
+ subject.errors.size.must_equal 0
15
+ end
16
+
17
+ it "accepts valid SSL urls" do
18
+ subject = build_url_record
19
+ subject.url = 'https://www.verrot.fr'
20
+ subject.valid?.must_equal true
21
+ subject.errors.size.must_equal 0
22
+ end
23
+
24
+ describe "for invalid urls" do
25
+ it "rejects invalid urls" do
26
+ subject = build_url_record
27
+ subject.url = 'http://^^^^.fr'
28
+ subject.valid?.must_equal false
29
+ subject.errors.size.must_equal 1
30
+ end
31
+
32
+ it "generates an error message of type invalid" do
33
+ subject = build_url_record
34
+ subject.url = 'http://^^^^.fr'
35
+ subject.valid?.must_equal false
36
+ subject.errors[:url].include?(subject.errors.generate_message(:url, :invalid)).must_equal true
37
+ end
38
+ end
39
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activevalidators
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 5
9
- - 1
10
- version: 1.5.1
8
+ - 6
9
+ - 0
10
+ version: 1.6.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Franck Verrot
@@ -20,8 +20,7 @@ autorequire:
20
20
  bindir: bin
21
21
  cert_chain: []
22
22
 
23
- date: 2011-05-13 00:00:00 +02:00
24
- default_executable:
23
+ date: 2011-09-09 00:00:00 Z
25
24
  dependencies:
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: bundler
@@ -38,7 +37,7 @@ dependencies:
38
37
  type: :development
39
38
  version_requirements: *id001
40
39
  - !ruby/object:Gem::Dependency
41
- name: rspec
40
+ name: minitest
42
41
  prerelease: false
43
42
  requirement: &id002 !ruby/object:Gem::Requirement
44
43
  none: false
@@ -52,7 +51,7 @@ dependencies:
52
51
  type: :development
53
52
  version_requirements: *id002
54
53
  - !ruby/object:Gem::Dependency
55
- name: rspec-core
54
+ name: turn
56
55
  prerelease: false
57
56
  requirement: &id003 !ruby/object:Gem::Requirement
58
57
  none: false
@@ -66,18 +65,20 @@ dependencies:
66
65
  type: :development
67
66
  version_requirements: *id003
68
67
  - !ruby/object:Gem::Dependency
69
- name: rspec-expectations
68
+ name: rake
70
69
  prerelease: false
71
70
  requirement: &id004 !ruby/object:Gem::Requirement
72
71
  none: false
73
72
  requirements:
74
73
  - - ">="
75
74
  - !ruby/object:Gem::Version
76
- hash: 3
75
+ hash: 49
77
76
  segments:
78
77
  - 0
79
- version: "0"
80
- type: :development
78
+ - 8
79
+ - 7
80
+ version: 0.8.7
81
+ type: :runtime
81
82
  version_requirements: *id004
82
83
  - !ruby/object:Gem::Dependency
83
84
  name: activerecord
@@ -85,7 +86,7 @@ dependencies:
85
86
  requirement: &id005 !ruby/object:Gem::Requirement
86
87
  none: false
87
88
  requirements:
88
- - - ~>
89
+ - - ">="
89
90
  - !ruby/object:Gem::Version
90
91
  hash: 7
91
92
  segments:
@@ -101,7 +102,7 @@ dependencies:
101
102
  requirement: &id006 !ruby/object:Gem::Requirement
102
103
  none: false
103
104
  requirements:
104
- - - ~>
105
+ - - ">="
105
106
  - !ruby/object:Gem::Version
106
107
  hash: 7
107
108
  segments:
@@ -117,14 +118,12 @@ dependencies:
117
118
  requirement: &id007 !ruby/object:Gem::Requirement
118
119
  none: false
119
120
  requirements:
120
- - - ~>
121
+ - - ">="
121
122
  - !ruby/object:Gem::Version
122
- hash: 25
123
+ hash: 3
123
124
  segments:
124
- - 2
125
- - 2
126
- - 15
127
- version: 2.2.15
125
+ - 0
126
+ version: "0"
128
127
  type: :runtime
129
128
  version_requirements: *id007
130
129
  - !ruby/object:Gem::Dependency
@@ -133,32 +132,14 @@ dependencies:
133
132
  requirement: &id008 !ruby/object:Gem::Requirement
134
133
  none: false
135
134
  requirements:
136
- - - ~>
135
+ - - ">="
137
136
  - !ruby/object:Gem::Version
138
- hash: 5
137
+ hash: 3
139
138
  segments:
140
139
  - 0
141
- - 6
142
- - 1
143
- version: 0.6.1
140
+ version: "0"
144
141
  type: :runtime
145
142
  version_requirements: *id008
146
- - !ruby/object:Gem::Dependency
147
- name: date_validator
148
- prerelease: false
149
- requirement: &id009 !ruby/object:Gem::Requirement
150
- none: false
151
- requirements:
152
- - - ~>
153
- - !ruby/object:Gem::Version
154
- hash: 5
155
- segments:
156
- - 0
157
- - 6
158
- - 1
159
- version: 0.6.1
160
- type: :runtime
161
- version_requirements: *id009
162
143
  description: ActiveValidators is a collection of ActiveModel/ActiveRecord validations
163
144
  email:
164
145
  - franck@verrot.fr
@@ -169,14 +150,13 @@ extensions: []
169
150
  extra_rdoc_files: []
170
151
 
171
152
  files:
172
- - .bundle/config
173
153
  - .gitignore
154
+ - .travis.yml
174
155
  - Gemfile
175
156
  - LICENSE
176
157
  - README.md
177
158
  - Rakefile
178
159
  - activevalidators.gemspec
179
- - autotest/discover.rb
180
160
  - lib/active_model/validations/credit_card_validator.rb
181
161
  - lib/active_model/validations/email_validator.rb
182
162
  - lib/active_model/validations/ip_validator.rb
@@ -188,21 +168,20 @@ files:
188
168
  - lib/active_model/validations/tracking_number_validator.rb
189
169
  - lib/active_model/validations/twitter_validator.rb
190
170
  - lib/active_model/validations/url_validator.rb
171
+ - lib/active_validators/version.rb
191
172
  - lib/activevalidators.rb
192
- - spec/activevalidators_spec.rb
193
- - spec/spec_helper.rb
194
- - spec/validations/credit_card_spec.rb
195
- - spec/validations/email_spec.rb
196
- - spec/validations/ip_spec.rb
197
- - spec/validations/password_spec.rb
198
- - spec/validations/phone_spec.rb
199
- - spec/validations/postal_code_spec.rb
200
- - spec/validations/respond_to_spec.rb
201
- - spec/validations/slug_spec.rb
202
- - spec/validations/tracking_number_spec.rb
203
- - spec/validations/twitter_spec.rb
204
- - spec/validations/url_spec.rb
205
- has_rdoc: true
173
+ - test/test_helper.rb
174
+ - test/validations/credit_card_test.rb
175
+ - test/validations/email_test.rb
176
+ - test/validations/ip_test.rb
177
+ - test/validations/password_test.rb
178
+ - test/validations/phone_test.rb
179
+ - test/validations/postal_code_test.rb
180
+ - test/validations/respond_to_test.rb
181
+ - test/validations/slug_test.rb
182
+ - test/validations/tracking_number_test.rb
183
+ - test/validations/twitter_test.rb
184
+ - test/validations/url_test.rb
206
185
  homepage: http://github.com/cesario/activevalidators
207
186
  licenses: []
208
187
 
@@ -232,21 +211,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
211
  requirements: []
233
212
 
234
213
  rubyforge_project:
235
- rubygems_version: 1.6.2
214
+ rubygems_version: 1.8.10
236
215
  signing_key:
237
216
  specification_version: 3
238
217
  summary: Collection of ActiveModel/ActiveRecord validations
239
218
  test_files:
240
- - spec/activevalidators_spec.rb
241
- - spec/spec_helper.rb
242
- - spec/validations/credit_card_spec.rb
243
- - spec/validations/email_spec.rb
244
- - spec/validations/ip_spec.rb
245
- - spec/validations/password_spec.rb
246
- - spec/validations/phone_spec.rb
247
- - spec/validations/postal_code_spec.rb
248
- - spec/validations/respond_to_spec.rb
249
- - spec/validations/slug_spec.rb
250
- - spec/validations/tracking_number_spec.rb
251
- - spec/validations/twitter_spec.rb
252
- - spec/validations/url_spec.rb
219
+ - test/test_helper.rb
220
+ - test/validations/credit_card_test.rb
221
+ - test/validations/email_test.rb
222
+ - test/validations/ip_test.rb
223
+ - test/validations/password_test.rb
224
+ - test/validations/phone_test.rb
225
+ - test/validations/postal_code_test.rb
226
+ - test/validations/respond_to_test.rb
227
+ - test/validations/slug_test.rb
228
+ - test/validations/tracking_number_test.rb
229
+ - test/validations/twitter_test.rb
230
+ - test/validations/url_test.rb
@@ -1,2 +0,0 @@
1
- ---
2
- BUNDLE_DISABLE_SHARED_GEMS: "1"
@@ -1 +0,0 @@
1
- Autotest.add_discovery { "rspec2" }
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "A class with active validators included" do
4
- subject { TestRecord }
5
-
6
- validators = ['Email','Url','RespondTo','Phone','Slug','Ip','CreditCard','Date','Password','Twitter'].map(&:underscore)
7
- validators.each do |validator|
8
- describe ".validates_#{validator}" do
9
- it "is defined" do
10
- subject.should respond_to("validates_#{validator}")
11
- end
12
-
13
- context "when it doesn't receive a hash with options" do
14
- it "calls validates #{validator} => true" do
15
- subject.should_receive('validates').with hash_including(validator => true)
16
- subject.send("validates_#{validator}")
17
- end
18
-
19
- it "calls 'validates *attributes, #{validator} => true' when fed with attributes" do
20
- subject.should_receive('validates').with(:attr1, :attr2, validator => true)
21
- subject.send("validates_#{validator}", :attr1, :attr2)
22
- end
23
- end
24
-
25
- context "when it receives a hash with options" do
26
- it "calls validates #{validator} => options" do
27
- subject.should_receive('validates').with hash_including(validator => {:options => :blah})
28
- subject.send("validates_#{validator}", :options => :blah)
29
- end
30
-
31
- it "calls 'validates *attributes, #{validator} => options' when fed with attributes" do
32
- subject.should_receive('validates').with(:attr1, :attr2, validator => {:options => :blah})
33
- subject.send("validates_#{validator}", :attr1, :attr2, :options => :blah)
34
- end
35
- end
36
-
37
- end
38
- end
39
- end
@@ -1,15 +0,0 @@
1
- require 'activevalidators'
2
-
3
- %w(models).each do |directory|
4
- Dir["#{File.dirname(__FILE__)}/#{directory}/*.rb"].each {|f| require f}
5
- end
6
-
7
- RSpec.configure do |config|
8
- end
9
-
10
- class TestRecord
11
- include ActiveModel::Validations
12
- attr_accessor :ip, :url, :slug, :responder, :global_condition,
13
- :local_condition, :phone, :email, :card, :password, :twitter_username,
14
- :postal_code, :tracking_number
15
- end
@@ -1,44 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
2
-
3
- describe "Email Validation" do
4
- before(:each) do
5
- TestRecord.reset_callbacks(:validate)
6
- TestRecord.validates :email, :email => true
7
- end
8
-
9
- subject { TestRecord.new }
10
-
11
- it "accepts valid emails" do
12
- subject.email = 'franck@verrot.fr'
13
- subject.should be_valid
14
- subject.should have(0).errors
15
- end
16
-
17
- it "accepts complete emails" do
18
- subject.email = 'Mikel Lindsaar (My email address) <mikel@test.lindsaar.net>'
19
- subject.should be_valid
20
- subject.should have(0).errors
21
- end
22
-
23
- describe "for invalid emails" do
24
- before :each do
25
- subject.email = 'franck.fr'
26
- end
27
-
28
- it "rejects invalid emails" do
29
- subject.should_not be_valid
30
- subject.should have(1).error
31
- end
32
-
33
- it 'rejects local emails' do
34
- subject.email = 'franck'
35
- subject.should_not be_valid
36
- subject.should have(1).error
37
- end
38
-
39
- it "generates an error message of type invalid" do
40
- subject.should_not be_valid
41
- subject.errors[:email].should include subject.errors.generate_message(:email, :invalid)
42
- end
43
- end
44
- end
@@ -1,73 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
2
-
3
- describe "IP Validation" do
4
- before(:each) do
5
- TestRecord.reset_callbacks(:validate)
6
- end
7
-
8
- subject { TestRecord.new }
9
-
10
- describe "IPv4 Validation" do
11
- before :each do
12
- TestRecord.validates :ip, :ip => { :format => :v4 }
13
- end
14
-
15
- it "accepts valid IPs" do
16
- subject.ip = '192.168.1.1'
17
- subject.should be_valid
18
- subject.should have(0).errors
19
- end
20
-
21
- context "for invalid IPs" do
22
- before :each do
23
- subject.ip = '267.34.56.3'
24
- end
25
-
26
- it "rejects invalid IPs" do
27
- subject.should_not be_valid
28
- subject.should have(1).error
29
- end
30
-
31
- it "generates an error message of type invalid" do
32
- subject.should_not be_valid
33
- subject.errors[:ip].should include subject.errors.generate_message(:ip, :invalid)
34
- end
35
- end
36
- end
37
-
38
- describe "IPv6 Validation" do
39
- before :each do
40
- TestRecord.validates :ip, :ip => { :format => :v6 }
41
- end
42
-
43
- it "accepts valid IPs" do
44
- subject.ip = '::1'
45
- subject.should be_valid
46
- subject.should have(0).errors
47
- end
48
-
49
- context "for invalid IPs" do
50
- before :each do
51
- subject.ip = '192.168.1.1'
52
- end
53
-
54
- it "rejects invalid IPs" do
55
- subject.should_not be_valid
56
- subject.should have(1).error
57
- end
58
-
59
- it "generates an error message of type invalid" do
60
- subject.should_not be_valid
61
- subject.errors[:ip].should include subject.errors.generate_message(:ip, :invalid)
62
- end
63
- end
64
- end
65
-
66
- it "checks validity of the arguments" do
67
- [3, "foo", 1..6].each do |wrong_argument|
68
- expect {
69
- TestRecord.validates :ip, :ip => { :format => wrong_argument }
70
- }.to raise_error(ArgumentError, "Unknown IP validator format #{wrong_argument.inspect}")
71
- end
72
- end
73
- end
@@ -1,44 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
2
-
3
- describe "Password Validation" do
4
- STRENGTHS = {
5
- :weak => { :valid => 'sixchr', :invalid => 'foo' },
6
- :medium => { :valid => 'chrs123', :invalid => 'sixchr' },
7
- :strong => { :valid => 'HQSij2323#$%', :invalid => 'chrs123' }
8
- }
9
-
10
- subject { TestRecord.new }
11
-
12
- STRENGTHS.each_pair do |strength, passwords|
13
- describe "#{strength} mode" do
14
- before(:each) do
15
- TestRecord.reset_callbacks(:validate)
16
- TestRecord.validates :password, :password => { :strength => strength }
17
- end
18
-
19
- describe "valid passwords" do
20
- it "accepts a #{strength} password like #{passwords[:valid]}" do
21
- subject.password = passwords[:valid]
22
- subject.should be_valid
23
- subject.should have(0).errors
24
- end
25
- end
26
-
27
- describe "invalid passwords" do
28
- before :each do
29
- subject.password = passwords[:invalid]
30
- end
31
-
32
- it "rejects invalid passwords like #{passwords[:invalid]}" do
33
- subject.should_not be_valid
34
- subject.should have(1).error
35
- end
36
-
37
- it "generates an error message of type invalid" do
38
- subject.should_not be_valid
39
- subject.errors[:password].should include subject.errors.generate_message(:password, :invalid)
40
- end
41
- end
42
- end
43
- end
44
- end