2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe EventCollection do
|
|
|
|
describe '#to_a' do
|
2019-12-21 20:55:43 +05:30
|
|
|
set(:group) { create(:group) }
|
|
|
|
set(:project) { create(:project_empty_repo, group: group) }
|
|
|
|
set(:projects) { Project.where(id: project.id) }
|
|
|
|
set(:user) { create(:user) }
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
context 'with project events' do
|
|
|
|
before do
|
|
|
|
20.times do
|
|
|
|
event = create(:push_event, project: project, author: user)
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
create(:push_event_payload, event: event)
|
|
|
|
end
|
|
|
|
|
|
|
|
create(:closed_issue_event, project: project, author: user)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it 'returns an Array of events' do
|
|
|
|
events = described_class.new(projects).to_a
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(events).to be_an_instance_of(Array)
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it 'applies a limit to the number of events' do
|
|
|
|
events = described_class.new(projects).to_a
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(events.length).to eq(20)
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it 'can paginate through events' do
|
|
|
|
events = described_class.new(projects, offset: 20).to_a
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(events.length).to eq(1)
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it 'returns an empty Array when crossing the maximum page number' do
|
|
|
|
events = described_class.new(projects, limit: 1, offset: 15).to_a
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(events).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows filtering of events using an EventFilter' do
|
|
|
|
filter = EventFilter.new(EventFilter::ISSUE)
|
|
|
|
events = described_class.new(projects, filter: filter).to_a
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(events.length).to eq(1)
|
|
|
|
expect(events[0].action).to eq(Event::CLOSED)
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
context 'with group events' do
|
|
|
|
let(:groups) { group.self_and_descendants.public_or_visible_to_user(user) }
|
|
|
|
let(:subject) { described_class.new(projects, groups: groups).to_a }
|
|
|
|
|
|
|
|
it 'includes also group events' do
|
|
|
|
subgroup = create(:group, parent: group)
|
|
|
|
event1 = create(:event, project: project, author: user)
|
|
|
|
event2 = create(:event, project: nil, group: group, author: user)
|
|
|
|
event3 = create(:event, project: nil, group: subgroup, author: user)
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(subject).to eq([event3, event2, event1])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include events from inaccessible groups' do
|
|
|
|
subgroup = create(:group, :private, parent: group)
|
|
|
|
event1 = create(:event, project: nil, group: group, author: user)
|
|
|
|
create(:event, project: nil, group: subgroup, author: user)
|
|
|
|
|
|
|
|
expect(subject).to eq([event1])
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|