summaryrefslogtreecommitdiff
path: root/spec/helpers/projects_helper_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 10:34:06 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 10:34:06 +0000
commit859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch)
treed7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/helpers/projects_helper_spec.rb
parent446d496a6d000c73a304be52587cd9bbc7493136 (diff)
downloadgitlab-ce-859a6fb938bb9ee2a317c46dfa4fcc1af49608f0.tar.gz
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/helpers/projects_helper_spec.rb')
-rw-r--r--spec/helpers/projects_helper_spec.rb113
1 files changed, 81 insertions, 32 deletions
diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb
index b920e2e5600..303e3c78153 100644
--- a/spec/helpers/projects_helper_spec.rb
+++ b/spec/helpers/projects_helper_spec.rb
@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe ProjectsHelper do
include ProjectForksHelper
+ include AfterNextHelpers
let_it_be_with_reload(:project) { create(:project) }
let_it_be_with_refind(:project_with_repo) { create(:project, :repository) }
@@ -398,6 +399,45 @@ RSpec.describe ProjectsHelper do
helper.send(:get_project_nav_tabs, project, user)
end
+ context 'Security & Compliance tabs' do
+ before do
+ stub_feature_flags(secure_security_and_compliance_configuration_page_on_ce: feature_flag_enabled)
+ allow(helper).to receive(:can?).with(user, :read_security_configuration, project).and_return(can_read_security_configuration)
+ end
+
+ context 'when user cannot read security configuration' do
+ let(:can_read_security_configuration) { false }
+
+ context 'when feature flag is disabled' do
+ let(:feature_flag_enabled) { false }
+
+ it { is_expected.not_to include(:security_configuration) }
+ end
+
+ context 'when feature flag is enabled' do
+ let(:feature_flag_enabled) { true }
+
+ it { is_expected.not_to include(:security_configuration) }
+ end
+ end
+
+ context 'when user can read security configuration' do
+ let(:can_read_security_configuration) { true }
+
+ context 'when feature flag is disabled' do
+ let(:feature_flag_enabled) { false }
+
+ it { is_expected.not_to include(:security_configuration) }
+ end
+
+ context 'when feature flag is enabled' do
+ let(:feature_flag_enabled) { true }
+
+ it { is_expected.to include(:security_configuration) }
+ end
+ end
+ end
+
context 'when builds feature is enabled' do
before do
allow(project).to receive(:builds_enabled?).and_return(true)
@@ -459,6 +499,20 @@ RSpec.describe ProjectsHelper do
it { is_expected.not_to include(:confluence) }
it { is_expected.to include(:wiki) }
end
+
+ context 'learn gitlab experiment' do
+ context 'when it is enabled' do
+ before do
+ expect(helper).to receive(:learn_gitlab_experiment_enabled?).with(project).and_return(true)
+ end
+
+ it { is_expected.to include(:learn_gitlab) }
+ end
+
+ context 'when it is not enabled' do
+ it { is_expected.not_to include(:learn_gitlab) }
+ end
+ end
end
describe '#can_view_operations_tab?' do
@@ -657,31 +711,6 @@ RSpec.describe ProjectsHelper do
end
end
- describe 'link_to_filter_repo' do
- subject { helper.link_to_filter_repo }
-
- it 'generates a hardcoded link to git filter-repo' do
- result = helper.link_to_filter_repo
- doc = Nokogiri::HTML.fragment(result)
-
- expect(doc.children.size).to eq(1)
-
- link = doc.children.first
-
- aggregate_failures do
- expect(result).to be_html_safe
-
- expect(link.name).to eq('a')
- expect(link[:target]).to eq('_blank')
- expect(link[:rel]).to eq('noopener noreferrer')
- expect(link[:href]).to eq('https://github.com/newren/git-filter-repo')
- expect(link.inner_html).to eq('git filter-repo')
-
- expect(result).to be_html_safe
- end
- end
- end
-
describe '#explore_projects_tab?' do
subject { helper.explore_projects_tab? }
@@ -854,16 +883,36 @@ RSpec.describe ProjectsHelper do
end
describe '#can_import_members?' do
- let(:owner) { project.owner }
+ context 'when user is project owner' do
+ before do
+ allow(helper).to receive(:current_user) { project.owner }
+ end
- it 'returns false if user cannot admin_project_member' do
- allow(helper).to receive(:current_user) { user }
- expect(helper.can_import_members?).to eq false
+ it 'returns true for owner of project' do
+ expect(helper.can_import_members?).to eq true
+ end
end
- it 'returns true if user can admin_project_member' do
- allow(helper).to receive(:current_user) { owner }
- expect(helper.can_import_members?).to eq true
+ context 'when user is not a project owner' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:user_project_role, :can_import) do
+ :maintainer | true
+ :developer | false
+ :reporter | false
+ :guest | false
+ end
+
+ with_them do
+ before do
+ project.add_role(user, user_project_role)
+ allow(helper).to receive(:current_user) { user }
+ end
+
+ it 'resolves if the user can import members' do
+ expect(helper.can_import_members?).to eq can_import
+ end
+ end
end
end