Browse Source

Password reset routing

pull/81/head
baarkerlounger 3 years ago
parent
commit
b1cf1ea71f
  1. 2
      app/controllers/users/passwords_controller.rb
  2. 1
      config/environments/test.rb
  3. 3
      spec/rails_helper.rb
  4. 33
      spec/requests/users/passwords_controller_spec.rb

2
app/controllers/users/passwords_controller.rb

@ -14,6 +14,6 @@ class Users::PasswordsController < Devise::PasswordsController
protected protected
def after_sending_reset_password_instructions_path_for(_resource) 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
end end

1
config/environments/test.rb

@ -43,6 +43,7 @@ Rails.application.configure do
# The :test delivery method accumulates sent emails in the # The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array. # ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test config.action_mailer.delivery_method = :test
config.action_mailer.default_options = { from: "test@gmail.com" }
# Print deprecation notices to the stderr. # Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr config.active_support.deprecation = :stderr

3
spec/rails_helper.rb

@ -114,9 +114,6 @@ RSpec.configure do |config|
# spec # spec
Capybara.server = :puma, { Silent: true } Capybara.server = :puma, { Silent: true }
# For Devise > 4.1.1
config.include Devise::Test::ControllerHelpers, type: :controller config.include Devise::Test::ControllerHelpers, type: :controller
config.include Devise::Test::IntegrationHelpers, type: :request 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 end

33
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
Loading…
Cancel
Save