From ef2c8593b9f80951e97fadb5a3c9c5cdf0f1b1c9 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 11 Apr 2013 23:54:20 +0300 Subject: [PATCH] Disable mailer for spinach --- app/services/notification_service.rb | 22 +++++++++++++--------- spec/support/test_env.rb | 6 +++++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index 4b3c982c189..379d2c54629 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -13,7 +13,7 @@ class NotificationService # even if user disabled notifications def new_key(key) if key.user - Notify.delay.new_ssh_key_email(key.id) + mailer.new_ssh_key_email(key.id) end end @@ -84,14 +84,14 @@ class NotificationService recipients = recipients.concat(project_watchers(merge_request.project)).uniq recipients.each do |recipient| - Notify.delay.merged_merge_request_email(recipient.id, merge_request.id) + mailer.merged_merge_request_email(recipient.id, merge_request.id) end end # Notify new user with email after creation def new_user(user) # Dont email omniauth created users - Notify.delay.new_user_email(user.id, user.password) unless user.extern_uid? + mailer.new_user_email(user.id, user.password) unless user.extern_uid? end # Notify users on new note in system @@ -131,16 +131,16 @@ class NotificationService notify_method = "note_#{note.noteable_type.underscore}_email".to_sym recipients.each do |recipient| - Notify.delay.send(notify_method, recipient.id, note.id) + mailer.send(notify_method, recipient.id, note.id) end end def new_team_member(users_project) - Notify.delay.project_access_granted_email(users_project.id) + mailer.project_access_granted_email(users_project.id) end def update_team_member(users_project) - Notify.delay.project_access_granted_email(users_project.id) + mailer.project_access_granted_email(users_project.id) end protected @@ -186,7 +186,7 @@ class NotificationService recipients.delete(target.author) recipients.each do |recipient| - Notify.delay.send(method, recipient.id, target.id) + mailer.send(method, recipient.id, target.id) end end @@ -196,7 +196,7 @@ class NotificationService recipients.delete(current_user) recipients.each do |recipient| - Notify.delay.send(method, recipient.id, target.id, current_user.id) + mailer.send(method, recipient.id, target.id, current_user.id) end end @@ -213,7 +213,11 @@ class NotificationService recipients.delete(current_user) recipients.each do |recipient| - Notify.delay.send(method, recipient.id, target.id, target.assignee_id_was) + mailer.send(method, recipient.id, target.id, target.assignee_id_was) end end + + def mailer + Notify.delay + end end diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index 175698ac9c9..8a2e004f824 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -1,3 +1,5 @@ +require 'rspec/mocks' + module TestEnv extend self @@ -13,6 +15,8 @@ module TestEnv # - remove_key # def init(opts = {}) + RSpec::Mocks::setup(self) + # Disable observers to improve test speed # # You can enable it in whole test case where needed by next string: @@ -82,6 +86,6 @@ module TestEnv end def disable_mailer - ActionMailer::Base.perform_deliveries = false + NotificationService.any_instance.stub(mailer: double.as_null_object) end end