diff --git a/app/mailers/export_mailer.rb b/app/mailers/export_mailer.rb index 6d36b4d8f..24e34d0f6 100644 --- a/app/mailers/export_mailer.rb +++ b/app/mailers/export_mailer.rb @@ -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 diff --git a/app/mailers/report_mailer.rb b/app/mailers/report_mailer.rb index 5256add0e..b3479cc74 100644 --- a/app/mailers/report_mailer.rb +++ b/app/mailers/report_mailer.rb @@ -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 diff --git a/app/workers/export_user.rb b/app/workers/export_user.rb index f01535ce9..b67cc76ed 100644 --- a/app/workers/export_user.rb +++ b/app/workers/export_user.rb @@ -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 diff --git a/app/workers/mail/report_worker.rb b/app/workers/mail/report_worker.rb index 92c201dcb..6d272f486 100644 --- a/app/workers/mail/report_worker.rb +++ b/app/workers/mail/report_worker.rb @@ -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 diff --git a/spec/mailers/export_spec.rb b/spec/mailers/export_spec.rb index b699c10d5..16d5ac71c 100644 --- a/spec/mailers/export_spec.rb +++ b/spec/mailers/export_spec.rb @@ -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 diff --git a/spec/mailers/report_spec.rb b/spec/mailers/report_spec.rb index 10edd0dae..b5ec54642 100644 --- a/spec/mailers/report_spec.rb +++ b/spec/mailers/report_spec.rb @@ -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 diff --git a/spec/workers/export_user_spec.rb b/spec/workers/export_user_spec.rb index f6ecfba55..0011b26ea 100644 --- a/spec/workers/export_user_spec.rb +++ b/spec/workers/export_user_spec.rb @@ -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