activevalidators 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +15 -6
- data/Rakefile +1 -1
- data/activevalidators.gemspec +1 -1
- data/lib/active_model/validations/slug_validator.rb +11 -0
- data/lib/{active_validators.rb → activevalidators.rb} +1 -0
- data/spec/models/slug_validator_model.rb +7 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/specs/slug_spec.rb +28 -0
- metadata +9 -4
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -6,23 +6,32 @@ Collection of ActiveModel/ActiveRecord validations
|
|
6
6
|
Installation (Rails 3)
|
7
7
|
----------------------
|
8
8
|
|
9
|
-
In your Gemfile:
|
9
|
+
In your Gemfile ( >>= 1.1.0 ):
|
10
10
|
|
11
|
-
gem 'activevalidators'
|
11
|
+
gem 'activevalidators'
|
12
|
+
|
13
|
+
**N.B: if you use version <= 1.0.2, use this instead:**
|
12
14
|
|
15
|
+
gem 'activevalidators', :require => 'active_validators'
|
13
16
|
|
14
17
|
In your models, the gem provides new validators like `email`, or `url`:
|
15
18
|
|
16
19
|
class User
|
17
20
|
validates :email_address, :email => true
|
18
21
|
validates :link_url, :url => true
|
22
|
+
validates :user_phone, :phone => true
|
23
|
+
end
|
24
|
+
|
25
|
+
class Article
|
26
|
+
validates :slug, :slug => true
|
19
27
|
end
|
20
28
|
|
21
|
-
Exhaustive list of supported validators:
|
29
|
+
Exhaustive list of supported validators and their implementation:
|
22
30
|
|
23
|
-
* `email` :
|
24
|
-
* `url` :
|
25
|
-
* `phone` :
|
31
|
+
* `email` : based on the `mail` gem
|
32
|
+
* `url` : based on a regular expression
|
33
|
+
* `phone` : based on a regular expression
|
34
|
+
* `slug` : based on `ActiveSupport::String#parameterize`
|
26
35
|
|
27
36
|
Todo
|
28
37
|
----
|
data/Rakefile
CHANGED
data/activevalidators.gemspec
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
|
2
|
+
|
3
|
+
describe "Slug Validation" do
|
4
|
+
it "accepts valid slugs" do
|
5
|
+
model = Models::SlugValidatorModel.new
|
6
|
+
model.slug = '1234567890-foo-bar-bar'
|
7
|
+
model.valid?.should be(true)
|
8
|
+
model.should have(0).errors
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "for invalid slugs" do
|
12
|
+
let(:model) do
|
13
|
+
Models::SlugValidatorModel.new.tap do |m|
|
14
|
+
m.slug = '@#$%^'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "rejects invalid slugs" do
|
19
|
+
model.valid?.should be(false)
|
20
|
+
model.should have(1).errors
|
21
|
+
end
|
22
|
+
|
23
|
+
it "generates an error message of type invalid" do
|
24
|
+
model.valid?.should be(false)
|
25
|
+
model.errors[:slug].should == [model.errors.generate_message(:slug, :invalid)]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 1.0.2
|
9
|
+
version: 1.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Franck Verrot
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-12-01 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -134,16 +134,19 @@ files:
|
|
134
134
|
- lib/active_model/validations/email_validator.rb
|
135
135
|
- lib/active_model/validations/phone_validator.rb
|
136
136
|
- lib/active_model/validations/respond_to_validator.rb
|
137
|
+
- lib/active_model/validations/slug_validator.rb
|
137
138
|
- lib/active_model/validations/url_validator.rb
|
138
|
-
- lib/
|
139
|
+
- lib/activevalidators.rb
|
139
140
|
- spec/models/email_validator_model.rb
|
140
141
|
- spec/models/phone_validator_model.rb
|
141
142
|
- spec/models/respond_to_validator_model.rb
|
143
|
+
- spec/models/slug_validator_model.rb
|
142
144
|
- spec/models/url_validator_model.rb
|
143
145
|
- spec/spec_helper.rb
|
144
146
|
- spec/specs/email_spec.rb
|
145
147
|
- spec/specs/phone_spec.rb
|
146
148
|
- spec/specs/respond_to_spec.rb
|
149
|
+
- spec/specs/slug_spec.rb
|
147
150
|
- spec/specs/url_spec.rb
|
148
151
|
has_rdoc: true
|
149
152
|
homepage: http://github.com/cesario/activevalidators
|
@@ -181,9 +184,11 @@ test_files:
|
|
181
184
|
- spec/models/email_validator_model.rb
|
182
185
|
- spec/models/phone_validator_model.rb
|
183
186
|
- spec/models/respond_to_validator_model.rb
|
187
|
+
- spec/models/slug_validator_model.rb
|
184
188
|
- spec/models/url_validator_model.rb
|
185
189
|
- spec/spec_helper.rb
|
186
190
|
- spec/specs/email_spec.rb
|
187
191
|
- spec/specs/phone_spec.rb
|
188
192
|
- spec/specs/respond_to_spec.rb
|
193
|
+
- spec/specs/slug_spec.rb
|
189
194
|
- spec/specs/url_spec.rb
|