Permalink
Browse files

Checking if unconfirmed_email has changed before to set update_needs_…

…confirmation flash message.

Conflicts:

	test/integration/registerable_test.rb

Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
  • Loading branch information...
1 parent 1da8490 commit 73f617db7b4c9c533210e56404242ee85395ebc8 Víctor Manuel Cruz Dueñas committed with josevalim Jul 5, 2012
Showing with 32 additions and 5 deletions.
  1. +10 −4 app/controllers/devise/registrations_controller.rb
  2. +22 −1 test/integration/registerable_test.rb
View
14 app/controllers/devise/registrations_controller.rb
@@ -38,13 +38,13 @@ def edit
# the current user in place.
def update
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
+ prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
if resource.update_with_password(resource_params)
if is_navigational_format?
- if resource.respond_to?(:pending_reconfirmation?) && resource.pending_reconfirmation?
- flash_key = :update_needs_confirmation
- end
- set_flash_message :notice, flash_key || :updated
+ flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
+ :update_needs_confirmation : :updated
+ set_flash_message :notice, flash_key
end
sign_in resource_name, resource, :bypass => true
respond_with resource, :location => after_update_path_for(resource)
@@ -74,6 +74,12 @@ def cancel
protected
+ def update_needs_confirmation?(resource, previous)
+ resource.respond_to?(:pending_reconfirmation?) &&
+ resource.pending_reconfirmation? &&
+ previous != resource.unconfirmed_email
+ end
+
# Build a devise resource passing in the session. Useful to move
# temporary session data to the newly created user.
def build_resource(hash=nil)
View
23 test/integration/registerable_test.rb
@@ -321,4 +321,25 @@ class ReconfirmableRegistrationTest < ActionController::IntegrationTest
assert Admin.first.valid_password?('pas123')
end
-end
+
+ test 'a signed in admin should not see a reconfirmation message if he did not change his email, despite having an unconfirmed email' do
+ sign_in_as_admin
+
+ get edit_admin_registration_path
+ fill_in 'email', :with => 'admin.new@example.com'
+ fill_in 'current password', :with => '123456'
+ click_button 'Update'
+
+ get edit_admin_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 '/admin_area/home'
+ assert_contain 'You updated your account successfully.'
+
+ assert_equal "admin.new@example.com", Admin.first.unconfirmed_email
+ assert Admin.first.valid_password?('pas123')
+ end
+end

0 comments on commit 73f617d

Please sign in to comment.