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
# :nocov:
module DeliverNever
def deliver_later
self
end
end
module MuteNotifications
def new_note(note)
end
end
module Gitlab
class Seeder
extend ActionView::Helpers::NumberHelper
......@@ -82,18 +70,22 @@ module Gitlab
Project.include(ProjectSeed)
User.include(UserSeed)
mute_notifications
mute_mailer
old_perform_deliveries = ActionMailer::Base.perform_deliveries
ActionMailer::Base.perform_deliveries = false
SeedFu.quiet = true
without_statement_timeout do
yield
without_new_note_notifications do
yield
end
end
puts "\nOK".color(:green)
ensure
SeedFu.quiet = false
ActionMailer::Base.perform_deliveries = old_perform_deliveries
ActiveRecord::Base.logger = old_logger
puts "\nOK".color(:green)
end
def self.without_gitaly_timeout
......@@ -109,12 +101,14 @@ module Gitlab
ApplicationSetting.expire
end
def self.mute_notifications
NotificationService.prepend(MuteNotifications)
end
def self.without_new_note_notifications
NotificationService.alias_method :original_new_note, :new_note
NotificationService.define_method(:new_note) { |note| }
def self.mute_mailer
ActionMailer::MessageDelivery.prepend(DeliverNever)
yield
ensure
NotificationService.alias_method :new_note, :original_new_note
NotificationService.remove_method :original_new_note
end
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