require 'spec_helper' describe SystemNoteService do include Gitlab::Routing include RepoHelpers set(:group) { create(:group) } set(:project) { create(:project, :repository, group: group) } set(:author) { create(:user) } let(:noteable) { create(:issue, project: project) } let(:issue) { noteable } shared_examples_for 'a system note' do let(:expected_noteable) { noteable } let(:commit_count) { nil } it 'has the correct attributes', :aggregate_failures do expect(subject).to be_valid expect(subject).to be_system expect(subject.noteable).to eq expected_noteable expect(subject.project).to eq project expect(subject.author).to eq author expect(subject.system_note_metadata.action).to eq(action) expect(subject.system_note_metadata.commit_count).to eq(commit_count) end end describe '.add_commits' do subject { described_class.add_commits(noteable, project, author, new_commits, old_commits, oldrev) } let(:noteable) { create(:merge_request, source_project: project, target_project: project) } let(:new_commits) { noteable.commits } let(:old_commits) { [] } let(:oldrev) { nil } it_behaves_like 'a system note' do let(:commit_count) { new_commits.size } let(:action) { 'commit' } end describe 'note body' do let(:note_lines) { subject.note.split("\n").reject(&:blank?) } describe 'comparison diff link line' do it 'adds the comparison text' do expect(note_lines[2]).to match "[Compare with previous version]" end end context 'without existing commits' do it 'adds a message header' do expect(note_lines[0]).to eq "added #{new_commits.size} commits" end it 'adds a message for each commit' do decoded_note_content = HTMLEntities.new.decode(subject.note) new_commits.each do |commit| expect(decoded_note_content).to include("
  • #{commit.short_id} - #{commit.title}
  • ") end end end describe 'summary line for existing commits' do let(:summary_line) { note_lines[1] } context 'with one existing commit' do let(:old_commits) { [noteable.commits.last] } it 'includes the existing commit' do expect(summary_line).to start_with("