Commit 2453449e authored by Lin Jen-Shin's avatar Lin Jen-Shin

Don't include EmailHelpers manually, pick with rspec

`:mailer` is needed to pick it easily, while
`type: :mailer` is needed for picking it automatically for
tests located in spec/mailers/*_spec.rb

It's a bit complicated in spec/services/notification_service_spec.rb
but we'll leave it alone for now.
parent aef62b69
require 'spec_helper' require 'spec_helper'
describe Ci::Pipeline do describe Ci::Pipeline, :mailer do
include EmailHelpers
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project) } let(:project) { create(:project) }
...@@ -1252,8 +1250,6 @@ describe Ci::Pipeline do ...@@ -1252,8 +1250,6 @@ describe Ci::Pipeline do
pipeline.user.global_notification_setting pipeline.user.global_notification_setting
.update(level: 'custom', failed_pipeline: true, success_pipeline: true) .update(level: 'custom', failed_pipeline: true, success_pipeline: true)
reset_delivered_emails!
perform_enqueued_jobs do perform_enqueued_jobs do
pipeline.enqueue pipeline.enqueue
pipeline.run pipeline.run
......
require 'spec_helper' require 'spec_helper'
describe DeployKey do describe DeployKey, :mailer do
include EmailHelpers
describe "Associations" do describe "Associations" do
it { is_expected.to have_many(:deploy_keys_projects) } it { is_expected.to have_many(:deploy_keys_projects) }
it { is_expected.to have_many(:projects) } it { is_expected.to have_many(:projects) }
......
...@@ -114,9 +114,7 @@ describe GpgKey do ...@@ -114,9 +114,7 @@ describe GpgKey do
end end
end end
describe 'notification' do describe 'notification', :mailer do
include EmailHelpers
let(:user) { create(:user) } let(:user) { create(:user) }
it 'sends a notification' do it 'sends a notification' do
......
require 'spec_helper' require 'spec_helper'
describe Key do describe Key, :mailer do
include EmailHelpers
describe "Associations" do describe "Associations" do
it { is_expected.to belong_to(:user) } it { is_expected.to belong_to(:user) }
end end
......
require 'spec_helper' require 'spec_helper'
describe PipelinesEmailService do describe PipelinesEmailService, :mailer do
include EmailHelpers
let(:pipeline) do let(:pipeline) do
create(:ci_pipeline, project: project, sha: project.commit('master').sha) create(:ci_pipeline, project: project, sha: project.commit('master').sha)
end end
...@@ -14,10 +12,6 @@ describe PipelinesEmailService do ...@@ -14,10 +12,6 @@ describe PipelinesEmailService do
Gitlab::DataBuilder::Pipeline.build(pipeline) Gitlab::DataBuilder::Pipeline.build(pipeline)
end end
before do
reset_delivered_emails!
end
describe 'Validations' do describe 'Validations' do
context 'when service is active' do context 'when service is active' do
before do before do
......
require 'spec_helper' require 'spec_helper'
describe API::Issues do # rubocop:disable RSpec/FilePath describe API::Issues, :mailer do # rubocop:disable RSpec/FilePath
include EmailHelpers
set(:user) { create(:user) } set(:user) { create(:user) }
set(:project) do set(:project) do
create(:project, :public, creator_id: user.id, namespace: user.namespace) create(:project, :public, creator_id: user.id, namespace: user.namespace)
......
require 'spec_helper' require 'spec_helper'
describe API::Issues do describe API::Issues, :mailer do
include EmailHelpers
set(:user) { create(:user) } set(:user) { create(:user) }
set(:project) do set(:project) do
create(:project, :public, creator_id: user.id, namespace: user.namespace) create(:project, :public, creator_id: user.id, namespace: user.namespace)
......
require 'spec_helper' require 'spec_helper'
describe API::V3::Issues do describe API::V3::Issues, :mailer do
include EmailHelpers
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
let(:non_member) { create(:user) } let(:non_member) { create(:user) }
......
# coding: utf-8 # coding: utf-8
require 'spec_helper' require 'spec_helper'
describe Issues::UpdateService do describe Issues::UpdateService, :mailer do
include EmailHelpers
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
let(:user3) { create(:user) } let(:user3) { create(:user) }
......
require 'spec_helper' require 'spec_helper'
describe MergeRequests::UpdateService do describe MergeRequests::UpdateService, :mailer do
include EmailHelpers
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
......
require 'spec_helper' require 'spec_helper'
describe NotificationService do describe NotificationService, :mailer do
include EmailHelpers
let(:notification) { described_class.new } let(:notification) { described_class.new }
let(:assignee) { create(:user) } let(:assignee) { create(:user) }
...@@ -14,7 +12,6 @@ describe NotificationService do ...@@ -14,7 +12,6 @@ describe NotificationService do
shared_examples 'notifications for new mentions' do shared_examples 'notifications for new mentions' do
def send_notifications(*new_mentions) def send_notifications(*new_mentions)
reset_delivered_emails!
notification.send(notification_method, mentionable, new_mentions, @u_disabled) notification.send(notification_method, mentionable, new_mentions, @u_disabled)
end end
...@@ -137,12 +134,11 @@ describe NotificationService do ...@@ -137,12 +134,11 @@ describe NotificationService do
describe '#new_note' do describe '#new_note' do
it do it do
add_users_with_subscription(note.project, issue) add_users_with_subscription(note.project, issue)
reset_delivered_emails!
# Ensure create SentNotification by noteable = issue 6 times, not noteable = note # Ensure create SentNotification by noteable = issue 6 times, not noteable = note
expect(SentNotification).to receive(:record).with(issue, any_args).exactly(8).times expect(SentNotification).to receive(:record).with(issue, any_args).exactly(8).times
reset_delivered_emails!
notification.new_note(note) notification.new_note(note)
should_email(@u_watcher) should_email(@u_watcher)
...@@ -165,9 +161,10 @@ describe NotificationService do ...@@ -165,9 +161,10 @@ describe NotificationService do
it "emails the note author if they've opted into notifications about their activity" do it "emails the note author if they've opted into notifications about their activity" do
add_users_with_subscription(note.project, issue) add_users_with_subscription(note.project, issue)
note.author.notified_of_own_activity = true
reset_delivered_emails! reset_delivered_emails!
note.author.notified_of_own_activity = true
notification.new_note(note) notification.new_note(note)
should_email(note.author) should_email(note.author)
......
...@@ -49,7 +49,7 @@ RSpec.configure do |config| ...@@ -49,7 +49,7 @@ RSpec.configure do |config|
config.include SearchHelpers, type: :feature config.include SearchHelpers, type: :feature
config.include WaitForRequests, :js config.include WaitForRequests, :js
config.include StubConfiguration config.include StubConfiguration
config.include EmailHelpers, type: :mailer config.include EmailHelpers, :mailer, type: :mailer
config.include TestEnv config.include TestEnv
config.include ActiveJob::TestHelper config.include ActiveJob::TestHelper
config.include ActiveSupport::Testing::TimeHelpers config.include ActiveSupport::Testing::TimeHelpers
...@@ -99,6 +99,10 @@ RSpec.configure do |config| ...@@ -99,6 +99,10 @@ RSpec.configure do |config|
RequestStore.clear! RequestStore.clear!
end end
config.before(:example, :mailer) do
reset_delivered_emails!
end
if ENV['CI'] if ENV['CI']
config.around(:each) do |ex| config.around(:each) do |ex|
ex.run_with_retry retry: 2 ex.run_with_retry retry: 2
......
...@@ -7,7 +7,6 @@ shared_context 'gitlab email notification' do ...@@ -7,7 +7,6 @@ shared_context 'gitlab email notification' do
let(:new_user_address) { 'newguy@example.com' } let(:new_user_address) { 'newguy@example.com' }
before do before do
reset_delivered_emails!
email = recipient.emails.create(email: "notifications@example.com") email = recipient.emails.create(email: "notifications@example.com")
recipient.update_attribute(:notification_email, email.email) recipient.update_attribute(:notification_email, email.email)
stub_incoming_email_setting(enabled: true, address: "reply+%{key}@#{Gitlab.config.gitlab.host}") stub_incoming_email_setting(enabled: true, address: "reply+%{key}@#{Gitlab.config.gitlab.host}")
......
...@@ -7,8 +7,6 @@ RSpec.shared_examples 'updating mentions' do |service_class| ...@@ -7,8 +7,6 @@ RSpec.shared_examples 'updating mentions' do |service_class|
end end
def update_mentionable(opts) def update_mentionable(opts)
reset_delivered_emails!
perform_enqueued_jobs do perform_enqueued_jobs do
service_class.new(project, user, opts).execute(mentionable) service_class.new(project, user, opts).execute(mentionable)
end end
......
require 'spec_helper' require 'spec_helper'
describe EmailsOnPushWorker do describe EmailsOnPushWorker, :mailer do
include RepoHelpers include RepoHelpers
include EmailHelpers
include EmailSpec::Matchers include EmailSpec::Matchers
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
...@@ -90,7 +89,6 @@ describe EmailsOnPushWorker do ...@@ -90,7 +89,6 @@ describe EmailsOnPushWorker do
context "when there is an SMTP error" do context "when there is an SMTP error" do
before do before do
reset_delivered_emails!
allow(Notify).to receive(:repository_push_email).and_raise(Net::SMTPFatalError) allow(Notify).to receive(:repository_push_email).and_raise(Net::SMTPFatalError)
allow(subject).to receive_message_chain(:logger, :info) allow(subject).to receive_message_chain(:logger, :info)
perform perform
...@@ -114,8 +112,6 @@ describe EmailsOnPushWorker do ...@@ -114,8 +112,6 @@ describe EmailsOnPushWorker do
allow_any_instance_of(Mail::TestMailer).to receive(:deliver!).and_wrap_original do |original, mail| allow_any_instance_of(Mail::TestMailer).to receive(:deliver!).and_wrap_original do |original, mail|
original.call(Mail.new(mail.encoded)) original.call(Mail.new(mail.encoded))
end end
reset_delivered_emails!
end end
it "sends the mail to each of the recipients" do it "sends the mail to each of the recipients" do
......
require 'spec_helper' require 'spec_helper'
describe PipelineNotificationWorker do describe PipelineNotificationWorker, :mailer do
include EmailHelpers
let(:pipeline) { create(:ci_pipeline) } let(:pipeline) { create(:ci_pipeline) }
describe '#execute' do describe '#execute' do
......
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