I'm working on the exercises for chapter 6 of Hartl's Rails 4 Tutorial. The first exercise tests to make sure that user email addresses are down-cased correctly:
require 'spec_helper'
describe User do
.
.
.
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
expect(@user.reload.email).to eq mixed_case_email.downcase
end
end
.
.
.
end
What I don't understand is why the 'reload' method is necessary here. Once @user.email
is set to the contents of mixed_case_email
and saved, aren't @user.reload.email
and @user.email
the same thing? I took the reload method out just to try it and it didn't seem to change anything with the test.
What am I missing here?