debian-mirror-gitlab/spec/support/shared_examples/services/updating_mentions_shared_examples.rb

113 lines
3.6 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
RSpec.shared_examples 'updating mentions' do |service_class|
2019-12-21 20:55:43 +05:30
let(:service_class) { service_class }
let(:mentioned_user) { create(:user) }
let(:group_member1) { create(:user) }
let(:group_member2) { create(:user) }
let(:external_group) { create(:group, :private) }
2016-09-13 17:45:13 +05:30
2017-09-10 17:25:29 +05:30
before do
2018-03-17 18:26:18 +05:30
project.add_developer(mentioned_user)
2019-12-21 20:55:43 +05:30
group.add_developer(group_member1)
group.add_developer(group_member2)
2017-09-10 17:25:29 +05:30
end
2016-09-13 17:45:13 +05:30
def update_mentionable(opts)
perform_enqueued_jobs do
service_class.new(project, user, opts).execute(mentionable)
end
mentionable.reload
end
2019-12-21 20:55:43 +05:30
context 'when mentioning a different user' do
context 'in title' do
before do
update_mentionable(title: "For #{mentioned_user.to_reference}")
end
2019-12-26 22:10:19 +05:30
it 'emails only the newly-mentioned user', :sidekiq_might_not_need_inline do
2019-12-21 20:55:43 +05:30
should_only_email(mentioned_user)
end
end
context 'in description' do
before do
update_mentionable(description: "For #{mentioned_user.to_reference}")
end
2019-12-26 22:10:19 +05:30
it 'emails only the newly-mentioned user', :sidekiq_might_not_need_inline do
2019-12-21 20:55:43 +05:30
should_only_email(mentioned_user)
end
end
end
context 'when mentioning a user and a group with access to' do
shared_examples 'updating attribute with allowed mentions' do |attribute|
before do
update_mentionable(
{ attribute => "For #{group.to_reference}, cc: #{mentioned_user.to_reference}" }
)
end
2019-12-26 22:10:19 +05:30
it 'emails group members', :sidekiq_might_not_need_inline do
2019-12-21 20:55:43 +05:30
should_email(mentioned_user)
should_email(group_member1)
should_email(group_member2)
end
end
2019-12-26 22:10:19 +05:30
shared_examples 'updating attribute with existing group mention' do |attribute|
before do
mentionable.update!({ attribute => "FYI: #{group.to_reference}" })
end
it 'creates todos for only newly mentioned users' do
expect do
update_mentionable(
{ attribute => "For #{group.to_reference}, cc: #{mentioned_user.to_reference}" }
)
end.to change { Todo.count }.by(1)
end
end
2019-12-21 20:55:43 +05:30
context 'when group is public' do
it_behaves_like 'updating attribute with allowed mentions', :title
it_behaves_like 'updating attribute with allowed mentions', :description
2019-12-26 22:10:19 +05:30
it_behaves_like 'updating attribute with existing group mention', :title
it_behaves_like 'updating attribute with existing group mention', :description
2017-09-10 17:25:29 +05:30
end
2016-09-13 17:45:13 +05:30
2019-12-21 20:55:43 +05:30
context 'when the group is private' do
before do
group.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
end
it_behaves_like 'updating attribute with allowed mentions', :title
it_behaves_like 'updating attribute with allowed mentions', :description
2019-12-26 22:10:19 +05:30
it_behaves_like 'updating attribute with existing group mention', :title
it_behaves_like 'updating attribute with existing group mention', :description
2016-09-13 17:45:13 +05:30
end
end
2019-12-21 20:55:43 +05:30
context 'when mentioning a user and a group without access to' do
shared_examples 'updating attribute with not allowed mentions' do |attribute|
before do
update_mentionable(
{ attribute => "For #{external_group.to_reference}, cc: #{mentioned_user.to_reference}" }
)
end
2019-12-26 22:10:19 +05:30
it 'emails mentioned user', :sidekiq_might_not_need_inline do
2019-12-21 20:55:43 +05:30
should_only_email(mentioned_user)
end
2017-09-10 17:25:29 +05:30
end
2016-09-13 17:45:13 +05:30
2019-12-21 20:55:43 +05:30
context 'when the group is private' do
it_behaves_like 'updating attribute with not allowed mentions', :title
it_behaves_like 'updating attribute with not allowed mentions', :description
2016-09-13 17:45:13 +05:30
end
end
end