diff --git a/app/controllers/users/passwords_controller.rb b/app/controllers/users/passwords_controller.rb index a77e5e1f3..0fa8c1fa5 100644 --- a/app/controllers/users/passwords_controller.rb +++ b/app/controllers/users/passwords_controller.rb @@ -14,6 +14,6 @@ class Users::PasswordsController < Devise::PasswordsController protected def after_sending_reset_password_instructions_path_for(_resource) - confirmations_reset_path(email: params.dig("user", "email")) if is_navigational_format? + confirmations_reset_path(email: params.dig("user", "email")) end end diff --git a/config/environments/test.rb b/config/environments/test.rb index 22de4a7bf..a9b68bb26 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -43,6 +43,7 @@ Rails.application.configure do # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + config.action_mailer.default_options = { from: "test@gmail.com" } # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 6364434e8..e948ebd4c 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -114,9 +114,6 @@ RSpec.configure do |config| # spec Capybara.server = :puma, { Silent: true } - # For Devise > 4.1.1 config.include Devise::Test::ControllerHelpers, type: :controller config.include Devise::Test::IntegrationHelpers, type: :request - # Use the following instead if you are on Devise <= 4.1.1 - # config.include Devise::TestHelpers, :type => :controller end diff --git a/spec/requests/users/passwords_controller_spec.rb b/spec/requests/users/passwords_controller_spec.rb new file mode 100644 index 000000000..b0a3f5783 --- /dev/null +++ b/spec/requests/users/passwords_controller_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" +require_relative "../../support/devise" + +RSpec.describe Users::PasswordsController, type: :request do + let(:params) { { user: { email: email } } } + + context "when a password reset is requested for a valid email" do + let(:user) { FactoryBot.create(:user) } + let(:email) { user.email } + + it "redirects to the email sent page anyway" do + post "/users/password", params: params + expect(response).to have_http_status(:redirect) + follow_redirect! + expect(response.body).to match(/Check your email/) + end + end + + context "when a password reset is requested with an email that doesn't exist in the system" do + before do + allow_any_instance_of(Users::PasswordsController).to receive(:is_navigational_format?).and_return(false) + end + + let(:email) { "madeup_email@test.com" } + + it "redirects to the email sent page anyway" do + post "/users/password", params: params + expect(response).to have_http_status(:redirect) + follow_redirect! + expect(response.body).to match(/Check your email/) + end + end +end