Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Nankai Pan committed Sep 13, 2020
1 parent ba4eed8 commit 721d0de
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/controllers/distributions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def insufficient_error_message(details)
end

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

def schedule_reminder_email(distribution)
Expand Down
21 changes: 12 additions & 9 deletions spec/requests/distributions_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@
expect(partner).to be_valid
expect(Flipper).to receive(:enabled?).with(:email_active).and_return(true)

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

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)
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/)
end

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

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion spec/services/distribution_create_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@partner.update!(send_reminders: false)
allow(Flipper).to receive(:enabled?).with(:email_active).and_return(true)

expect(PartnerMailerJob).not_to receive(:perform_now)
expect(PartnerMailerJob).not_to receive(:perform_async)
subject.new(distribution_params).call
end
end
Expand Down
5 changes: 2 additions & 3 deletions spec/system/distribution_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
select @storage_location.name, from: "From storage location"

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

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

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

0 comments on commit 721d0de

Please sign in to comment.