Skip to content

Commit

Permalink
Reverts PR 1835 (#1865)
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinthinks authored Sep 21, 2020
1 parent 2ecdbd0 commit bb06058
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/controllers/distributions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def insufficient_error_message(details)
end

def send_notification(org, dist, subject: 'Your Distribution')
PartnerMailerJob.perform_async(org, dist, subject) if Flipper.enabled?(:email_active)
PartnerMailerJob.perform_now(org, dist, subject) if Flipper.enabled?(:email_active)
end

def schedule_reminder_email(distribution)
Expand Down
4 changes: 1 addition & 3 deletions app/jobs/partner_mailer_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# This job notifies a Partner that they have a pending distribution
class PartnerMailerJob
include Sidekiq::Worker

class PartnerMailerJob < ApplicationJob
def perform(org_id, dist_id, subject)
current_organization = Organization.find(org_id)
distribution = Distribution.find(dist_id)
Expand Down
2 changes: 1 addition & 1 deletion app/services/distribution_create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ def call
private

def send_notification
PartnerMailerJob.perform_async(distribution_organization.id, distribution.id, 'Your Distribution') if Flipper.enabled?(:email_active)
PartnerMailerJob.perform_now(distribution_organization.id, distribution.id, 'Your Distribution') if Flipper.enabled?(:email_active)
end
end
4 changes: 2 additions & 2 deletions spec/jobs/partner_mailer_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

it "does not send mail for past distributions" do
expect do
PartnerMailerJob.new.perform(organization.id, past_distribution.id, mailer_subject)
PartnerMailerJob.perform_now(organization.id, past_distribution.id, mailer_subject)
end.not_to change { ActionMailer::Base.deliveries.count }
end

it "sends mail for future distributions immediately" do
expect do
PartnerMailerJob.new.perform(organization.id, future_distribution.id, mailer_subject)
PartnerMailerJob.perform_now(organization.id, future_distribution.id, mailer_subject)
end.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end
Expand Down
21 changes: 9 additions & 12 deletions spec/requests/distributions_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@
expect(partner).to be_valid
expect(Flipper).to receive(:enabled?).with(:email_active).and_return(true)

post distributions_path(params)
expect do
post distributions_path(params)

expect(response).to have_http_status(:redirect)
last_distribution = Distribution.last
expect(response).to redirect_to(distribution_path(last_distribution))
expect(PartnerMailerJob).to have_enqueued_sidekiq_job(last_distribution.organization.id, last_distribution.id, /Your Distribution/)
expect(response).to have_http_status(:redirect)
last_distribution = Distribution.last
expect(response).to redirect_to(distribution_path(last_distribution))
end.to change { ActionMailer::Base.deliveries.count }.by(1)
end

it "renders #new again on failure, with notice" do
Expand Down Expand Up @@ -231,18 +232,14 @@
before { allow(Flipper).to receive(:enabled?).with(:email_active).and_return(true) }

it "does not send an e-mail" do
Sidekiq::Testing.inline! do
subject
expect(PartnerMailerJob).not_to have_enqueued_sidekiq_job(distribution.organization.id, distribution.id, "Your Distribution")
end
expect { subject }.not_to change { ActionMailer::Base.deliveries.count }
end

context "sending" do
let(:issued_at) { distribution.issued_at + 1.day }

it "does send the email" do
subject
expect(PartnerMailerJob).to have_enqueued_sidekiq_job(distribution.organization.id, distribution.id, /Your Distribution Date Has Changed/)
it "does send an e-mail" do
expect { subject }.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end

Expand Down
7 changes: 3 additions & 4 deletions spec/services/distribution_create_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
@partner.update!(send_reminders: true)
allow(Flipper).to receive(:enabled?).with(:email_active).and_return(true)

result = subject.new(distribution_params).call

expect(PartnerMailerJob).to have_enqueued_sidekiq_job(@organization.id, result.distribution.id, "Your Distribution")
expect(PartnerMailerJob).to receive(:perform_now).once
subject.new(distribution_params).call
end
end

Expand All @@ -33,7 +32,7 @@
@partner.update!(send_reminders: false)
allow(Flipper).to receive(:enabled?).with(:email_active).and_return(true)

expect(PartnerMailerJob).not_to receive(:perform_async)
expect(PartnerMailerJob).not_to receive(:perform_now)
subject.new(distribution_params).call
end
end
Expand Down
5 changes: 3 additions & 2 deletions spec/system/distribution_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
choose "Pick up"

fill_in "Comment", with: "Take my wipes... please"
expect(PartnerMailerJob).to receive(:perform_async)

click_button "Save", match: :first
expect do
click_button "Save", match: :first
end.to change { ActionMailer::Base.deliveries.count }.by(1)

expect(page).to have_content "Distributions"
expect(page.find(".alert-info")).to have_content "reated"
Expand Down

0 comments on commit bb06058

Please sign in to comment.