Reputation: 4880
I've added the following tests to spec/requests/user_pages_spec.rb:
require 'spec_helper'
describe "UserPages" do
subject { page }
.
.
.
describe "user should be able to update username" do
before do
@user = FactoryGirl.create(:user)
visit new_user_session_path
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign In"
end
specify { @user.username.should_not == "New Name" }
context "after filling in correct details" do
before do
visit edit_user_registration_path
fill_in "Name", with: "New Name"
fill_in "Current password", with: @user.password
click_button "Update"
end
specify { @user.reload.username.should == "New Name" }
it { should have_selector('div.alert.alert-notice', text: "You updated your account successfully." ) }
it { should have_selector('title', text: "Edit account details" ) }
end
end
end
The first specify returns username "Person", but so does the second one after the reload:
1) UserPages user should be able to update username after filling in correct details
Failure/Error: specify { @user.reload.username.should == "New Name" }
expected: "New Name"
got: "Person" (using ==)
# ./spec/requests/user_pages_spec.rb:83:in `block (4 levels) in <top (required)>'
If I change any line the test fails, and I've checked the app manually and updating works. I've also tried calling just @user.reload
before getting the name again.
What could be the problem? Should I be putting this code somewhere else?
Thanks for your time.
Upvotes: 2
Views: 4063
Reputation: 4245
You should use @user
instance in this lines:
fill_in "Email", with: user.email
fill_in "Password", with: user.password
So, it should be:
fill_in "Email", with: @user.email
fill_in "Password", with: @user.password
Upvotes: 3