BigW Consortium Gitlab

project_features_apply_to_issuables_shared_examples.rb 1.29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
shared_examples 'project features apply to issuables' do |klass|
  let(:described_class) { klass }

  let(:group) { create(:group) }
  let(:user_in_group) { create(:group_member, :developer, user: create(:user), group: group ).user }
  let(:user_outside_group) { create(:user) }

  let(:project) { create(:empty_project, :public, project_args) }

  def project_args
    feature = "#{described_class.model_name.plural}_access_level".to_sym

    args = { group: group }
    args[feature] = access_level

    args
  end

  before do
    _ = issuable
    login_as(user)
    visit path
  end

  context 'public access level' do
    let(:access_level) { ProjectFeature::ENABLED }

    context 'group member' do
      let(:user) { user_in_group }

      it { expect(page).to have_content(issuable.title) }
    end

    context 'non-member' do
      let(:user) { user_outside_group }

      it { expect(page).to have_content(issuable.title) }
    end
  end

  context 'private access level' do
    let(:access_level) { ProjectFeature::PRIVATE }

    context 'group member' do
      let(:user) { user_in_group }

      it { expect(page).to have_content(issuable.title) }
    end

    context 'non-member' do
      let(:user) { user_outside_group }

      it { expect(page).not_to have_content(issuable.title) }
    end
  end
end