summaryrefslogtreecommitdiff
path: root/spec/services
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-10 12:08:16 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-10 12:08:16 +0000
commit1fa79760ad2d4bd67f5c5a27f372a7533b9b7c69 (patch)
treeffdfbd9113743831ff4f1290959a62cf6567fde5 /spec/services
parent82fa8a3d1e8466ef36b58604d20fcc145ea12118 (diff)
downloadgitlab-ce-1fa79760ad2d4bd67f5c5a27f372a7533b9b7c69.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/notification_recipients/build_service_spec.rb (renamed from spec/services/notification_recipient_service_spec.rb)2
-rw-r--r--spec/services/notification_recipients/builder/default_spec.rb44
-rw-r--r--spec/services/notification_service_spec.rb2
-rw-r--r--spec/services/snippets/create_service_spec.rb10
4 files changed, 50 insertions, 8 deletions
diff --git a/spec/services/notification_recipient_service_spec.rb b/spec/services/notification_recipients/build_service_spec.rb
index 9c2283f555b..2e848c2f04d 100644
--- a/spec/services/notification_recipient_service_spec.rb
+++ b/spec/services/notification_recipients/build_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe NotificationRecipientService do
+describe NotificationRecipients::BuildService do
let(:service) { described_class }
let(:assignee) { create(:user) }
let(:project) { create(:project, :public) }
diff --git a/spec/services/notification_recipients/builder/default_spec.rb b/spec/services/notification_recipients/builder/default_spec.rb
new file mode 100644
index 00000000000..307ca40248e
--- /dev/null
+++ b/spec/services/notification_recipients/builder/default_spec.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe NotificationRecipients::Builder::Default do
+ describe '#build!' do
+ let_it_be(:group) { create(:group, :public) }
+ let_it_be(:project) { create(:project, :public, group: group).tap { |p| p.add_developer(project_watcher) } }
+ let_it_be(:issue) { create(:issue, project: project) }
+
+ let_it_be(:current_user) { create(:user) }
+ let_it_be(:other_user) { create(:user) }
+ let_it_be(:participant) { create(:user) }
+ let_it_be(:group_watcher) { create(:user) }
+ let_it_be(:project_watcher) { create(:user) }
+
+ let_it_be(:notification_setting_project_w) { create(:notification_setting, source: project, user: project_watcher, level: 2) }
+ let_it_be(:notification_setting_group_w) { create(:notification_setting, source: group, user: group_watcher, level: 2) }
+
+ subject { described_class.new(issue, current_user, action: :new).tap { |s| s.build! } }
+
+ context 'participants and project watchers' do
+ before do
+ expect(issue).to receive(:participants).and_return([participant, current_user])
+ end
+
+ it 'adds all participants and watchers' do
+ expect(subject.recipients.map(&:user)).to include(participant, project_watcher, group_watcher)
+ expect(subject.recipients.map(&:user)).not_to include(other_user)
+ end
+ end
+
+ context 'subscribers' do
+ it 'adds all subscribers' do
+ subscriber = create(:user)
+ non_subscriber = create(:user)
+ create(:subscription, project: project, user: subscriber, subscribable: issue, subscribed: true)
+ create(:subscription, project: project, user: non_subscriber, subscribable: issue, subscribed: false)
+
+ expect(subject.recipients.map(&:user)).to include(subscriber)
+ end
+ end
+ end
+end
diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb
index d2680606738..96906b4ca3c 100644
--- a/spec/services/notification_service_spec.rb
+++ b/spec/services/notification_service_spec.rb
@@ -710,7 +710,7 @@ describe NotificationService, :mailer do
user_3 = create(:user)
recipient_1 = NotificationRecipient.new(user_1, :custom, custom_action: :new_release)
recipient_2 = NotificationRecipient.new(user_2, :custom, custom_action: :new_release)
- allow(NotificationRecipientService).to receive(:build_new_release_recipients).and_return([recipient_1, recipient_2])
+ allow(NotificationRecipients::BuildService).to receive(:build_new_release_recipients).and_return([recipient_1, recipient_2])
release
diff --git a/spec/services/snippets/create_service_spec.rb b/spec/services/snippets/create_service_spec.rb
index 5c853f8b7d7..ffad3c8b8e5 100644
--- a/spec/services/snippets/create_service_spec.rb
+++ b/spec/services/snippets/create_service_spec.rb
@@ -185,12 +185,10 @@ describe Snippets::CreateService do
expect { subject }.not_to change { Snippet.count }
end
- it 'does not create the repository' do
- expect(snippet.repository_exists?).to be_falsey
- end
-
- it 'destroys the existing repository' do
- expect(Repositories::DestroyService).to receive(:new).and_call_original
+ it 'destroys the created repository' do
+ expect_next_instance_of(Repository) do |instance|
+ expect(instance).to receive(:remove).and_call_original
+ end
subject
end