Skip to content

Commit

Permalink
Fixes issue hotsh#728 -- don't save the user until the entire profile…
Browse files Browse the repository at this point in the history
… update has succeeded
  • Loading branch information
carols10cents committed Nov 22, 2012
1 parent 9e802be commit 891777f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
1 change: 0 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ def edit_user_profile(params)
unless params[:password].nil? or params[:password].empty?
if params[:password] == params[:password_confirm]
self.password = params[:password]
self.save
else
return "Passwords must match"
end
Expand Down
29 changes: 28 additions & 1 deletion test/acceptance/edit_profile_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,33 @@
assert has_field?("password")
end

it "doesn't save the updated password if the email update doesn't save" do
@existing_user = Fabricate(:user, :email_confirmed => true)

@u.password = "old_password"
@u.save!

previous_password = @u.hashed_password

visit "/users/#{@u.username}/edit"

fill_in "password", :with => "new_password"
fill_in "password_confirm", :with => "new_password"

fill_in "email", :with => @existing_user.email

VCR.use_cassette("update_profile_multiple_saves_bug") do
click_button "Save"
end

within flash do
assert has_content?("Profile could not be saved:")
assert has_content?("Email is already taken.")
end

@u.reload.hashed_password.must_equal previous_password
end

it "verifies your email if you change it" do
visit "/users/#{@u.username}/edit"
email = "new_email@new_email.com"
Expand Down Expand Up @@ -206,4 +233,4 @@
page.current_url.wont_match(/\/users\/#{u.username}\/edit/)
end
end
end
end

0 comments on commit 891777f

Please sign in to comment.