2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-15 09:19:45 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe NoteSummary do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { build(:project) }
|
2017-03-15 09:19:45 -04:00
|
|
|
let(:noteable) { build(:issue) }
|
|
|
|
let(:user) { build(:user) }
|
|
|
|
|
|
|
|
def create_note_summary
|
|
|
|
described_class.new(noteable, project, user, 'note', action: 'icon', commit_count: 5)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#metadata?' do
|
|
|
|
it 'returns true when metadata present' do
|
|
|
|
expect(create_note_summary.metadata?).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when metadata not present' do
|
|
|
|
expect(described_class.new(noteable, project, user, 'note').metadata?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#note' do
|
|
|
|
it 'returns note hash' do
|
2019-04-08 11:33:30 -04:00
|
|
|
Timecop.freeze do
|
|
|
|
expect(create_note_summary.note).to eq(noteable: noteable, project: project, author: user, note: 'note',
|
|
|
|
created_at: Time.now)
|
|
|
|
end
|
2017-03-15 09:19:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when noteable is a commit' do
|
2019-04-08 11:33:30 -04:00
|
|
|
let(:noteable) { build(:commit, system_note_timestamp: Time.at(43)) }
|
2017-03-15 09:19:45 -04:00
|
|
|
|
|
|
|
it 'returns note hash specific to commit' do
|
|
|
|
expect(create_note_summary.note).to eq(
|
|
|
|
noteable: nil, project: project, author: user, note: 'note',
|
2019-04-08 11:33:30 -04:00
|
|
|
noteable_type: 'Commit', commit_id: noteable.id,
|
|
|
|
created_at: Time.at(43)
|
2017-03-15 09:19:45 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#metadata' do
|
|
|
|
it 'returns metadata hash' do
|
|
|
|
expect(create_note_summary.metadata).to eq(action: 'icon', commit_count: 5)
|
|
|
|
end
|
2019-10-18 07:11:44 -04:00
|
|
|
|
|
|
|
context 'description action and noteable has saved_description_version' do
|
|
|
|
before do
|
|
|
|
noteable.saved_description_version = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.new(noteable, project, user, 'note', action: 'description') }
|
|
|
|
|
|
|
|
it 'sets the description_version metadata' do
|
|
|
|
expect(subject.metadata).to include(description_version: 1)
|
|
|
|
end
|
|
|
|
end
|
2017-03-15 09:19:45 -04:00
|
|
|
end
|
|
|
|
end
|