Permalink
Browse files

Valida unicidade de email

  • Loading branch information...
1 parent 2a2ff0d commit 0500cc13f11486f8c27dab03763242e2bde3eab9 @elomar committed Mar 10, 2012
Showing with 11 additions and 1 deletion.
  1. +1 −1 app/models/usuario.rb
  2. +10 −0 spec/models/usuario_spec.rb
View
@@ -4,5 +4,5 @@ class Usuario < ActiveRecord::Base
validates :nome, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
- validates :email, presence: true, format: VALID_EMAIL_REGEX
+ validates :email, presence: true, format: VALID_EMAIL_REGEX, uniqueness: { case_sensitive: false }
end
@@ -52,4 +52,14 @@
it { should_not be_valid }
end
+ describe "quando email já está em uso em maiúsculas" do
+ before do
+ usuario_mesmo_email = @usuario.dup
+ usuario_mesmo_email.email = @usuario.email.upcase
+ usuario_mesmo_email.save
+ end
+
+ it { should_not be_valid }
+ end
+
end

0 comments on commit 0500cc1

Please sign in to comment.