BigW Consortium Gitlab

joined_groups_finder_spec.rb 2.36 KB
Newer Older
1 2 3 4 5 6 7
require 'spec_helper'

describe JoinedGroupsFinder do
  describe '#execute' do
    let!(:profile_owner)    { create(:user) }
    let!(:profile_visitor)  { create(:user) }

Douwe Maan committed
8 9 10 11 12 13
    let!(:private_group)    { create(:group, :private) }
    let!(:private_group_2)  { create(:group, :private) }
    let!(:internal_group)   { create(:group, :internal) }
    let!(:internal_group_2) { create(:group, :internal) }
    let!(:public_group)     { create(:group, :public) }
    let!(:public_group_2)   { create(:group, :public) }
14 15
    let!(:finder) { described_class.new(profile_owner) }

Douwe Maan committed
16 17 18
    context 'without a user' do
      before do
        public_group.add_master(profile_owner)
19 20
      end

Douwe Maan committed
21 22 23 24
      it 'only shows public groups from profile owner' do
        expect(finder.execute).to eq([public_group])
      end
    end
25

Douwe Maan committed
26 27 28 29 30 31
    context "with a user" do
      before do
        private_group.add_master(profile_owner)
        internal_group.add_master(profile_owner)
        public_group.add_master(profile_owner)
      end
32

Douwe Maan committed
33 34 35 36 37 38 39 40
      context "when the profile visitor is in the private group" do
        before do
          private_group.add_developer(profile_visitor)
        end

        it 'only shows groups where both users are authorized to see' do
          expect(finder.execute(profile_visitor)).to eq([public_group, internal_group, private_group])
        end
41 42
      end

Douwe Maan committed
43
      context 'if profile visitor is in one of the private group projects' do
44 45
        before do
          project = create(:project, :private, group: private_group, name: 'B', path: 'B')
46
          project.add_user(profile_visitor, Gitlab::Access::DEVELOPER)
47 48
        end

Douwe Maan committed
49
        it 'shows group' do
Douwe Maan committed
50
          expect(finder.execute(profile_visitor)).to eq([public_group, internal_group, private_group])
Douwe Maan committed
51
        end
52
      end
Felipe Artur committed
53 54 55 56 57 58

      context 'external users' do
        before do
          profile_visitor.update_attributes(external: true)
        end

Douwe Maan committed
59 60 61 62
        context 'if not a member' do
          it "does not show internal groups" do
            expect(finder.execute(profile_visitor)).to eq([public_group])
          end
Felipe Artur committed
63 64
        end

Douwe Maan committed
65 66 67 68 69 70 71 72
        context "if authorized" do
          before do
            internal_group.add_master(profile_visitor)
          end

          it "shows internal groups if authorized" do
            expect(finder.execute(profile_visitor)).to eq([public_group, internal_group])
          end
Felipe Artur committed
73 74
        end
      end
75 76 77
    end
  end
end