diff --git a/app/controllers/devise/passwords_controller.rb b/app/controllers/devise/passwords_controller.rb index 6460f9e7..ca60daa1 100644 --- a/app/controllers/devise/passwords_controller.rb +++ b/app/controllers/devise/passwords_controller.rb @@ -13,10 +13,12 @@ class Devise::PasswordsController < ApplicationController self.resource = resource_class.send_reset_password_instructions(params[resource_name]) if resource.errors.empty? - set_flash_message :notice, :send_instructions - redirect_to new_session_path(resource_name) + set_flash_message(:notice, :send_instructions) if is_navigational_format? + respond_with resource, :location => new_session_path(resource_name) else - render_with_scope :new + respond_with(resource) do |format| + format.any(*navigational_formats) { render_with_scope :new } + end end end @@ -32,10 +34,13 @@ class Devise::PasswordsController < ApplicationController self.resource = resource_class.reset_password_by_token(params[resource_name]) if resource.errors.empty? - set_flash_message :notice, :updated - sign_in_and_redirect(resource_name, resource) + set_flash_message(:notice, :updated) if is_navigational_format? + sign_in(resource_name, resource) + respond_with resource, :location => redirect_location(resource_name, resource) else - render_with_scope :edit + respond_with(resource) do |format| + format.any(*navigational_formats) { render_with_scope :edit } + end end end end diff --git a/test/integration/recoverable_test.rb b/test/integration/recoverable_test.rb index 8de6c02f..27a3da3f 100644 --- a/test/integration/recoverable_test.rb +++ b/test/integration/recoverable_test.rb @@ -157,4 +157,41 @@ class PasswordTest < ActionController::IntegrationTest assert !warden.authenticated?(:user) end + test 'reset password request with valid E-Mail in XML format should return valid response' do + create_user + post user_password_path(:format => 'xml'), :user => {:email => "user@test.com"} + assert_response :success + assert response.body.include? %(\n) + end + + test 'reset password request with invalid E-Mail in XML format should return valid response' do + create_user + post user_password_path(:format => 'xml'), :user => {:email => "invalid.test@test.com"} + assert_response :unprocessable_entity + assert response.body.include? %(\n) + end + + test 'change password with valid parameters in XML format should return valid response' do + user = create_user + request_forgot_password + put user_password_path(:format => 'xml'), :user => {:reset_password_token => user.reload.reset_password_token, :password => '987654321', :password_confirmation => '987654321'} + assert_response :success + assert warden.authenticated?(:user) + end + + test 'change password with invalid token in XML format should return invalid response' do + user = create_user + request_forgot_password + put user_password_path(:format => 'xml'), :user => {:reset_password_token => 'invalid.token', :password => '987654321', :password_confirmation => '987654321'} + assert_response :unprocessable_entity + assert response.body.include? %(\n) + end + + test 'change password with invalid new password in XML format should return invalid response' do + user = create_user + request_forgot_password + put user_password_path(:format => 'xml'), :user => {:reset_password_token => user.reload.reset_password_token, :password => '', :password_confirmation => '987654321'} + assert_response :unprocessable_entity + assert response.body.include? %(\n) + end end