2019-10-16 05:07:51 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-11 09:21:06 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe UserRecentEventsFinder do
|
2020-06-19 14:08:39 -04:00
|
|
|
let_it_be(:project_owner, reload: true) { create(:user) }
|
|
|
|
let_it_be(:current_user, reload: true) { create(:user) }
|
2018-06-12 11:02:06 -04:00
|
|
|
let(:private_project) { create(:project, :private, creator: project_owner) }
|
|
|
|
let(:internal_project) { create(:project, :internal, creator: project_owner) }
|
|
|
|
let(:public_project) { create(:project, :public, creator: project_owner) }
|
|
|
|
let!(:private_event) { create(:event, project: private_project, author: project_owner) }
|
|
|
|
let!(:internal_event) { create(:event, project: internal_project, author: project_owner) }
|
|
|
|
let!(:public_event) { create(:event, project: public_project, author: project_owner) }
|
2020-09-02 11:10:54 -04:00
|
|
|
let(:limit) { nil }
|
|
|
|
let(:params) { { limit: limit } }
|
2017-12-11 09:21:06 -05:00
|
|
|
|
2020-09-02 11:10:54 -04:00
|
|
|
subject(:finder) { described_class.new(current_user, project_owner, params) }
|
2017-12-11 09:21:06 -05:00
|
|
|
|
|
|
|
describe '#execute' do
|
2018-09-07 11:08:55 -04:00
|
|
|
context 'when profile is public' do
|
|
|
|
it 'returns all the events' do
|
|
|
|
expect(finder.execute).to include(private_event, internal_event, public_event)
|
2018-06-12 11:02:06 -04:00
|
|
|
end
|
2017-12-11 09:21:06 -05:00
|
|
|
end
|
|
|
|
|
2018-09-07 11:08:55 -04:00
|
|
|
context 'when profile is private' do
|
|
|
|
it 'returns no event' do
|
|
|
|
allow(Ability).to receive(:allowed?).and_call_original
|
|
|
|
allow(Ability).to receive(:allowed?).with(current_user, :read_user_profile, project_owner).and_return(false)
|
2017-12-11 09:21:06 -05:00
|
|
|
|
|
|
|
expect(finder.execute).to be_empty
|
|
|
|
end
|
|
|
|
end
|
2018-06-12 11:02:06 -04:00
|
|
|
|
2018-09-07 11:08:55 -04:00
|
|
|
it 'does not include the events if the user cannot read cross project' do
|
2018-12-07 12:09:00 -05:00
|
|
|
allow(Ability).to receive(:allowed?).and_call_original
|
2018-09-07 11:08:55 -04:00
|
|
|
expect(Ability).to receive(:allowed?).with(current_user, :read_cross_project) { false }
|
2018-12-07 12:09:00 -05:00
|
|
|
|
2018-09-07 11:08:55 -04:00
|
|
|
expect(finder.execute).to be_empty
|
2018-06-12 11:02:06 -04:00
|
|
|
end
|
2020-06-19 14:08:39 -04:00
|
|
|
|
2020-07-16 20:09:37 -04:00
|
|
|
describe 'design activity events' do
|
2020-06-19 14:08:39 -04:00
|
|
|
let_it_be(:event_a) { create(:design_event, author: project_owner) }
|
|
|
|
let_it_be(:event_b) { create(:design_event, author: project_owner) }
|
|
|
|
|
2020-07-16 20:09:37 -04:00
|
|
|
it 'only includes design events', :aggregate_failures do
|
|
|
|
events = finder.execute
|
2020-06-19 14:08:39 -04:00
|
|
|
|
2020-07-16 20:09:37 -04:00
|
|
|
expect(events).to include(event_a)
|
|
|
|
expect(events).to include(event_b)
|
2020-06-19 14:08:39 -04:00
|
|
|
end
|
|
|
|
end
|
2020-09-02 11:10:54 -04:00
|
|
|
|
|
|
|
context 'limits' do
|
|
|
|
before do
|
|
|
|
stub_const("#{described_class}::DEFAULT_LIMIT", 1)
|
|
|
|
stub_const("#{described_class}::MAX_LIMIT", 3)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when limit is not set' do
|
|
|
|
it 'returns events limited to DEFAULT_LIMIT' do
|
|
|
|
expect(finder.execute.size).to eq(described_class::DEFAULT_LIMIT)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when limit is set' do
|
|
|
|
let(:limit) { 2 }
|
|
|
|
|
|
|
|
it 'returns events limited to specified limit' do
|
|
|
|
expect(finder.execute.size).to eq(limit)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when limit is set to a number that exceeds maximum limit' do
|
|
|
|
let(:limit) { 4 }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(:event, project: public_project, author: project_owner)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns events limited to MAX_LIMIT' do
|
|
|
|
expect(finder.execute.size).to eq(described_class::MAX_LIMIT)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-12-11 09:21:06 -05:00
|
|
|
end
|
|
|
|
end
|