DRY up the added update service specs, add two email helpers
This commit is contained in:
parent
b62954db4c
commit
0e9c4a902d
4 changed files with 49 additions and 62 deletions
|
@ -320,37 +320,10 @@ describe Issues::UpdateService, services: true do
|
|||
end
|
||||
end
|
||||
|
||||
context 'updated user mentions' do
|
||||
let(:user4) { create(:user) }
|
||||
before do
|
||||
project.team << [user4, :developer]
|
||||
end
|
||||
|
||||
context "in title" do
|
||||
before do
|
||||
perform_enqueued_jobs { update_issue(title: user4.to_reference) }
|
||||
end
|
||||
|
||||
it 'emails only the newly-mentioned user' do
|
||||
should_not_email(user)
|
||||
should_not_email(user2)
|
||||
should_not_email(user3)
|
||||
should_email(user4)
|
||||
end
|
||||
end
|
||||
|
||||
context 'in description' do
|
||||
before do
|
||||
perform_enqueued_jobs { update_issue(description: user4.to_reference) }
|
||||
end
|
||||
|
||||
it 'emails only the newly-mentioned user' do
|
||||
should_not_email(user)
|
||||
should_not_email(user2)
|
||||
should_not_email(user3)
|
||||
should_email(user4)
|
||||
end
|
||||
end
|
||||
context 'updating mentions' do
|
||||
let(:mentionable) { issue }
|
||||
include_examples 'updating mentions', Issues::UpdateService
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -226,37 +226,9 @@ describe MergeRequests::UpdateService, services: true do
|
|||
end
|
||||
end
|
||||
|
||||
context 'updated user mentions' do
|
||||
let(:user4) { create(:user) }
|
||||
before do
|
||||
project.team << [user4, :developer]
|
||||
end
|
||||
|
||||
context 'in title' do
|
||||
before do
|
||||
perform_enqueued_jobs { update_merge_request(title: user4.to_reference) }
|
||||
end
|
||||
|
||||
it 'emails only the newly-mentioned user' do
|
||||
should_not_email(user)
|
||||
should_not_email(user2)
|
||||
should_not_email(user3)
|
||||
should_email(user4)
|
||||
end
|
||||
end
|
||||
|
||||
context 'in description' do
|
||||
before do
|
||||
perform_enqueued_jobs { update_merge_request(description: user4.to_reference) }
|
||||
end
|
||||
|
||||
it 'emails only the newly-mentioned user' do
|
||||
should_not_email(user)
|
||||
should_not_email(user2)
|
||||
should_not_email(user3)
|
||||
should_email(user4)
|
||||
end
|
||||
end
|
||||
context 'updating mentions' do
|
||||
let(:mentionable) { merge_request }
|
||||
include_examples 'updating mentions', MergeRequests::UpdateService
|
||||
end
|
||||
|
||||
context 'when MergeRequest has tasks' do
|
||||
|
|
|
@ -3,6 +3,16 @@ module EmailHelpers
|
|||
ActionMailer::Base.deliveries.map(&:to).flatten.count(user.email) == 1
|
||||
end
|
||||
|
||||
def reset_delivered_emails!
|
||||
ActionMailer::Base.deliveries.clear
|
||||
end
|
||||
|
||||
def should_only_email(*users)
|
||||
users.each {|user| should_email(user) }
|
||||
recipients = ActionMailer::Base.deliveries.flat_map(&:to)
|
||||
expect(recipients.count).to eq(users.count)
|
||||
end
|
||||
|
||||
def should_email(user)
|
||||
expect(sent_to_user?(user)).to be_truthy
|
||||
end
|
||||
|
|
32
spec/support/updating_mentions_shared_examples.rb
Normal file
32
spec/support/updating_mentions_shared_examples.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
RSpec.shared_examples 'updating mentions' do |service_class|
|
||||
let(:mentioned_user) { create(:user) }
|
||||
let(:service_class) { service_class }
|
||||
|
||||
before { project.team << [mentioned_user, :developer] }
|
||||
|
||||
def update_mentionable(opts)
|
||||
reset_delivered_emails!
|
||||
|
||||
perform_enqueued_jobs do
|
||||
service_class.new(project, user, opts).execute(mentionable)
|
||||
end
|
||||
|
||||
mentionable.reload
|
||||
end
|
||||
|
||||
context 'in title' do
|
||||
before { update_mentionable(title: mentioned_user.to_reference) }
|
||||
|
||||
it 'emails only the newly-mentioned user' do
|
||||
should_only_email(mentioned_user)
|
||||
end
|
||||
end
|
||||
|
||||
context 'in description' do
|
||||
before { update_mentionable(description: mentioned_user.to_reference) }
|
||||
|
||||
it 'emails only the newly-mentioned user' do
|
||||
should_only_email(mentioned_user)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue