groups_finder_spec.rb 859 Bytes
Newer Older
1 2 3 4
require 'spec_helper'

describe GroupsFinder do
  describe '#execute' do
5 6 7 8 9
    let(:user)            { create(:user) }
    let!(:private_group)  { create(:group, :private) }
    let!(:internal_group) { create(:group, :internal) }
    let!(:public_group)   { create(:group, :public) }
    let(:finder)          { described_class.new }
10 11 12 13 14 15 16 17 18 19 20

    describe 'execute' do
      describe 'without a user' do
        subject { finder.execute }

        it { is_expected.to eq([public_group]) }
      end

      describe 'with a user' do
        subject { finder.execute(user) }

Felipe Artur's avatar
Felipe Artur committed
21 22 23 24 25
        context 'normal user' do
          it { is_expected.to eq([public_group, internal_group]) }
        end

        context 'external user' do
26 27
          let(:user) { create(:user, external: true) }

Felipe Artur's avatar
Felipe Artur committed
28 29
          it { is_expected.to eq([public_group]) }
        end
30 31 32 33
      end
    end
  end
end