Permalink
Browse files

Chapter 6 exercises.

  • Loading branch information...
1 parent a76aef1 commit f5031f2961af8162b0722f827873f99844566b6c @benedictfritz committed May 18, 2012
View
4 sample_app/app/models/user.rb
@@ -13,8 +13,8 @@ class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation
has_secure_password
- before_save { |user| user.email = email.downcase }
-
+ before_save { self.email.downcase! }
+
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true,
View
BIN sample_app/spec/models/.user_spec.rb.swp
Binary file not shown.
View
10 sample_app/spec/models/user_spec.rb
@@ -69,6 +69,16 @@
it { should_not be_valid }
end
+ describe "email address with mixed case" do
+ let(:mixed_case_email) { "Foo@ExAMPle.CoM" }
+
+ it "should be saved as all lower-case" do
+ @user.email = mixed_case_email
+ @user.save
+ @user.reload.email.should == mixed_case_email.downcase
+ end
+ end
+
describe "when password is not present" do
before { @user.password = @user.password_confirmation = " " }
it { should_not be_valid }

0 comments on commit f5031f2

Please sign in to comment.