Permalink
Browse files

Add better message when user updates while reconfirmable is enabled.

  • Loading branch information...
1 parent 5a82026 commit 8c0f74f036e5ae0174ab1c1c8df01edcd6ba0193 @heimidal heimidal committed Aug 13, 2011
@@ -41,7 +41,8 @@ def update
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
if resource.update_with_password(params[resource_name])
- set_flash_message :notice, :updated if is_navigational_format?
+ flash_key = :update_needs_confirmation if Devise.reconfirmable && resource.unconfirmed_email?
+ set_flash_message :notice, flash_key || :updated if is_navigational_format?
sign_in resource_name, resource, :bypass => true
respond_with resource, :location => after_update_path_for(resource)
else
View
@@ -36,6 +36,7 @@ en:
signed_up: 'Welcome! You have signed up successfully.'
inactive_signed_up: 'You have signed up successfully. However, we could not sign you in because your account is %{reason}.'
updated: 'You updated your account successfully.'
+ 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 your new email address."
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
reasons:
inactive: 'inactive'
@@ -274,3 +274,45 @@ class RegistrationTest < ActionController::IntegrationTest
assert_equal User.count, 0
end
end
+
+class ReconfirmableRegistrationTest < ActionController::IntegrationTest
+ def setup
+ add_unconfirmed_email_column
+ Devise.reconfirmable = true
+ end
+
+ def teardown
+ remove_unconfirmed_email_column
+ Devise.reconfirmable = false
+ end
+
+ test 'a signed in user should see a more appropriate flash message when editing his account if reconfirmable is enabled' do
+ sign_in_as_user
+ get edit_user_registration_path
+
+ fill_in 'email', :with => 'user.new@example.com'
+ fill_in 'current password', :with => '123456'
+ click_button 'Update'
+
+ assert_current_url '/'
+ assert_contain '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 your new email address.'
+
+ assert_equal "user.new@example.com", User.first.unconfirmed_email
+ end
+
+ test 'A signed in user should not see a reconfirmation message if they did not change their password' do
+ sign_in_as_user
+ get edit_user_registration_path
+
+ fill_in 'password', :with => 'pas123'
+ fill_in 'password confirmation', :with => 'pas123'
+ fill_in 'current password', :with => '123456'
+ click_button 'Update'
+
+ assert_current_url '/'
+ assert_contain 'You updated your account successfully.'
+
+ assert User.first.valid_password?('pas123')
+ end
+end
+

0 comments on commit 8c0f74f

Please sign in to comment.