2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_examples 'system note creation' do |update_params, note_text|
|
2019-02-15 15:39:39 +05:30
|
|
|
subject { described_class.new(project, user).execute(issuable, old_labels: []) }
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
issuable.assign_attributes(update_params)
|
2020-11-24 15:15:51 +05:30
|
|
|
issuable.save!
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates 1 system note with the correct content' do
|
|
|
|
expect { subject }.to change { Note.count }.from(0).to(1)
|
|
|
|
|
|
|
|
note = Note.last
|
|
|
|
expect(note.note).to match(note_text)
|
|
|
|
expect(note.noteable_type).to eq(issuable.class.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.shared_examples 'draft notes creation' do |wip_action|
|
2019-02-15 15:39:39 +05:30
|
|
|
subject { described_class.new(project, user).execute(issuable, old_labels: []) }
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it 'creates Draft toggle and title change notes' do
|
2018-10-15 14:42:47 +05:30
|
|
|
expect { subject }.to change { Note.count }.from(0).to(2)
|
|
|
|
|
|
|
|
expect(Note.first.note).to match("#{wip_action} as a **Work In Progress**")
|
|
|
|
expect(Note.second.note).to match('changed title')
|
|
|
|
end
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_examples 'a note with overridable created_at' do
|
2019-12-21 20:55:43 +05:30
|
|
|
let(:noteable) { create(:issue, project: project, system_note_timestamp: Time.at(42)) }
|
|
|
|
|
|
|
|
it 'the note has the correct time' do
|
|
|
|
expect(subject.created_at).to eq Time.at(42)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_examples 'a system note' do |params|
|
2019-12-21 20:55:43 +05:30
|
|
|
let(:expected_noteable) { noteable }
|
|
|
|
let(:commit_count) { nil }
|
|
|
|
|
|
|
|
it 'has the correct attributes', :aggregate_failures do
|
|
|
|
exclude_project = !params.nil? && params[:exclude_project]
|
|
|
|
|
|
|
|
expect(subject).to be_valid
|
|
|
|
expect(subject).to be_system
|
|
|
|
|
|
|
|
expect(subject.noteable).to eq expected_noteable
|
|
|
|
expect(subject.project).to eq project unless exclude_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
|