2019-09-02 07:12:20 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::NoteableMetadata do
|
2019-09-02 07:12:20 -04:00
|
|
|
subject { Class.new { include Gitlab::NoteableMetadata }.new }
|
|
|
|
|
|
|
|
it 'returns an empty Hash if an empty collection is provided' do
|
|
|
|
expect(subject.noteable_meta_data(Snippet.none, 'Snippet')).to eq({})
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an error when given a collection with no limit' do
|
|
|
|
expect { subject.noteable_meta_data(Snippet.all, 'Snippet') }.to raise_error(/must have a limit/)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'snippets' do
|
|
|
|
let!(:snippet) { create(:personal_snippet) }
|
|
|
|
let!(:other_snippet) { create(:personal_snippet) }
|
|
|
|
let!(:note) { create(:note, noteable: snippet) }
|
|
|
|
|
|
|
|
it 'aggregates stats on snippets' do
|
|
|
|
data = subject.noteable_meta_data(Snippet.all.limit(10), 'Snippet')
|
|
|
|
|
|
|
|
expect(data.count).to eq(2)
|
|
|
|
expect(data[snippet.id].user_notes_count).to eq(1)
|
|
|
|
expect(data[other_snippet.id].user_notes_count).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|