debian-mirror-gitlab/spec/finders/events_finder_spec.rb

116 lines
5 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe EventsFinder do
2020-04-22 19:07:51 +05:30
let_it_be(:user) { create(:user) }
2020-07-02 01:45:43 +05:30
let(:private_user) { create(:user, private_profile: true) }
2017-09-10 17:25:29 +05:30
let(:other_user) { create(:user) }
2020-03-13 15:44:24 +05:30
2017-09-10 17:25:29 +05:30
let(:project1) { create(:project, :private, creator_id: user.id, namespace: user.namespace) }
let(:project2) { create(:project, :private, creator_id: user.id, namespace: user.namespace) }
2020-03-13 15:44:24 +05:30
2017-09-10 17:25:29 +05:30
let(:closed_issue) { create(:closed_issue, project: project1, author: user) }
let(:opened_merge_request) { create(:merge_request, source_project: project2, author: user) }
2020-06-23 00:09:42 +05:30
let!(:closed_issue_event) { create(:event, :closed, project: project1, author: user, target: closed_issue, created_at: Date.new(2016, 12, 30)) }
let!(:opened_merge_request_event) { create(:event, :created, project: project2, author: user, target: opened_merge_request, created_at: Date.new(2017, 1, 31)) }
2017-09-10 17:25:29 +05:30
let(:closed_issue2) { create(:closed_issue, project: project1, author: user) }
let(:opened_merge_request2) { create(:merge_request, source_project: project2, author: user) }
2020-06-23 00:09:42 +05:30
let!(:closed_issue_event2) { create(:event, :closed, project: project1, author: user, target: closed_issue, created_at: Date.new(2016, 2, 2)) }
let!(:opened_merge_request_event2) { create(:event, :created, project: project2, author: user, target: opened_merge_request, created_at: Date.new(2017, 2, 2)) }
2020-03-13 15:44:24 +05:30
let(:opened_merge_request3) { create(:merge_request, source_project: project1, author: other_user) }
2020-06-23 00:09:42 +05:30
let!(:other_developer_event) { create(:event, :created, project: project1, author: other_user, target: opened_merge_request3 ) }
2017-09-10 17:25:29 +05:30
2020-04-22 19:07:51 +05:30
let_it_be(:public_project) { create(:project, :public, creator_id: user.id, namespace: user.namespace) }
2021-09-30 23:02:18 +05:30
2019-02-15 15:39:39 +05:30
let(:confidential_issue) { create(:closed_issue, confidential: true, project: public_project, author: user) }
2020-06-23 00:09:42 +05:30
let!(:confidential_event) { create(:event, :closed, project: public_project, author: user, target: confidential_issue) }
2019-02-15 15:39:39 +05:30
2017-09-10 17:25:29 +05:30
context 'when targeting a user' do
it 'returns events between specified dates filtered on action and type' do
events = described_class.new(source: user, current_user: user, action: 'created', target_type: 'merge_request', after: Date.new(2017, 1, 1), before: Date.new(2017, 2, 1)).execute
expect(events).to eq([opened_merge_request_event])
end
it 'does not return events the current_user does not have access to' do
events = described_class.new(source: user, current_user: other_user).execute
expect(events).not_to include(opened_merge_request_event)
end
2018-03-27 19:54:05 +05:30
2019-02-15 15:39:39 +05:30
it 'does not include events on confidential issues the user does not have access to' do
events = described_class.new(source: user, current_user: other_user).execute
expect(events).not_to include(confidential_event)
end
it 'includes confidential events user has access to' do
public_project.add_developer(other_user)
events = described_class.new(source: user, current_user: other_user).execute
expect(events).to include(confidential_event)
end
2018-03-27 19:54:05 +05:30
it 'returns nothing when the current user cannot read cross project' do
expect(Ability).to receive(:allowed?).with(user, :read_cross_project) { false }
events = described_class.new(source: user, current_user: user).execute
expect(events).to be_empty
end
2020-07-02 01:45:43 +05:30
it 'returns nothing when the target profile is private' do
events = described_class.new(source: private_user, current_user: other_user).execute
expect(events).to be_empty
end
2017-09-10 17:25:29 +05:30
end
2020-07-28 23:09:34 +05:30
describe 'wiki events' do
2020-04-22 19:07:51 +05:30
let_it_be(:events) { create_list(:wiki_page_event, 3, project: public_project) }
subject(:finder) { described_class.new(source: public_project, target_type: 'wiki', current_user: user) }
2020-07-28 23:09:34 +05:30
it 'can find the wiki events' do
expect(finder.execute).to match_array(events)
2020-04-22 19:07:51 +05:30
end
end
2020-03-13 15:44:24 +05:30
context 'dashboard events' do
before do
project1.add_developer(other_user)
end
context 'scope is `all`' do
it 'includes activity of other users' do
events = described_class.new(source: user, current_user: user, scope: 'all').execute
expect(events).to include(other_developer_event)
end
end
context 'scope is not `all`' do
it 'does not include activity of other users' do
events = described_class.new(source: user, current_user: user, scope: '').execute
expect(events).not_to include(other_developer_event)
end
end
end
2017-09-10 17:25:29 +05:30
context 'when targeting a project' do
it 'returns project events between specified dates filtered on action and type' do
events = described_class.new(source: project1, current_user: user, action: 'closed', target_type: 'issue', after: Date.new(2016, 12, 1), before: Date.new(2017, 1, 1)).execute
expect(events).to eq([closed_issue_event])
end
it 'does not return events the current_user does not have access to' do
events = described_class.new(source: project2, current_user: other_user).execute
expect(events).to be_empty
end
end
end