diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-14 00:09:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-14 00:09:07 +0000 |
commit | e144369009f3404072f7e0f969f7cded93195a01 (patch) | |
tree | d7a354e2c3c69a7ad65dc81aba8fe2ba59b0a26f /spec/services/issues | |
parent | d466ee5042520ad078fe050cb078d81dc2ebe196 (diff) | |
download | gitlab-ce-e144369009f3404072f7e0f969f7cded93195a01.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/issues')
-rw-r--r-- | spec/services/issues/create_service_spec.rb | 25 | ||||
-rw-r--r-- | spec/services/issues/move_service_spec.rb | 14 | ||||
-rw-r--r-- | spec/services/issues/update_service_spec.rb | 43 |
3 files changed, 81 insertions, 1 deletions
diff --git a/spec/services/issues/create_service_spec.rb b/spec/services/issues/create_service_spec.rb index 44d4cd70f9a..c9701e5d194 100644 --- a/spec/services/issues/create_service_spec.rb +++ b/spec/services/issues/create_service_spec.rb @@ -171,6 +171,31 @@ describe Issues::CreateService do described_class.new(project, user, opts).execute end + + context 'after_save callback to store_mentions' do + context 'when mentionable attributes change' do + let(:opts) { { title: 'Title', description: "Description with #{user.to_reference}" } } + + it 'saves mentions' do + expect_next_instance_of(Issue) do |instance| + expect(instance).to receive(:store_mentions!).and_call_original + end + expect(issue.user_mentions.count).to eq 1 + end + end + + context 'when save fails' do + let(:opts) { { title: '', label_ids: labels.map(&:id), milestone_id: milestone.id } } + + it 'does not call store_mentions' do + expect_next_instance_of(Issue) do |instance| + expect(instance).not_to receive(:store_mentions!).and_call_original + end + expect(issue.valid?).to be false + expect(issue.user_mentions.count).to eq 0 + end + end + end end context 'issue create service' do diff --git a/spec/services/issues/move_service_spec.rb b/spec/services/issues/move_service_spec.rb index ee809aabac0..ccd4dd4231b 100644 --- a/spec/services/issues/move_service_spec.rb +++ b/spec/services/issues/move_service_spec.rb @@ -6,7 +6,7 @@ describe Issues::MoveService do let(:user) { create(:user) } let(:author) { create(:user) } let(:title) { 'Some issue' } - let(:description) { 'Some issue description' } + let(:description) { "Some issue description with mention to #{user.to_reference}" } let(:group) { create(:group, :private) } let(:sub_group_1) { create(:group, :private, parent: group) } let(:sub_group_2) { create(:group, :private, parent: group) } @@ -36,6 +36,9 @@ describe Issues::MoveService do end context 'issue movable' do + let!(:note_with_mention) { create(:note, noteable: old_issue, author: author, project: old_project, note: "note with mention #{user.to_reference}") } + let!(:note_with_no_mention) { create(:note, noteable: old_issue, author: author, project: old_project, note: "note without mention") } + include_context 'user can move issue' context 'generic issue' do @@ -94,6 +97,15 @@ describe Issues::MoveService do it 'moves the award emoji' do expect(old_issue.award_emoji.first.name).to eq new_issue.reload.award_emoji.first.name end + + 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.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 + end + end end context 'issue with assignee' do diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb index 64bca770d5b..888a63980f6 100644 --- a/spec/services/issues/update_service_spec.rb +++ b/spec/services/issues/update_service_spec.rb @@ -211,6 +211,49 @@ describe Issues::UpdateService, :mailer do expect(note.note).to eq 'locked this issue' end end + + context 'after_save callback to store_mentions' do + let(:issue) { create(:issue, title: 'Old title', description: "simple description", project: project, author: create(:user)) } + let(:labels) { create_pair(:label, project: project) } + let(:milestone) { create(:milestone, project: project) } + + context 'when mentionable attributes change' do + let(:opts) { { description: "Description with #{user.to_reference}" } } + + it 'saves mentions' do + expect(issue).to receive(:store_mentions!).and_call_original + + expect { update_issue(opts) }.to change { IssueUserMention.count }.by(1) + + expect(issue.referenced_users).to match_array([user]) + end + end + + context 'when mentionable attributes do not change' do + let(:opts) { { label_ids: labels.map(&:id), milestone_id: milestone.id } } + + it 'does not call store_mentions' do + expect(issue).not_to receive(:store_mentions!).and_call_original + + expect { update_issue(opts) }.not_to change { IssueUserMention.count } + + expect(issue.referenced_users).to be_empty + end + end + + context 'when save fails' do + let(:opts) { { title: '', label_ids: labels.map(&:id), milestone_id: milestone.id } } + + it 'does not call store_mentions' do + expect(issue).not_to receive(:store_mentions!).and_call_original + + expect { update_issue(opts) }.not_to change { IssueUserMention.count } + + expect(issue.referenced_users).to be_empty + expect(issue.valid?).to be false + end + end + end end context 'when description changed' do |