You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.6 KiB
47 lines
1.6 KiB
3 years ago
|
require "rails_helper"
|
||
|
require_relative "../../support/devise"
|
||
|
|
||
3 years ago
|
RSpec.describe Auth::PasswordsController, type: :request do
|
||
3 years ago
|
let(:params) { { user: { email: email } } }
|
||
3 years ago
|
|
||
3 years ago
|
context "when a password reset is requested for a valid email" do
|
||
|
let(:user) { FactoryBot.create(:user) }
|
||
|
let(:email) { user.email }
|
||
3 years ago
|
|
||
3 years ago
|
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/)
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
3 years ago
|
context "when a password reset is requested with an email that doesn't exist in the system" do
|
||
|
before do
|
||
3 years ago
|
allow_any_instance_of(Auth::PasswordsController).to receive(:is_navigational_format?).and_return(false)
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
3 years ago
|
let(:email) { "madeup_email@test.com" }
|
||
3 years ago
|
|
||
3 years ago
|
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/)
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
|
|
||
|
context "when a password reset is requested the email" do
|
||
3 years ago
|
let(:user) { FactoryBot.create(:user, last_sign_in_at: Time.zone.now) }
|
||
3 years ago
|
let(:email) { user.email }
|
||
|
|
||
|
it "should contain the correct email" do
|
||
3 years ago
|
post "/users/password", params: params
|
||
|
follow_redirect!
|
||
3 years ago
|
email_ascii_content = ActionMailer::Base.deliveries.last.body.raw_source
|
||
|
email_content = email_ascii_content.encode("ASCII", "UTF-8", undef: :replace)
|
||
|
expect(email_content).to match(email)
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|