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

41 lines
1.6 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2018-03-27 19:54:05 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe UserRecentEventsFinder do
2018-06-27 16:04:02 +05:30
let(:current_user) { create(:user) }
let(:project_owner) { 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!(: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) }
2018-03-27 19:54:05 +05:30
2018-06-27 16:04:02 +05:30
subject(:finder) { described_class.new(current_user, project_owner) }
2018-03-27 19:54:05 +05:30
describe '#execute' do
2018-11-20 20:47:30 +05:30
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-27 16:04:02 +05:30
end
2018-03-27 19:54:05 +05:30
end
2018-11-20 20:47:30 +05:30
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)
2018-03-27 19:54:05 +05:30
expect(finder.execute).to be_empty
end
end
2018-06-27 16:04:02 +05:30
2018-11-20 20:47:30 +05:30
it 'does not include the events if the user cannot read cross project' do
2019-02-15 15:39:39 +05:30
allow(Ability).to receive(:allowed?).and_call_original
2018-11-20 20:47:30 +05:30
expect(Ability).to receive(:allowed?).with(current_user, :read_cross_project) { false }
2019-02-15 15:39:39 +05:30
2018-11-20 20:47:30 +05:30
expect(finder.execute).to be_empty
2018-06-27 16:04:02 +05:30
end
2018-03-27 19:54:05 +05:30
end
end