-
Notifications
You must be signed in to change notification settings - Fork 1
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 #1742 from tactilenews/1741_add_missing_specs_twil…
…io_webhooks_refactor_to_dry_deactivate_logic
- Loading branch information
Showing
12 changed files
with
201 additions
and
76 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
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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
class MarkInactiveContributorInactiveJob < ApplicationJob | ||
queue_as :mark_inactive_contributor_inactive | ||
|
||
def perform(contributor_id:) | ||
contributor = Contributor.where(id: contributor_id).first | ||
return unless contributor | ||
|
||
contributor.deactivated_at = Time.current | ||
contributor.save(validate: false) | ||
ContributorMarkedInactive.with(contributor_id: contributor.id).deliver_later(User.all) | ||
User.admin.find_each do |admin| | ||
PostmarkAdapter::Outbound.contributor_marked_as_inactive!(admin, contributor) | ||
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe MarkInactiveContributorInactiveJob do | ||
describe '#perform_later(contributor_id:)' do | ||
subject { -> { described_class.new.perform(contributor_id: contributor.id) } } | ||
|
||
let!(:admin) { create_list(:user, 2, admin: true) } | ||
let!(:non_admin_user) { create(:user) } | ||
|
||
context 'given an unknown contributor' do | ||
let(:contributor) { Contributor.new(id: 12_345) } | ||
|
||
# if a contributor is deleted from the db before the job is run, | ||
# then we should not try to run the job, but exit early. | ||
it { is_expected.not_to raise_error(NoMethodError) } | ||
end | ||
|
||
context 'given a known contributor' do | ||
let(:contributor) { create(:contributor) } | ||
|
||
it { is_expected.to change { contributor.reload.deactivated_at }.from(nil).to(kind_of(ActiveSupport::TimeWithZone)) } | ||
it_behaves_like 'an ActivityNotification', 'ContributorMarkedInactive' | ||
it 'enqueues a job to inform admin' do | ||
expect { subject.call }.to have_enqueued_job.on_queue('default').with( | ||
'PostmarkAdapter::Outbound', | ||
'contributor_marked_as_inactive_email', | ||
'deliver_now', # How ActionMailer works in test environment, even though in production we call deliver_later | ||
{ | ||
params: { admin: an_instance_of(User), contributor: contributor }, | ||
args: [] | ||
} | ||
).exactly(2).times | ||
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