diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 16:54:15 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 16:54:15 +0300 |
commit | be834a25982746ffd85252ff502df42bb88cb9d5 (patch) | |
tree | b4d6a8ba0931e12fac08f05abea33a3b8ec2c8a2 /spec/helpers/projects_helper_spec.rb | |
parent | ee925a3597f27e92f83a50937a64068109675b3d (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc32
Diffstat (limited to 'spec/helpers/projects_helper_spec.rb')
-rw-r--r-- | spec/helpers/projects_helper_spec.rb | 114 |
1 files changed, 26 insertions, 88 deletions
diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 2b345ff3ae6..f081cf225b1 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -5,16 +5,15 @@ require 'spec_helper' RSpec.describe ProjectsHelper do include ProjectForksHelper - let_it_be(:project) { create(:project) } + let_it_be_with_reload(:project) { create(:project) } + let_it_be_with_refind(:project_with_repo) { create(:project, :repository) } let_it_be(:user) { create(:user) } - describe '#project_incident_management_setting' do - let(:project) { create(:project) } - - before do - helper.instance_variable_set(:@project, project) - end + before do + helper.instance_variable_set(:@project, project) + end + describe '#project_incident_management_setting' do context 'when incident_management_setting exists' do let(:project_incident_management_setting) do create(:project_incident_management_setting, project: project) @@ -40,20 +39,14 @@ RSpec.describe ProjectsHelper do end describe '#error_tracking_setting_project_json' do - let(:project) { create(:project) } - context 'error tracking setting does not exist' do - before do - helper.instance_variable_set(:@project, project) - end - it 'returns nil' do expect(helper.error_tracking_setting_project_json).to be_nil end end context 'error tracking setting exists' do - let!(:error_tracking_setting) { create(:project_error_tracking_setting, project: project) } + let_it_be(:error_tracking_setting) { create(:project_error_tracking_setting, project: project) } context 'api_url present' do let(:json) do @@ -65,24 +58,16 @@ RSpec.describe ProjectsHelper do }.to_json end - before do - helper.instance_variable_set(:@project, project) - end - it 'returns error tracking json' do expect(helper.error_tracking_setting_project_json).to eq(json) end end context 'api_url not present' do - before do + it 'returns nil' do project.error_tracking_setting.api_url = nil project.error_tracking_setting.enabled = false - helper.instance_variable_set(:@project, project) - end - - it 'returns nil' do expect(helper.error_tracking_setting_project_json).to be_nil end end @@ -98,8 +83,7 @@ RSpec.describe ProjectsHelper do end describe "can_change_visibility_level?" do - let(:project) { create(:project) } - let(:user) { create(:project_member, :reporter, user: create(:user), project: project).user } + let_it_be(:user) { create(:project_member, :reporter, user: create(:user), project: project).user } let(:forked_project) { fork_project(project, user) } it "returns false if there are no appropriate permissions" do @@ -142,8 +126,7 @@ RSpec.describe ProjectsHelper do end describe '#can_disable_emails?' do - let(:project) { create(:project) } - let(:user) { create(:project_member, :maintainer, user: create(:user), project: project).user } + let_it_be(:user) { create(:project_member, :maintainer, user: create(:user), project: project).user } it 'returns true for the project owner' do allow(helper).to receive(:can?).with(project.owner, :set_emails_disabled, project) { true } @@ -166,11 +149,7 @@ RSpec.describe ProjectsHelper do end describe "readme_cache_key" do - let(:project) { create(:project, :repository) } - - before do - helper.instance_variable_set(:@project, project) - end + let(:project) { project_with_repo } it "returns a valid cach key" do expect(helper.send(:readme_cache_key)).to eq("#{project.full_path}-#{project.commit.id}-readme") @@ -184,8 +163,7 @@ RSpec.describe ProjectsHelper do end describe "#project_list_cache_key", :clean_gitlab_redis_shared_state do - let(:project) { create(:project, :repository) } - let(:user) { create(:user) } + let(:project) { project_with_repo } before do allow(helper).to receive(:current_user).and_return(user) @@ -249,8 +227,6 @@ RSpec.describe ProjectsHelper do describe '#load_pipeline_status' do it 'loads the pipeline status in batch' do - project = build(:project) - helper.load_pipeline_status([project]) # Skip lazy loading of the `pipeline_status` attribute pipeline_status = project.instance_variable_get('@pipeline_status') @@ -260,8 +236,6 @@ RSpec.describe ProjectsHelper do end describe '#show_no_ssh_key_message?' do - let(:user) { create(:user) } - before do allow(helper).to receive(:current_user).and_return(user) end @@ -282,8 +256,6 @@ RSpec.describe ProjectsHelper do end describe '#show_no_password_message?' do - let(:user) { create(:user) } - before do allow(helper).to receive(:current_user).and_return(user) end @@ -424,7 +396,6 @@ RSpec.describe ProjectsHelper do before do allow(helper).to receive(:current_user).and_return(user) - helper.instance_variable_set(:@project, project) end context 'when there is no current_user' do @@ -444,9 +415,6 @@ RSpec.describe ProjectsHelper do end describe '#get_project_nav_tabs' do - let_it_be(:user) { create(:user) } - let(:project) { create(:project) } - before do allow(helper).to receive(:can?) { true } end @@ -524,7 +492,14 @@ RSpec.describe ProjectsHelper do subject { helper.send(:can_view_operations_tab?, user, project) } - [:read_environment, :read_cluster, :metrics_dashboard].each do |ability| + [ + :metrics_dashboard, + :read_alert_management_alert, + :read_environment, + :read_issue, + :read_sentry_issue, + :read_cluster + ].each do |ability| it 'includes operations tab' do allow(helper).to receive(:can?).and_return(false) allow(helper).to receive(:can?).with(user, ability, project).and_return(true) @@ -536,7 +511,6 @@ RSpec.describe ProjectsHelper do describe '#show_projects' do let(:projects) do - create(:project) Project.all end @@ -561,8 +535,8 @@ RSpec.describe ProjectsHelper do end end - describe('#push_to_create_project_command') do - let(:user) { create(:user, username: 'john') } + describe '#push_to_create_project_command' do + let(:user) { build_stubbed(:user, username: 'john') } it 'returns the command to push to create project over HTTP' do allow(Gitlab::CurrentSettings.current_application_settings).to receive(:enabled_git_access_protocol) { 'http' } @@ -578,8 +552,6 @@ RSpec.describe ProjectsHelper do end describe '#any_projects?' do - let!(:project) { create(:project) } - it 'returns true when projects will be returned' do expect(helper.any_projects?(Project.all)).to eq(true) end @@ -609,7 +581,7 @@ RSpec.describe ProjectsHelper do end describe '#git_user_name' do - let(:user) { double(:user, name: 'John "A" Doe53') } + let(:user) { build_stubbed(:user, name: 'John "A" Doe53') } before do allow(helper).to receive(:current_user).and_return(user) @@ -632,8 +604,6 @@ RSpec.describe ProjectsHelper do end context 'user logged in' do - let(:user) { create(:user) } - before do allow(helper).to receive(:current_user).and_return(user) end @@ -658,7 +628,6 @@ RSpec.describe ProjectsHelper do end describe 'show_xcode_link' do - let!(:project) { create(:project) } let(:mac_ua) { 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36' } let(:ios_ua) { 'Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3' } @@ -799,7 +768,7 @@ RSpec.describe ProjectsHelper do describe '#show_auto_devops_implicitly_enabled_banner?' do using RSpec::Parameterized::TableSyntax - let(:user) { create(:user) } + let_it_be_with_reload(:project_with_auto_devops) { create(:project, :repository, :auto_devops) } let(:feature_visibilities) do { @@ -873,9 +842,9 @@ RSpec.describe ProjectsHelper do with_them do let(:project) do if project_setting.nil? - create(:project, :repository) + project_with_repo else - create(:project, :repository, :auto_devops) + project_with_auto_devops end end @@ -896,14 +865,8 @@ RSpec.describe ProjectsHelper do end describe '#can_import_members?' do - let(:project) { create(:project) } - let(:user) { create(:user) } let(:owner) { project.owner } - before do - helper.instance_variable_set(:@project, project) - 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 @@ -916,12 +879,6 @@ RSpec.describe ProjectsHelper do end describe '#metrics_external_dashboard_url' do - let(:project) { create(:project) } - - before do - helper.instance_variable_set(:@project, project) - end - context 'metrics_setting exists' do it 'returns external_dashboard_url' do metrics_setting = create(:project_metrics_setting, project: project) @@ -938,12 +895,6 @@ RSpec.describe ProjectsHelper do end describe '#grafana_integration_url' do - let(:project) { create(:project) } - - before do - helper.instance_variable_set(:@project, project) - end - subject { helper.grafana_integration_url } it { is_expected.to eq(nil) } @@ -956,12 +907,6 @@ RSpec.describe ProjectsHelper do end describe '#grafana_integration_token' do - let(:project) { create(:project) } - - before do - helper.instance_variable_set(:@project, project) - end - subject { helper.grafana_integration_masked_token } it { is_expected.to eq(nil) } @@ -974,12 +919,6 @@ RSpec.describe ProjectsHelper do end describe '#grafana_integration_enabled?' do - let(:project) { create(:project) } - - before do - helper.instance_variable_set(:@project, project) - end - subject { helper.grafana_integration_enabled? } it { is_expected.to eq(nil) } @@ -992,7 +931,6 @@ RSpec.describe ProjectsHelper do end describe '#project_license_name(project)', :request_store do - let_it_be(:project) { create(:project) } let_it_be(:repository) { project.repository } subject { project_license_name(project) } |