Skip to content

Commit

Permalink
Merge pull request #342 from DefactoSoftware/jurre/fix-account-update…
Browse files Browse the repository at this point in the history
…-flashes

fix account update flashes
  • Loading branch information
fatboypunk committed Jul 21, 2015
2 parents 24c46a4 + 5eaf581 commit 189505c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
17 changes: 16 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ def edit

def update
@user = current_user
if @user.respond_to?(:unconfirmed_email)
prev_unconfirmed_email = @user.unconfirmed_email
end

if @user.update_with_password(user_params)
redirect_to edit_user_path, notice: t(:user_updated)
flash_key = if update_needs_confirmation?(@user, prev_unconfirmed_email)
:update_needs_confirmation
else
:updated
end
redirect_to edit_user_path, notice: t(".#{flash_key}")
else
render :edit
end
Expand All @@ -36,4 +45,10 @@ def user_params
:password_confirmation,
:current_password)
end

def update_needs_confirmation?(resource, previous)
resource.respond_to?(:pending_reconfirmation?) &&
resource.pending_reconfirmation? &&
previous != resource.unconfirmed_email
end
end
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ en:
invite: Invite User
invitation_sent_at: Invited %{time_ago} ago
confirm: Confirm
update:
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
updated: You updated your account successfully.

entry_filters:
title: Filters
clients: All Clients
Expand Down
3 changes: 3 additions & 0 deletions config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ nl:
email: Email
invitation_sent_at: "%{time_ago} geleden uitgenodigd"
invite: Nodig uit
update:
update_needs_confirmation: U heeft uw account aangepast, maar we moeten uw email valideren. Controlleer uw email en klik op de bevestigingslink om uw nieuw email te valideren.
updated: Uw account is aangepast.
views:
pagination:
truncate: ...
Expand Down
12 changes: 11 additions & 1 deletion spec/features/user_edits_account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@
fill_in "user_current_password", with: user.password
click_button "Update"

expect(page).to have_content I18n.t(:user_updated)
expect(page).to have_content I18n.t("users.update.updated")
end

scenario "changing the email address" do
fill_in "user_email", with: "[email protected]"
fill_in "user_current_password", with: user.password
click_button "Update"

expect(page).to have_content(
I18n.t("users.update.update_needs_confirmation")
)
end

scenario "with invalid data" do
Expand Down

0 comments on commit 189505c

Please sign in to comment.