diff options
Diffstat (limited to 'spec/finders/user_recent_events_finder_spec.rb')
-rw-r--r-- | spec/finders/user_recent_events_finder_spec.rb | 112 |
1 files changed, 102 insertions, 10 deletions
diff --git a/spec/finders/user_recent_events_finder_spec.rb b/spec/finders/user_recent_events_finder_spec.rb index afebff5b5c9..5a9243d150d 100644 --- a/spec/finders/user_recent_events_finder_spec.rb +++ b/spec/finders/user_recent_events_finder_spec.rb @@ -5,16 +5,17 @@ require 'spec_helper' RSpec.describe UserRecentEventsFinder do let_it_be(:project_owner, reload: true) { create(:user) } let_it_be(:current_user, reload: true) { create(:user) } - 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_it_be(:private_project) { create(:project, :private, creator: project_owner) } + let_it_be(:internal_project) { create(:project, :internal, creator: project_owner) } + let_it_be(: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) } + let_it_be(:issue) { create(:issue, project: public_project) } let(:limit) { nil } let(:params) { { limit: limit } } - subject(:finder) { described_class.new(current_user, project_owner, params) } + subject(:finder) { described_class.new(current_user, project_owner, nil, params) } describe '#execute' do context 'when profile is public' do @@ -39,15 +40,106 @@ RSpec.describe UserRecentEventsFinder do expect(finder.execute).to be_empty end - describe 'design activity events' do - let_it_be(:event_a) { create(:design_event, author: project_owner) } - let_it_be(:event_b) { create(:design_event, author: project_owner) } + context 'events from multiple users' do + let_it_be(:second_user, reload: true) { create(:user) } + let_it_be(:private_project_second_user) { create(:project, :private, creator: second_user) } + let(:internal_project_second_user) { create(:project, :internal, creator: second_user) } + let(:public_project_second_user) { create(:project, :public, creator: second_user) } + let!(:private_event_second_user) { create(:event, project: private_project_second_user, author: second_user) } + let!(:internal_event_second_user) { create(:event, project: internal_project_second_user, author: second_user) } + let!(:public_event_second_user) { create(:event, project: public_project_second_user, author: second_user) } + + it 'includes events from all users', :aggregate_failures do + events = described_class.new(current_user, [project_owner, second_user], nil, params).execute + + expect(events).to include(private_event, internal_event, public_event) + expect(events).to include(private_event_second_user, internal_event_second_user, public_event_second_user) + expect(events.size).to eq(6) + end + + it 'does not include events from users with private profile', :aggregate_failures do + allow(Ability).to receive(:allowed?).and_call_original + allow(Ability).to receive(:allowed?).with(current_user, :read_user_profile, second_user).and_return(false) + + events = described_class.new(current_user, [project_owner, second_user], nil, params).execute + + expect(events).to include(private_event, internal_event, public_event) + expect(events.size).to eq(3) + end + end + + context 'filter activity events' do + let!(:push_event) { create(:push_event, project: public_project, author: project_owner) } + let!(:merge_event) { create(:event, :merged, project: public_project, author: project_owner) } + let!(:issue_event) { create(:event, :closed, project: public_project, target: issue, author: project_owner) } + let!(:comment_event) { create(:event, :commented, project: public_project, author: project_owner) } + let!(:wiki_event) { create(:wiki_page_event, project: public_project, author: project_owner) } + let!(:design_event) { create(:design_event, project: public_project, author: project_owner) } + let!(:team_event) { create(:event, :joined, project: public_project, author: project_owner) } + + it 'includes all events', :aggregate_failures do + event_filter = EventFilter.new(EventFilter::ALL) + events = described_class.new(current_user, project_owner, event_filter, params).execute + + expect(events).to include(private_event, internal_event, public_event) + expect(events).to include(push_event, merge_event, issue_event, comment_event, wiki_event, design_event, team_event) + expect(events.size).to eq(10) + end + + it 'only includes push events', :aggregate_failures do + event_filter = EventFilter.new(EventFilter::PUSH) + events = described_class.new(current_user, project_owner, event_filter, params).execute + + expect(events).to include(push_event) + expect(events.size).to eq(1) + end + + it 'only includes merge events', :aggregate_failures do + event_filter = EventFilter.new(EventFilter::MERGED) + events = described_class.new(current_user, project_owner, event_filter, params).execute + + expect(events).to include(merge_event) + expect(events.size).to eq(1) + end + + it 'only includes issue events', :aggregate_failures do + event_filter = EventFilter.new(EventFilter::ISSUE) + events = described_class.new(current_user, project_owner, event_filter, params).execute + + expect(events).to include(issue_event) + expect(events.size).to eq(1) + end + + it 'only includes comments events', :aggregate_failures do + event_filter = EventFilter.new(EventFilter::COMMENTS) + events = described_class.new(current_user, project_owner, event_filter, params).execute + + expect(events).to include(comment_event) + expect(events.size).to eq(1) + end + + it 'only includes wiki events', :aggregate_failures do + event_filter = EventFilter.new(EventFilter::WIKI) + events = described_class.new(current_user, project_owner, event_filter, params).execute + + expect(events).to include(wiki_event) + expect(events.size).to eq(1) + end it 'only includes design events', :aggregate_failures do - events = finder.execute + event_filter = EventFilter.new(EventFilter::DESIGNS) + events = described_class.new(current_user, project_owner, event_filter, params).execute - expect(events).to include(event_a) - expect(events).to include(event_b) + expect(events).to include(design_event) + expect(events.size).to eq(1) + end + + it 'only includes team events', :aggregate_failures do + event_filter = EventFilter.new(EventFilter::TEAM) + events = described_class.new(current_user, project_owner, event_filter, params).execute + + expect(events).to include(private_event, internal_event, public_event, team_event) + expect(events.size).to eq(4) end end |