diff options
Diffstat (limited to 'spec/services/system_note_service_spec.rb')
-rw-r--r-- | spec/services/system_note_service_spec.rb | 257 |
1 files changed, 129 insertions, 128 deletions
diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb index 194687cbbd6..3e9528a83d0 100644 --- a/spec/services/system_note_service_spec.rb +++ b/spec/services/system_note_service_spec.rb @@ -23,82 +23,75 @@ describe SystemNoteService do end end - describe '.assignee_change' do - let(:assignee) { create(:user) } + describe '.add_commits' do + let(:noteable) { create(:merge_request, source_project: project) } + let(:new_commits) { noteable.commits } + let(:old_commits) { [] } + let(:oldrev) { nil } - subject { described_class.assignee_change(noteable, project, author, assignee) } + subject { described_class.add_commits(noteable, project, author, new_commits, old_commits, oldrev) } it_behaves_like 'a system note' - context 'when assignee added' do - it 'sets the note text' do - expect(subject.note).to eq "Reassigned to @#{assignee.username}" - end - end + describe 'note body' do + let(:note_lines) { subject.note.split("\n").reject(&:blank?) } - context 'when assignee removed' do - let(:assignee) { nil } + context 'without existing commits' do + it 'adds a message header' do + expect(note_lines[0]).to eq "Added #{new_commits.size} commits:" + end - it 'sets the note text' do - expect(subject.note).to eq 'Assignee removed' + it 'adds a message line for each commit' do + new_commits.each_with_index do |commit, i| + # Skip the header + expect(note_lines[i + 1]).to eq "* #{commit.short_id} - #{commit.title}" + end + end end - end - end - describe '.cross_reference' do - let(:mentioner) { create(:issue, project: project) } - - subject { described_class.cross_reference(noteable, mentioner, author) } - - it_behaves_like 'a system note' - - context 'when cross-reference disallowed' do - before do - expect(described_class).to receive(:cross_reference_disallowed?).and_return(true) - end + describe 'summary line for existing commits' do + let(:summary_line) { note_lines[1] } - it 'returns nil' do - expect(subject).to be_nil - end - end + context 'with one existing commit' do + let(:old_commits) { [noteable.commits.last] } - context 'when cross-reference allowed' do - before do - expect(described_class).to receive(:cross_reference_disallowed?).and_return(false) - end + it 'includes the existing commit' do + expect(summary_line).to eq "* #{old_commits.first.short_id} - 1 commit from branch `feature`" + end + end - describe 'note_body' do - context 'cross-project' do - let(:project2) { create(:project) } - let(:mentioner) { create(:issue, project: project2) } + context 'with multiple existing commits' do + let(:old_commits) { noteable.commits[3..-1] } - context 'from Commit' do - let(:mentioner) { project2.repository.commit } + context 'with oldrev' do + let(:oldrev) { noteable.commits[2].id } - it 'references the mentioning commit' do - expect(subject.note).to eq "mentioned in commit #{project2.path_with_namespace}@#{mentioner.id}" + it 'includes a commit range' do + expect(summary_line).to start_with "* #{Commit.truncate_sha(oldrev)}...#{old_commits.last.short_id}" end - end - context 'from non-Commit' do - it 'references the mentioning object' do - expect(subject.note).to eq "mentioned in issue #{project2.path_with_namespace}##{mentioner.iid}" + it 'includes a commit count' do + expect(summary_line).to end_with " - 2 commits from branch `feature`" end end - end - context 'same project' do - context 'from Commit' do - let(:mentioner) { project.repository.commit } + context 'without oldrev' do + it 'includes a commit range' do + expect(summary_line).to start_with "* #{old_commits[0].short_id}..#{old_commits[-1].short_id}" + end - it 'references the mentioning commit' do - expect(subject.note).to eq "mentioned in commit #{mentioner.id}" + it 'includes a commit count' do + expect(summary_line).to end_with " - 2 commits from branch `feature`" end end - context 'from non-Commit' do - it 'references the mentioning object' do - expect(subject.note).to eq "mentioned in issue ##{mentioner.iid}" + context 'on a fork' do + before do + expect(noteable).to receive(:for_fork?).and_return(true) + end + + it 'includes the project namespace' do + expect(summary_line).to end_with "`#{noteable.target_project_namespace}:feature`" end end end @@ -106,12 +99,34 @@ describe SystemNoteService do end end - describe '.label_change' do + describe '.change_assignee' do + let(:assignee) { create(:user) } + + subject { described_class.change_assignee(noteable, project, author, assignee) } + + it_behaves_like 'a system note' + + context 'when assignee added' do + it 'sets the note text' do + expect(subject.note).to eq "Reassigned to @#{assignee.username}" + end + end + + context 'when assignee removed' do + let(:assignee) { nil } + + it 'sets the note text' do + expect(subject.note).to eq 'Assignee removed' + end + end + end + + describe '.change_label' do let(:labels) { create_list(:label, 2) } let(:added) { [] } let(:removed) { [] } - subject { described_class.label_change(noteable, project, author, added, removed) } + subject { described_class.change_label(noteable, project, author, added, removed) } it_behaves_like 'a system note' @@ -143,10 +158,10 @@ describe SystemNoteService do end end - describe '.milestone_change' do + describe '.change_milestone' do let(:milestone) { create(:milestone, project: project) } - subject { described_class.milestone_change(noteable, project, author, milestone) } + subject { described_class.change_milestone(noteable, project, author, milestone) } it_behaves_like 'a system note' @@ -165,101 +180,86 @@ describe SystemNoteService do end end - describe '.commit_add' do - let(:noteable) { create(:merge_request, source_project: project) } - let(:new_commits) { noteable.commits } - let(:old_commits) { [] } - let(:oldrev) { nil } + describe '.change_status' do + let(:status) { 'new_status' } + let(:source) { nil } - subject { described_class.commit_add(noteable, project, author, new_commits, old_commits, oldrev) } + subject { described_class.change_status(noteable, project, author, status, source) } it_behaves_like 'a system note' - describe 'note body' do - let(:note_lines) { subject.note.split("\n").reject(&:blank?) } + context 'with a source' do + let(:source) { double('commit', gfm_reference: 'commit 123456') } - context 'without existing commits' do - it 'adds a message header' do - expect(note_lines[0]).to eq "Added #{new_commits.size} commits:" - end + it 'sets the note text' do + expect(subject.note).to eq "Status changed to #{status} by commit 123456" + end + end - it 'adds a message line for each commit' do - new_commits.each_with_index do |commit, i| - # Skip the header - expect(note_lines[i + 1]).to eq "* #{commit.short_id} - #{commit.title}" - end - end + context 'without a source' do + it 'sets the note text' do + expect(subject.note).to eq "Status changed to #{status}" end + end + end - describe 'summary line for existing commits' do - let(:summary_line) { note_lines[1] } + describe '.cross_reference' do + let(:mentioner) { create(:issue, project: project) } - context 'with one existing commit' do - let(:old_commits) { [noteable.commits.last] } + subject { described_class.cross_reference(noteable, mentioner, author) } - it 'includes the existing commit' do - expect(summary_line).to eq "* #{old_commits.first.short_id} - 1 commit from branch `feature`" - end - end + it_behaves_like 'a system note' - context 'with multiple existing commits' do - let(:old_commits) { noteable.commits[3..-1] } + context 'when cross-reference disallowed' do + before do + expect(described_class).to receive(:cross_reference_disallowed?).and_return(true) + end - context 'with oldrev' do - let(:oldrev) { noteable.commits[2].id } + it 'returns nil' do + expect(subject).to be_nil + end + end - it 'includes a commit range' do - expect(summary_line).to start_with "* #{Commit.truncate_sha(oldrev)}...#{old_commits.last.short_id}" - end + context 'when cross-reference allowed' do + before do + expect(described_class).to receive(:cross_reference_disallowed?).and_return(false) + end - it 'includes a commit count' do - expect(summary_line).to end_with " - 2 commits from branch `feature`" - end - end + describe 'note_body' do + context 'cross-project' do + let(:project2) { create(:project) } + let(:mentioner) { create(:issue, project: project2) } - context 'without oldrev' do - it 'includes a commit range' do - expect(summary_line).to start_with "* #{old_commits[0].short_id}..#{old_commits[-1].short_id}" - end + context 'from Commit' do + let(:mentioner) { project2.repository.commit } - it 'includes a commit count' do - expect(summary_line).to end_with " - 2 commits from branch `feature`" + it 'references the mentioning commit' do + expect(subject.note).to eq "mentioned in commit #{project2.path_with_namespace}@#{mentioner.id}" end end - context 'on a fork' do - before do - expect(noteable).to receive(:for_fork?).and_return(true) - end - - it 'includes the project namespace' do - expect(summary_line).to end_with "`#{noteable.target_project_namespace}:feature`" + context 'from non-Commit' do + it 'references the mentioning object' do + expect(subject.note).to eq "mentioned in issue #{project2.path_with_namespace}##{mentioner.iid}" end end end - end - end - end - - describe '.status_change' do - let(:status) { 'new_status' } - let(:source) { nil } - subject { described_class.status_change(noteable, project, author, status, source) } - - it_behaves_like 'a system note' - - context 'with a source' do - let(:source) { double('commit', gfm_reference: 'commit 123456') } + context 'same project' do + context 'from Commit' do + let(:mentioner) { project.repository.commit } - it 'sets the note text' do - expect(subject.note).to eq "Status changed to #{status} by commit 123456" - end - end + it 'references the mentioning commit' do + expect(subject.note).to eq "mentioned in commit #{mentioner.id}" + end + end - context 'without a source' do - it 'sets the note text' do - expect(subject.note).to eq "Status changed to #{status}" + context 'from non-Commit' do + it 'references the mentioning object' do + expect(subject.note).to eq "mentioned in issue ##{mentioner.iid}" + end + end + end end end end @@ -274,6 +274,7 @@ describe SystemNoteService do end end + # TODO (rspeicher) describe '.cross_reference_disallowed?' describe '.cross_reference_exists?' do |