Commit d3ecf7cb authored by Ash McKenzie's avatar Ash McKenzie

Merge branch '340308-fix-gitlab-seeder-quiet-leaking' into 'master'

Fix Gitlab::Seeder.quiet changes leaking

See merge request gitlab-org/gitlab!69764
parents fde60a07 5f83fb7c
# frozen_string_literal: true # frozen_string_literal: true
# :nocov:
module DeliverNever
def deliver_later
self
end
end
module MuteNotifications
def new_note(note)
end
end
module Gitlab module Gitlab
class Seeder class Seeder
extend ActionView::Helpers::NumberHelper extend ActionView::Helpers::NumberHelper
...@@ -82,18 +70,22 @@ module Gitlab ...@@ -82,18 +70,22 @@ module Gitlab
Project.include(ProjectSeed) Project.include(ProjectSeed)
User.include(UserSeed) User.include(UserSeed)
mute_notifications old_perform_deliveries = ActionMailer::Base.perform_deliveries
mute_mailer ActionMailer::Base.perform_deliveries = false
SeedFu.quiet = true SeedFu.quiet = true
without_statement_timeout do without_statement_timeout do
yield without_new_note_notifications do
yield
end
end end
puts "\nOK".color(:green)
ensure
SeedFu.quiet = false SeedFu.quiet = false
ActionMailer::Base.perform_deliveries = old_perform_deliveries
ActiveRecord::Base.logger = old_logger ActiveRecord::Base.logger = old_logger
puts "\nOK".color(:green)
end end
def self.without_gitaly_timeout def self.without_gitaly_timeout
...@@ -109,12 +101,14 @@ module Gitlab ...@@ -109,12 +101,14 @@ module Gitlab
ApplicationSetting.expire ApplicationSetting.expire
end end
def self.mute_notifications def self.without_new_note_notifications
NotificationService.prepend(MuteNotifications) NotificationService.alias_method :original_new_note, :new_note
end NotificationService.define_method(:new_note) { |note| }
def self.mute_mailer yield
ActionMailer::MessageDelivery.prepend(DeliverNever) ensure
NotificationService.alias_method :new_note, :original_new_note
NotificationService.remove_method :original_new_note
end end
def self.without_statement_timeout def self.without_statement_timeout
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Seeder do
describe '.quiet' do
it 'disables mail deliveries' do
expect(ActionMailer::Base.perform_deliveries).to eq(true)
described_class.quiet do
expect(ActionMailer::Base.perform_deliveries).to eq(false)
end
expect(ActionMailer::Base.perform_deliveries).to eq(true)
end
it 'disables new note notifications' do
note = create(:note_on_issue)
notification_service = NotificationService.new
expect(notification_service).to receive(:send_new_note_notifications).twice
notification_service.new_note(note)
described_class.quiet do
expect(notification_service.new_note(note)).to eq(nil)
end
notification_service.new_note(note)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment