Skip to content

Commit 70cf847

Browse files
committed
6.5 Exercises
1 parent ddb942d commit 70cf847

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

app/models/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class User < ActiveRecord::Base
22
attr_accessible :email, :name, :password, :password_confirmation
33
has_secure_password
44

5-
before_save { |user| user.email = email.downcase }
5+
before_save { self.email.downcase }
66

77
validates :name, presence: true, length: { maximum: 50 }
88
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

spec/models/user_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@
6262
it { should_not be_valid }
6363
end
6464

65+
describe "email address with mixed case" do
66+
let(:mixed_case_email) { "[email protected]" }
67+
68+
it "should be saved as all lower-case" do
69+
@user.email = mixed_case_email
70+
@user.save
71+
@user.reload.email == mixed_case_email.downcase
72+
end
73+
end
74+
6575
describe "when password is not present" do
6676
before { @user.password = @user.password_confirmation = " " }
6777
it { should_not be_valid }

0 commit comments

Comments
 (0)