debian-mirror-gitlab/spec/services/note_summary_spec.rb

63 lines
1.8 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe NoteSummary do
2017-09-10 17:25:29 +05:30
let(:project) { build(:project) }
2017-08-17 22:00:37 +05:30
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-07-31 22:56:46 +05:30
Timecop.freeze do
expect(create_note_summary.note).to eq(noteable: noteable, project: project, author: user, note: 'note',
2020-05-24 23:13:21 +05:30
created_at: Time.current)
2019-07-31 22:56:46 +05:30
end
2017-08-17 22:00:37 +05:30
end
context 'when noteable is a commit' do
2020-05-24 23:13:21 +05:30
let(:noteable) { build(:commit, system_note_timestamp: Time.zone.at(43)) }
2017-08-17 22:00:37 +05:30
it 'returns note hash specific to commit' do
expect(create_note_summary.note).to eq(
noteable: nil, project: project, author: user, note: 'note',
2019-07-31 22:56:46 +05:30
noteable_type: 'Commit', commit_id: noteable.id,
2020-05-24 23:13:21 +05:30
created_at: Time.zone.at(43)
2017-08-17 22:00:37 +05:30
)
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-12-21 20:55:43 +05:30
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-08-17 22:00:37 +05:30
end
end