deliver needs to be called on the return value of the mailer call

This commit is contained in:
Jonne Haß 2014-12-28 22:34:43 +01:00
parent f62ba0f73c
commit 3a90386303
7 changed files with 18 additions and 17 deletions

View file

@ -7,7 +7,7 @@ class ExportMailer < ActionMailer::Base
mail(to: @user.email, subject: I18n.t('notifier.export_email.subject', name: @user.name)) do |format|
format.html { render 'users/export_email' }
format.text { render 'users/export_email' }
end.deliver
end
end
def export_failure_for(user)
@ -16,7 +16,7 @@ class ExportMailer < ActionMailer::Base
mail(to: @user.email, subject: I18n.t('notifier.export_failure_email.subject', name: @user.name)) do |format|
format.html { render 'users/export_failure_email' }
format.text { render 'users/export_failure_email' }
end.deliver
end
end
end

View file

@ -7,13 +7,14 @@ class ReportMailer < ActionMailer::Base
:type => I18n.t('notifier.report_email.type.' + type),
:id => id
}
Role.admins.each do |role|
person = Person.find(role.person_id)
if person.local?
user = User.find_by_id(person.owner_id)
unless user.user_preferences.exists?(:email_type => :someone_reported)
resource[:email] = user.email
format(resource).deliver_now
format(resource)
end
end
end

View file

@ -12,9 +12,9 @@ module Workers
@user.perform_export!
if @user.reload.export.present?
ExportMailer.export_complete_for(@user)
ExportMailer.export_complete_for(@user).deliver_now
else
ExportMailer.export_failure_for(@user)
ExportMailer.export_failure_for(@user).deliver_now
end
end
end

View file

@ -4,7 +4,7 @@ module Workers
sidekiq_options queue: :mail
def perform(type, id)
ReportMailer.new_report(type, id)
ReportMailer.new_report(type, id).deliver_now
end
end
end

View file

@ -7,30 +7,30 @@ require 'spec_helper'
describe ExportMailer, :type => :mailer do
describe '#export_complete_for' do
it "should deliver successfully" do
expect { ExportMailer.export_complete_for(alice) }.to_not raise_error
expect { ExportMailer.export_complete_for(alice).deliver_now }.to_not raise_error
end
it "should be added to the delivery queue" do
expect { ExportMailer.export_complete_for(alice) }.to change(ActionMailer::Base.deliveries, :size).by(1)
expect { ExportMailer.export_complete_for(alice).deliver_now }.to change(ActionMailer::Base.deliveries, :size).by(1)
end
it "should include correct recipient" do
ExportMailer.export_complete_for(alice)
ExportMailer.export_complete_for(alice).deliver_now
expect(ActionMailer::Base.deliveries[0].to[0]).to include(alice.email)
end
end
describe '#export_failure_for' do
it "should deliver successfully" do
expect { ExportMailer.export_failure_for(alice) }.to_not raise_error
expect { ExportMailer.export_failure_for(alice).deliver_now }.to_not raise_error
end
it "should be added to the delivery queue" do
expect { ExportMailer.export_failure_for(alice) }.to change(ActionMailer::Base.deliveries, :size).by(1)
expect { ExportMailer.export_failure_for(alice).deliver_now }.to change(ActionMailer::Base.deliveries, :size).by(1)
end
it "should include correct recipient" do
ExportMailer.export_failure_for(alice)
ExportMailer.export_failure_for(alice).deliver_now
expect(ActionMailer::Base.deliveries[0].to[0]).to include(alice.email)
end
end

View file

@ -14,18 +14,18 @@ describe Report, :type => :mailer do
it "should deliver successfully" do
expect {
ReportMailer.new_report('post', 666)
ReportMailer.new_report('post', 666).deliver_now
}.to_not raise_error
end
it "should be added to the delivery queue" do
expect {
ReportMailer.new_report('post', 666)
ReportMailer.new_report('post', 666).deliver_now
}.to change(ActionMailer::Base.deliveries, :size).by(1)
end
it "should include correct recipient" do
ReportMailer.new_report('post', 666)
ReportMailer.new_report('post', 666).deliver_now
expect(ActionMailer::Base.deliveries[0].to[0]).to include(@user.email)
end
end

View file

@ -13,14 +13,14 @@ describe Workers::ExportUser do
it 'sends a success message when the export is successful' do
alice.stub(:export).and_return(OpenStruct.new)
expect(ExportMailer).to receive(:export_complete_for).with(alice)
expect(ExportMailer).to receive(:export_complete_for).with(alice).and_call_original
Workers::ExportUser.new.perform(alice.id)
end
it 'sends a failure message when the export fails' do
alice.stub(:export).and_return(nil)
expect(alice).to receive(:perform_export!).and_return(false)
expect(ExportMailer).to receive(:export_failure_for).with(alice)
expect(ExportMailer).to receive(:export_failure_for).with(alice).and_call_original
Workers::ExportUser.new.perform(alice.id)
end
end