Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Replace email regex with EmailValidator gem

* Use Rails 3 `validates` method.
* Use Ruby 1.9 hash syntax.
  • Loading branch information...
commit 5d5d5c09596c4ee353a8bd2b5177f20fb1d7ea42 1 parent 68d77d1
@croaky croaky authored
View
5 Gemfile.lock
@@ -3,6 +3,7 @@ PATH
specs:
clearance (1.0.0.rc4)
bcrypt-ruby
+ email_validator
rails (>= 3.0)
GEM
@@ -69,6 +70,8 @@ GEM
nokogiri (>= 1.5.0)
database_cleaner (0.8.0)
diff-lcs (1.1.3)
+ email_validator (1.3.0)
+ activemodel
erubis (2.7.0)
factory_girl (3.5.0)
activesupport (>= 3.0.0)
@@ -155,7 +158,7 @@ GEM
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
- tzinfo (0.3.34)
+ tzinfo (0.3.35)
xpath (0.1.4)
nokogiri (~> 1.3)
View
1  clearance.gemspec
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
s.required_ruby_version = Gem::Requirement.new('>= 1.9.2')
s.add_dependency 'bcrypt-ruby'
+ s.add_dependency 'email_validator'
s.add_dependency 'rails', '>= 3.0'
s.add_development_dependency 'appraisal', '0.4.1'
s.add_development_dependency 'aruba', '0.4.11'
View
3  gemfiles/3.0.20.gemfile.lock
@@ -3,6 +3,7 @@ PATH
specs:
clearance (1.0.0.rc4)
bcrypt-ruby
+ email_validator
rails (>= 3.0)
GEM
@@ -68,6 +69,8 @@ GEM
nokogiri (>= 1.5.0)
database_cleaner (0.8.0)
diff-lcs (1.1.3)
+ email_validator (1.3.0)
+ activemodel
erubis (2.6.6)
abstract (>= 1.0.0)
factory_girl (3.5.0)
View
3  gemfiles/3.1.11.gemfile.lock
@@ -3,6 +3,7 @@ PATH
specs:
clearance (1.0.0.rc4)
bcrypt-ruby
+ email_validator
rails (>= 3.0)
GEM
@@ -69,6 +70,8 @@ GEM
nokogiri (>= 1.5.0)
database_cleaner (0.8.0)
diff-lcs (1.1.3)
+ email_validator (1.3.0)
+ activemodel
erubis (2.7.0)
factory_girl (3.5.0)
activesupport (>= 3.0.0)
View
3  gemfiles/3.2.12.gemfile.lock
@@ -3,6 +3,7 @@ PATH
specs:
clearance (1.0.0.rc4)
bcrypt-ruby
+ email_validator
rails (>= 3.0)
GEM
@@ -68,6 +69,8 @@ GEM
nokogiri (>= 1.5.0)
database_cleaner (0.8.0)
diff-lcs (1.1.3)
+ email_validator (1.3.0)
+ activemodel
erubis (2.7.0)
factory_girl (3.5.0)
activesupport (>= 3.0.0)
View
11 lib/clearance/user.rb
@@ -1,4 +1,5 @@
require 'digest/sha1'
+require 'email_validator'
module Clearance
module User
@@ -36,11 +37,13 @@ module Validations
extend ActiveSupport::Concern
included do
- validates_presence_of :email, :unless => :email_optional?
- validates_uniqueness_of :email, :allow_blank => true
- validates_format_of :email, :with => %r{\A[a-z0-9!#\$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#\$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\Z}i, :allow_blank => true
+ validates :email,
+ email: true,
+ presence: true,
+ uniqueness: { allow_blank: true },
+ unless: :email_optional?
- validates_presence_of :password, :unless => :password_optional?
+ validates :password, presence: true, unless: :password_optional?
end
end
View
12 spec/models/password_strategies_spec.rb
@@ -2,10 +2,16 @@
describe Clearance::User do
subject do
+ class UniquenessValidator < ActiveModel::Validator
+ def validate(record)
+ end
+ end
+
Class.new do
- def self.validates_presence_of(*args); end
- def self.validates_uniqueness_of(*args); end
- def self.validates_format_of(*args); end
+ include ActiveModel::Validations
+
+ validates_with UniquenessValidator
+
def self.before_validation(*args); end
def self.before_create(*args); end

0 comments on commit 5d5d5c0

Please sign in to comment.
Something went wrong with that request. Please try again.