Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-27 12:08:28 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-27 12:08:28 +0300
commit6ac4a6713ed3196af899011f7e18658e16ebaac0 (patch)
treec60237cb5203d171481b765d31bfead080d063cf /spec/services
parentd2b64c37bdef067656fdc8deb4728a2fbc6c2729 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/emails/create_service_spec.rb2
-rw-r--r--spec/services/issues/move_service_spec.rb2
-rw-r--r--spec/services/notification_recipients/builder/new_note_spec.rb64
-rw-r--r--spec/services/projects/fork_service_spec.rb4
4 files changed, 68 insertions, 4 deletions
diff --git a/spec/services/emails/create_service_spec.rb b/spec/services/emails/create_service_spec.rb
index 87f93ec97c9..23c2f53dca0 100644
--- a/spec/services/emails/create_service_spec.rb
+++ b/spec/services/emails/create_service_spec.rb
@@ -16,7 +16,7 @@ describe Emails::CreateService do
it 'creates an email with additional attributes' do
expect { service.execute(confirmation_token: 'abc') }.to change { Email.count }.by(1)
- expect(Email.where(opts).first.confirmation_token).to eq 'abc'
+ expect(Email.find_by(opts).confirmation_token).to eq 'abc'
end
it 'has the right user association' do
diff --git a/spec/services/issues/move_service_spec.rb b/spec/services/issues/move_service_spec.rb
index ccd4dd4231b..a449541f459 100644
--- a/spec/services/issues/move_service_spec.rb
+++ b/spec/services/issues/move_service_spec.rb
@@ -100,7 +100,7 @@ describe Issues::MoveService do
context 'when issue has notes with mentions' do
it 'saves user mentions with actual mentions for new issue' do
- expect(new_issue.user_mentions.where(note_id: nil).first.mentioned_users_ids).to match_array([user.id])
+ expect(new_issue.user_mentions.find_by(note_id: nil).mentioned_users_ids).to match_array([user.id])
expect(new_issue.user_mentions.where.not(note_id: nil).first.mentioned_users_ids).to match_array([user.id])
expect(new_issue.user_mentions.where.not(note_id: nil).count).to eq 1
expect(new_issue.user_mentions.count).to eq 2
diff --git a/spec/services/notification_recipients/builder/new_note_spec.rb b/spec/services/notification_recipients/builder/new_note_spec.rb
new file mode 100644
index 00000000000..f88e8b2dfb0
--- /dev/null
+++ b/spec/services/notification_recipients/builder/new_note_spec.rb
@@ -0,0 +1,64 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe NotificationRecipients::Builder::NewNote do
+ describe '#notification_recipients' do
+ let_it_be(:group) { create(:group, :public) }
+ let_it_be(:project) { create(:project, :public, group: group) }
+ let_it_be(:issue) { create(:issue, project: project) }
+
+ let_it_be(:other_user) { create(:user) }
+ let_it_be(:participant) { create(:user) }
+ let_it_be(:non_member_participant) { create(:user) }
+ let_it_be(:group_watcher) { create(:user) }
+ let_it_be(:project_watcher) { create(:user) }
+ let_it_be(:guest_project_watcher) { create(:user) }
+ let_it_be(:subscriber) { create(:user) }
+ let_it_be(:unsubscribed_user) { create(:user) }
+ let_it_be(:non_member_subscriber) { create(:user) }
+
+ let_it_be(:notification_setting_project_w) { create(:notification_setting, source: project, user: project_watcher, level: 2) }
+ let_it_be(:notification_setting_guest_w) { create(:notification_setting, source: project, user: guest_project_watcher, level: 2) }
+ let_it_be(:notification_setting_group_w) { create(:notification_setting, source: group, user: group_watcher, level: 2) }
+ let_it_be(:subscriptions) do
+ [
+ create(:subscription, project: project, user: subscriber, subscribable: issue, subscribed: true),
+ create(:subscription, project: project, user: unsubscribed_user, subscribable: issue, subscribed: false),
+ create(:subscription, project: project, user: non_member_subscriber, subscribable: issue, subscribed: true)
+ ]
+ end
+
+ subject { described_class.new(note) }
+
+ before do
+ project.add_developer(participant)
+ project.add_developer(project_watcher)
+ project.add_guest(guest_project_watcher)
+ project.add_developer(subscriber)
+ group.add_developer(group_watcher)
+
+ expect(issue).to receive(:participants).and_return([participant, non_member_participant])
+ end
+
+ context 'for public notes' do
+ let_it_be(:note) { create(:note, noteable: issue, project: project) }
+
+ it 'adds all participants, watchers and subscribers' do
+ expect(subject.notification_recipients.map(&:user)).to contain_exactly(
+ participant, non_member_participant, project_watcher, group_watcher, guest_project_watcher, subscriber, non_member_subscriber
+ )
+ end
+ end
+
+ context 'for confidential notes' do
+ let_it_be(:note) { create(:note, :confidential, noteable: issue, project: project) }
+
+ it 'adds all participants, watchers and subscribers that are project memebrs' do
+ expect(subject.notification_recipients.map(&:user)).to contain_exactly(
+ participant, project_watcher, group_watcher, subscriber
+ )
+ end
+ end
+ end
+end
diff --git a/spec/services/projects/fork_service_spec.rb b/spec/services/projects/fork_service_spec.rb
index 55987c6fa0f..443e3dfddf1 100644
--- a/spec/services/projects/fork_service_spec.rb
+++ b/spec/services/projects/fork_service_spec.rb
@@ -321,9 +321,9 @@ describe Projects::ForkService do
Projects::UpdateRepositoryStorageService.new(project).execute('test_second_storage')
fork_after_move = fork_project(project)
pool_repository_before_move = PoolRepository.joins(:shard)
- .where(source_project: project, shards: { name: 'default' }).first
+ .find_by(source_project: project, shards: { name: 'default' })
pool_repository_after_move = PoolRepository.joins(:shard)
- .where(source_project: project, shards: { name: 'test_second_storage' }).first
+ .find_by(source_project: project, shards: { name: 'test_second_storage' })
expect(fork_before_move.pool_repository).to eq(pool_repository_before_move)
expect(fork_after_move.pool_repository).to eq(pool_repository_after_move)