-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from rjurado01/refactor/action-mailer-paramete…
…rized Refactor mailer to use ActionMailer::Parameterized.
- Loading branch information
Showing
13 changed files
with
98 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ruby 2.6.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'rails_helper' | ||
|
||
describe RailsJwtAuth do | ||
before(:all) { RailsJwtAuth.model_name = "ActiveRecordUser" } | ||
|
||
describe '#send_email' do | ||
let(:unconfirmed_user) { FactoryBot.create(:active_record_unconfirmed_user) } | ||
|
||
after { RailsJwtAuth.deliver_later = false } | ||
|
||
context 'when deliver_later options is false' do | ||
before { RailsJwtAuth.deliver_later = false } | ||
|
||
it 'uses deliver method' do | ||
mock2 = OpenStruct.new(deliver: true) | ||
mock = OpenStruct.new(confirmation_instructions: mock2) | ||
|
||
expect(RailsJwtAuth::Mailer).to receive(:with).with(user_id: unconfirmed_user.id.to_s) | ||
.and_return(mock) | ||
expect(mock2).to receive(:deliver) | ||
|
||
RailsJwtAuth.send_email(:confirmation_instructions, unconfirmed_user) | ||
end | ||
end | ||
|
||
context 'when deliver_later options is false' do | ||
before { RailsJwtAuth.deliver_later = true } | ||
|
||
it 'uses deliver method' do | ||
mock2 = OpenStruct.new(deliver_later: true) | ||
mock = OpenStruct.new(confirmation_instructions: mock2) | ||
|
||
expect(RailsJwtAuth::Mailer).to receive(:with).with(user_id: unconfirmed_user.id.to_s) | ||
.and_return(mock) | ||
expect(mock2).to receive(:deliver_later) | ||
|
||
RailsJwtAuth.send_email(:confirmation_instructions, unconfirmed_user) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,45 +71,18 @@ | |
end | ||
|
||
describe '#send_confirmation_instructions' do | ||
before :all do | ||
class Mock | ||
def deliver | ||
end | ||
|
||
def deliver_later | ||
end | ||
end | ||
end | ||
|
||
it 'fills confirmation fields' do | ||
mock = Mock.new | ||
allow(RailsJwtAuth::Mailer).to receive(:confirmation_instructions).and_return(mock) | ||
unconfirmed_user.send_confirmation_instructions | ||
expect(unconfirmed_user.confirmation_token).not_to be_nil | ||
expect(unconfirmed_user.confirmation_sent_at).not_to be_nil | ||
end | ||
|
||
it 'sends confirmation email' do | ||
mock = Mock.new | ||
new_user = FactoryBot.build("#{orm.underscore}_unconfirmed_user") | ||
allow(RailsJwtAuth::Mailer).to receive(:confirmation_instructions).and_return(mock) | ||
expect(mock).to receive(:deliver) | ||
expect(RailsJwtAuth).to receive(:send_email).with(:confirmation_instructions, anything) | ||
new_user.send_confirmation_instructions | ||
end | ||
|
||
context 'when use deliver_later option' do | ||
before { RailsJwtAuth.deliver_later = true } | ||
after { RailsJwtAuth.deliver_later = false } | ||
|
||
it 'uses deliver_later method to send email' do | ||
mock = Mock.new | ||
new_user = FactoryBot.build("#{orm.underscore}_unconfirmed_user") | ||
allow(RailsJwtAuth::Mailer).to receive(:confirmation_instructions).and_return(mock) | ||
expect(mock).to receive(:deliver_later) | ||
new_user.send_confirmation_instructions | ||
end | ||
end | ||
|
||
context 'when user is confirmed' do | ||
it 'returns false' do | ||
expect(user.send_confirmation_instructions).to eq(false) | ||
|
@@ -121,9 +94,9 @@ def deliver_later | |
end | ||
|
||
it 'does not send confirmation email' do | ||
mock = Mock.new | ||
allow(RailsJwtAuth::Mailer).to receive(:confirmation_instructions).and_return(mock) | ||
expect(mock).not_to receive(:deliver) | ||
expect(RailsJwtAuth).not_to receive(:send_email) | ||
.with(:confirmation_instructions, anything) | ||
|
||
user.send_confirmation_instructions | ||
end | ||
|
||
|
@@ -174,22 +147,19 @@ def deliver_later | |
context 'when send_email_changed_notification option is false' do | ||
it 'sends only confirmation email' do | ||
allow(RailsJwtAuth).to receive(:send_email_changed_notification).and_return(false) | ||
expect(RailsJwtAuth).to receive(:send_email).with(:confirmation_instructions, user) | ||
expect(RailsJwtAuth).not_to receive(:send_email).with(:email_changed, user) | ||
user.update(email: '[email protected]') | ||
expect(ActionMailer::Base.deliveries.count).to eq(1) | ||
expect(ActionMailer::Base.deliveries.first.subject).to eq('Confirmation instructions') | ||
expect(ActionMailer::Base.deliveries.first.to).to eq(['[email protected]']) | ||
end | ||
end | ||
|
||
context 'when send_email_changed_notification option is true' do | ||
it 'sends confirmation and nofication email' do | ||
allow(RailsJwtAuth).to receive(:send_email_changed_notification).and_return(true) | ||
expect(RailsJwtAuth).to receive(:send_email).with(:email_changed, user) | ||
expect(RailsJwtAuth).to receive(:send_email).with(:confirmation_instructions, user) | ||
old_email = user.email | ||
user.update(email: '[email protected]') | ||
expect(ActionMailer::Base.deliveries.first.subject).to eq('Confirmation instructions') | ||
expect(ActionMailer::Base.deliveries.first.to).to eq(['[email protected]']) | ||
expect(ActionMailer::Base.deliveries.last.subject).to eq('Email changed') | ||
expect(ActionMailer::Base.deliveries.last.to).to eq([old_email]) | ||
end | ||
end | ||
end | ||
|
Oops, something went wrong.