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 CHANGED
@@ -1 +1,2 @@
1
1
  *.swp
2
+ *.gem
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activevalidators (1.0.2)
4
+ activevalidators (1.1.0)
5
5
  activemodel (>= 3.0.0)
6
6
  activerecord (>= 3.0.0)
7
7
  mail
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', :require => 'active_validators'
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` : checks the email based on the `mail` gem
24
- * `url` : checks the url based on a regular expression
25
- * `phone` : checks the phone number based on a regular expression
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
@@ -3,7 +3,7 @@ $:.unshift File.expand_path("../lib", __FILE__)
3
3
 
4
4
  require 'rubygems'
5
5
  require 'rubygems/specification'
6
- require 'active_validators'
6
+ require 'activevalidators'
7
7
 
8
8
  def gemspec
9
9
  @gemspec ||= begin
@@ -4,7 +4,7 @@ $:.unshift lib unless $:.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "activevalidators"
7
- s.version = '1.0.2'
7
+ s.version = '1.1.0'
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Franck Verrot"]
10
10
  s.email = ["franck@verrot.fr"]
@@ -0,0 +1,11 @@
1
+ module ActiveModel
2
+ module Validations
3
+ class SlugValidator < EachValidator
4
+ def validate_each(record, attribute, value)
5
+ unless value == value.parameterize
6
+ record.errors.add(attribute)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -11,5 +11,6 @@ module ActiveModel
11
11
  autoload :UrlValidator
12
12
  autoload :RespondToValidator
13
13
  autoload :PhoneValidator
14
+ autoload :SlugValidator
14
15
  end
15
16
  end
@@ -0,0 +1,7 @@
1
+ module Models
2
+ class SlugValidatorModel
3
+ include ActiveModel::Validations
4
+ attr_accessor :slug
5
+ validates :slug, :slug => true
6
+ end
7
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'active_validators'
1
+ require 'activevalidators'
2
2
 
3
3
  %w(models).each do |directory|
4
4
  Dir["#{File.dirname(__FILE__)}/#{directory}/*.rb"].each {|f| require f}
@@ -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
- - 2
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-11-28 00:00:00 +01:00
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/active_validators.rb
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