user_recent_events_finder_spec.rb 1.52 KB
Newer Older
1 2 3
require 'spec_helper'

describe UserRecentEventsFinder do
4 5 6 7 8 9 10 11
  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) }
12

13
  subject(:finder) { described_class.new(current_user, project_owner) }
14 15

  describe '#execute' do
16 17 18
    context 'when profile is public' do
      it 'returns all the events' do
        expect(finder.execute).to include(private_event, internal_event, public_event)
19
      end
20 21
    end

22 23 24 25
    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)
26 27 28 29

        expect(finder.execute).to be_empty
      end
    end
30

31
    it 'does not include the events if the user cannot read cross project' do
32
      allow(Ability).to receive(:allowed?).and_call_original
33
      expect(Ability).to receive(:allowed?).with(current_user, :read_cross_project) { false }
34

35
      expect(finder.execute).to be_empty
36
    end
37 38
  end
end