summaryrefslogtreecommitdiff
path: root/spec/helpers/projects_helper_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/helpers/projects_helper_spec.rb')
-rw-r--r--spec/helpers/projects_helper_spec.rb256
1 files changed, 128 insertions, 128 deletions
diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb
index 49895b0680b..5a1eed2af87 100644
--- a/spec/helpers/projects_helper_spec.rb
+++ b/spec/helpers/projects_helper_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe ProjectsHelper do
include ProjectForksHelper
@@ -28,7 +28,7 @@ describe ProjectsHelper do
expect(helper.can_change_visibility_level?(project, user)).to be_truthy
end
- it 'allows visibility level to be changed if the project is forked' do
+ it "allows visibility level to be changed if the project is forked" do
allow(helper).to receive(:can?).with(user, :change_visibility_level, project) { true }
project.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
fork_project(project)
@@ -114,11 +114,11 @@ describe ProjectsHelper do
end
it "includes a version" do
- expect(helper.project_list_cache_key(project).last).to start_with('v')
+ expect(helper.project_list_cache_key(project).last).to start_with("v")
end
- it 'includes wether or not the user can read cross project' do
- expect(helper.project_list_cache_key(project)).to include('cross-project:true')
+ it "includes wether or not the user can read cross project" do
+ expect(helper.project_list_cache_key(project)).to include("cross-project:true")
end
it "includes the pipeline status when there is a status" do
@@ -128,37 +128,37 @@ describe ProjectsHelper do
end
it "includes the user max member access" do
- expect(helper.project_list_cache_key(project)).to include('access:40')
+ expect(helper.project_list_cache_key(project)).to include("access:40")
end
end
- describe '#load_pipeline_status' do
- it 'loads the pipeline status in batch' 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')
+ pipeline_status = project.instance_variable_get("@pipeline_status")
expect(pipeline_status).to be_a(Gitlab::Cache::Ci::ProjectPipelineStatus)
end
end
- describe '#show_no_ssh_key_message?' do
+ describe "#show_no_ssh_key_message?" do
let(:user) { create(:user) }
before do
allow(helper).to receive(:current_user).and_return(user)
end
- context 'user has no keys' do
- it 'returns true' do
+ context "user has no keys" do
+ it "returns true" do
expect(helper.show_no_ssh_key_message?).to be_truthy
end
end
- context 'user has an ssh key' do
- it 'returns false' do
+ context "user has an ssh key" do
+ it "returns false" do
create(:personal_key, user: user)
expect(helper.show_no_ssh_key_message?).to be_falsey
@@ -166,37 +166,37 @@ describe ProjectsHelper do
end
end
- describe '#show_no_password_message?' do
+ describe "#show_no_password_message?" do
let(:user) { create(:user) }
before do
allow(helper).to receive(:current_user).and_return(user)
end
- context 'user has password set' do
- it 'returns false' do
+ context "user has password set" do
+ it "returns false" do
expect(helper.show_no_password_message?).to be_falsey
end
end
- context 'user has hidden the message' do
- it 'returns false' do
+ context "user has hidden the message" do
+ it "returns false" do
allow(helper).to receive(:cookies).and_return(hide_no_password_message: true)
expect(helper.show_no_password_message?).to be_falsey
end
end
- context 'user requires a password for Git' do
- it 'returns true' do
+ context "user requires a password for Git" do
+ it "returns true" do
allow(user).to receive(:require_password_creation_for_git?).and_return(true)
expect(helper.show_no_password_message?).to be_truthy
end
end
- context 'user requires a personal access token for Git' do
- it 'returns true' do
+ context "user requires a personal access token for Git" do
+ it "returns true" do
allow(user).to receive(:require_password_creation_for_git?).and_return(false)
allow(user).to receive(:require_personal_access_token_creation_for_git_auth?).and_return(true)
@@ -205,23 +205,23 @@ describe ProjectsHelper do
end
end
- describe '#link_to_set_password' do
+ describe "#link_to_set_password" do
let(:user) { create(:user, password_automatically_set: true) }
before do
allow(helper).to receive(:current_user).and_return(user)
end
- context 'password authentication is enabled for Git' do
- it 'returns link to set a password' do
+ context "password authentication is enabled for Git" do
+ it "returns link to set a password" do
stub_application_setting(password_authentication_enabled_for_git?: true)
expect(helper.link_to_set_password).to match %r{<a href="#{edit_profile_password_path}">set a password</a>}
end
end
- context 'password authentication is disabled for Git' do
- it 'returns link to create a personal access token' do
+ context "password authentication is disabled for Git" do
+ it "returns link to create a personal access token" do
stub_application_setting(password_authentication_enabled_for_git?: false)
expect(helper.link_to_set_password).to match %r{<a href="#{profile_personal_access_tokens_path}">create a personal access token</a>}
@@ -229,19 +229,19 @@ describe ProjectsHelper do
end
end
- describe '#link_to_project' do
- let(:group) { create(:group, name: 'group name with space') }
- let(:project) { create(:project, group: group, name: 'project name with space') }
+ describe "#link_to_project" do
+ let(:group) { create(:group, name: "group name with space") }
+ let(:project) { create(:project, group: group, name: "project name with space") }
subject { link_to_project(project) }
- it 'returns an HTML link to the project' do
+ it "returns an HTML link to the project" do
expect(subject).to match(%r{/#{group.full_path}/#{project.path}})
- expect(subject).to include('group name with space /')
- expect(subject).to include('project name with space')
+ expect(subject).to include("group name with space /")
+ expect(subject).to include("project name with space")
end
end
- describe '#link_to_member_avatar' do
+ describe "#link_to_member_avatar" do
let(:user) { build_stubbed(:user) }
let(:expected) { double }
@@ -249,32 +249,32 @@ describe ProjectsHelper do
expect(helper).to receive(:avatar_icon_for_user).with(user, 16).and_return(expected)
end
- it 'returns image tag for member avatar' do
- expect(helper).to receive(:image_tag).with(expected, { width: 16, class: ["avatar", "avatar-inline", "s16"], alt: "", "data-src" => anything })
+ it "returns image tag for member avatar" do
+ expect(helper).to receive(:image_tag).with(expected, {:width => 16, :class => ["avatar", "avatar-inline", "s16"], :alt => "", "data-src" => anything})
helper.link_to_member_avatar(user)
end
- it 'returns image tag with avatar class' do
- expect(helper).to receive(:image_tag).with(expected, { width: 16, class: ["avatar", "avatar-inline", "s16", "any-avatar-class"], alt: "", "data-src" => anything })
+ it "returns image tag with avatar class" do
+ expect(helper).to receive(:image_tag).with(expected, {:width => 16, :class => ["avatar", "avatar-inline", "s16", "any-avatar-class"], :alt => "", "data-src" => anything})
helper.link_to_member_avatar(user, avatar_class: "any-avatar-class")
end
end
- describe '#link_to_member' do
+ describe "#link_to_member" do
let(:group) { build_stubbed(:group) }
let(:project) { build_stubbed(:project, group: group) }
- let(:user) { build_stubbed(:user, name: '<h1>Administrator</h1>') }
+ let(:user) { build_stubbed(:user, name: "<h1>Administrator</h1>") }
- describe 'using the default options' do
- it 'returns an HTML link to the user' do
+ describe "using the default options" do
+ it "returns an HTML link to the user" do
link = helper.link_to_member(project, user)
expect(link).to match(%r{/#{user.username}})
end
- it 'HTML escapes the name of the user' do
+ it "HTML escapes the name of the user" do
link = helper.link_to_member(project, user)
expect(link).to include(ERB::Util.html_escape(user.name))
@@ -283,26 +283,26 @@ describe ProjectsHelper do
end
end
- describe 'default_clone_protocol' do
- context 'when user is not logged in and gitlab protocol is HTTP' do
- it 'returns HTTP' do
+ describe "default_clone_protocol" do
+ context "when user is not logged in and gitlab protocol is HTTP" do
+ it "returns HTTP" do
allow(helper).to receive(:current_user).and_return(nil)
- expect(helper.send(:default_clone_protocol)).to eq('http')
+ expect(helper.send(:default_clone_protocol)).to eq("http")
end
end
- context 'when user is not logged in and gitlab protocol is HTTPS' do
- it 'returns HTTPS' do
- stub_config_setting(protocol: 'https')
+ context "when user is not logged in and gitlab protocol is HTTPS" do
+ it "returns HTTPS" do
+ stub_config_setting(protocol: "https")
allow(helper).to receive(:current_user).and_return(nil)
- expect(helper.send(:default_clone_protocol)).to eq('https')
+ expect(helper.send(:default_clone_protocol)).to eq("https")
end
end
end
- describe '#last_push_event' do
+ describe "#last_push_event" do
let(:user) { double(:user, fork_of: nil) }
let(:project) { double(:project, id: 1) }
@@ -311,15 +311,15 @@ describe ProjectsHelper do
helper.instance_variable_set(:@project, project)
end
- context 'when there is no current_user' do
+ context "when there is no current_user" do
let(:user) { nil }
- it 'returns nil' do
+ it "returns nil" do
expect(helper.last_push_event).to eq(nil)
end
end
- it 'returns recent push on the current project' do
+ it "returns recent push on the current project" do
event = double(:event)
expect(user).to receive(:recent_push).with(project).and_return(event)
@@ -327,7 +327,7 @@ describe ProjectsHelper do
end
end
- describe '#get_project_nav_tabs' do
+ describe "#get_project_nav_tabs" do
let(:project) { create(:project) }
let(:user) { create(:user) }
@@ -339,7 +339,7 @@ describe ProjectsHelper do
helper.send(:get_project_nav_tabs, project, user)
end
- context 'when builds feature is enabled' do
+ context "when builds feature is enabled" do
before do
allow(project).to receive(:builds_enabled?).and_return(true)
end
@@ -349,18 +349,18 @@ describe ProjectsHelper do
end
end
- context 'when builds feature is disabled' do
+ context "when builds feature is disabled" do
before do
allow(project).to receive(:builds_enabled?).and_return(false)
end
- context 'when user has access to builds' do
+ context "when user has access to builds" do
it "does include pipelines tab" do
is_expected.to include(:pipelines)
end
end
- context 'when user does not have access to builds' do
+ context "when user does not have access to builds" do
before do
allow(helper).to receive(:can?) { false }
end
@@ -371,138 +371,138 @@ describe ProjectsHelper do
end
end
- context 'when project has external wiki' do
- it 'includes external wiki tab' do
- project.create_external_wiki_service(active: true, properties: { 'external_wiki_url' => 'https://gitlab.com' })
+ context "when project has external wiki" do
+ it "includes external wiki tab" do
+ project.create_external_wiki_service(active: true, properties: {"external_wiki_url" => "https://gitlab.com"})
is_expected.to include(:external_wiki)
end
end
- context 'when project does not have external wiki' do
- it 'does not include external wiki tab' do
+ context "when project does not have external wiki" do
+ it "does not include external wiki tab" do
expect(project.external_wiki).to be_nil
is_expected.not_to include(:external_wiki)
end
end
end
- describe '#show_projects' do
+ describe "#show_projects" do
let(:projects) do
create(:project)
Project.all
end
- it 'returns true when there are projects' do
+ it "returns true when there are projects" do
expect(helper.show_projects?(projects, {})).to eq(true)
end
- it 'returns true when there are no projects but a name is given' do
- expect(helper.show_projects?(Project.none, name: 'foo')).to eq(true)
+ it "returns true when there are no projects but a name is given" do
+ expect(helper.show_projects?(Project.none, name: "foo")).to eq(true)
end
- it 'returns true when there are no projects but personal is present' do
- expect(helper.show_projects?(Project.none, personal: 'true')).to eq(true)
+ it "returns true when there are no projects but personal is present" do
+ expect(helper.show_projects?(Project.none, personal: "true")).to eq(true)
end
- it 'returns false when there are no projects and there is no name' do
+ it "returns false when there are no projects and there is no name" do
expect(helper.show_projects?(Project.none, {})).to eq(false)
end
end
- describe('#push_to_create_project_command') do
- let(:user) { create(:user, username: 'john') }
+ describe("#push_to_create_project_command") do
+ let(:user) { create(: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' }
+ 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" }
- expect(helper.push_to_create_project_command(user)).to eq('git push --set-upstream http://test.host/john/$(git rev-parse --show-toplevel | xargs basename).git $(git rev-parse --abbrev-ref HEAD)')
+ expect(helper.push_to_create_project_command(user)).to eq("git push --set-upstream http://test.host/john/$(git rev-parse --show-toplevel | xargs basename).git $(git rev-parse --abbrev-ref HEAD)")
end
- it 'returns the command to push to create project over SSH' do
- allow(Gitlab::CurrentSettings.current_application_settings).to receive(:enabled_git_access_protocol) { 'ssh' }
+ it "returns the command to push to create project over SSH" do
+ allow(Gitlab::CurrentSettings.current_application_settings).to receive(:enabled_git_access_protocol) { "ssh" }
- expect(helper.push_to_create_project_command(user)).to eq('git push --set-upstream git@localhost:john/$(git rev-parse --show-toplevel | xargs basename).git $(git rev-parse --abbrev-ref HEAD)')
+ expect(helper.push_to_create_project_command(user)).to eq("git push --set-upstream git@localhost:john/$(git rev-parse --show-toplevel | xargs basename).git $(git rev-parse --abbrev-ref HEAD)")
end
end
- describe '#any_projects?' do
+ describe "#any_projects?" do
let!(:project) { create(:project) }
- it 'returns true when projects will be returned' do
+ it "returns true when projects will be returned" do
expect(helper.any_projects?(Project.all)).to eq(true)
end
- it 'returns false when no projects will be returned' do
+ it "returns false when no projects will be returned" do
expect(helper.any_projects?(Project.none)).to eq(false)
end
- it 'returns true when using a non-empty Array' do
+ it "returns true when using a non-empty Array" do
expect(helper.any_projects?([project])).to eq(true)
end
- it 'returns false when using an empty Array' do
+ it "returns false when using an empty Array" do
expect(helper.any_projects?([])).to eq(false)
end
- it 'only executes a single query when a LIMIT is applied' do
+ it "only executes a single query when a LIMIT is applied" do
relation = Project.limit(1)
- recorder = ActiveRecord::QueryRecorder.new do
+ recorder = ActiveRecord::QueryRecorder.new {
2.times do
helper.any_projects?(relation)
end
- end
+ }
expect(recorder.count).to eq(1)
end
end
- describe '#git_user_name' do
+ describe "#git_user_name" do
let(:user) { double(:user, name: 'John "A" Doe53') }
before do
allow(helper).to receive(:current_user).and_return(user)
end
- it 'parses quotes in name' do
+ it "parses quotes in name" do
expect(helper.send(:git_user_name)).to eq('John \"A\" Doe53')
end
end
- describe 'show_xcode_link' do
+ 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' }
+ 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" }
- context 'when the repository is xcode compatible' do
+ context "when the repository is xcode compatible" do
before do
allow(project.repository).to receive(:xcode_project?).and_return(true)
end
- it 'returns false if the visitor is not using macos' do
+ it "returns false if the visitor is not using macos" do
allow(helper).to receive(:browser).and_return(Browser.new(ios_ua))
expect(helper.show_xcode_link?(project)).to eq(false)
end
- it 'returns true if the visitor is using macos' do
+ it "returns true if the visitor is using macos" do
allow(helper).to receive(:browser).and_return(Browser.new(mac_ua))
expect(helper.show_xcode_link?(project)).to eq(true)
end
end
- context 'when the repository is not xcode compatible' do
+ context "when the repository is not xcode compatible" do
before do
allow(project.repository).to receive(:xcode_project?).and_return(false)
end
- it 'returns false if the visitor is not using macos' do
+ it "returns false if the visitor is not using macos" do
allow(helper).to receive(:browser).and_return(Browser.new(ios_ua))
expect(helper.show_xcode_link?(project)).to eq(false)
end
- it 'returns false if the visitor is using macos' do
+ it "returns false if the visitor is using macos" do
allow(helper).to receive(:browser).and_return(Browser.new(mac_ua))
expect(helper.show_xcode_link?(project)).to eq(false)
@@ -510,10 +510,10 @@ describe ProjectsHelper do
end
end
- describe 'link_to_bfg' do
+ describe "link_to_bfg" do
subject { helper.link_to_bfg }
- it 'generates a hardcoded link to the BFG Repo-Cleaner' do
+ it "generates a hardcoded link to the BFG Repo-Cleaner" do
result = helper.link_to_bfg
doc = Nokogiri::HTML.fragment(result)
@@ -524,18 +524,18 @@ describe ProjectsHelper do
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://rtyley.github.io/bfg-repo-cleaner/')
- expect(link.inner_html).to eq('BFG')
+ 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://rtyley.github.io/bfg-repo-cleaner/")
+ expect(link.inner_html).to eq("BFG")
expect(result).to be_html_safe
end
end
end
- describe '#explore_projects_tab?' do
+ describe "#explore_projects_tab?" do
subject { helper.explore_projects_tab? }
it 'returns true when on the "All" tab under "Explore projects"' do
@@ -563,89 +563,89 @@ describe ProjectsHelper do
end
end
- describe '#show_merge_request_count' do
- context 'when the feature flag is enabled' do
+ describe "#show_merge_request_count" do
+ context "when the feature flag is enabled" do
before do
stub_feature_flags(project_list_show_mr_count: true)
end
- it 'returns true if compact mode is disabled' do
+ it "returns true if compact mode is disabled" do
expect(helper.show_merge_request_count?).to be_truthy
end
- it 'returns false if compact mode is enabled' do
+ it "returns false if compact mode is enabled" do
expect(helper.show_merge_request_count?(compact_mode: true)).to be_falsey
end
end
- context 'when the feature flag is disabled' do
+ context "when the feature flag is disabled" do
before do
stub_feature_flags(project_list_show_mr_count: false)
end
- it 'always returns false' do
+ it "always returns false" do
expect(helper.show_merge_request_count?(disabled: false)).to be_falsy
expect(helper.show_merge_request_count?(disabled: true)).to be_falsy
end
end
- context 'disabled flag' do
+ context "disabled flag" do
before do
stub_feature_flags(project_list_show_mr_count: true)
end
- it 'returns false if disabled flag is true' do
+ it "returns false if disabled flag is true" do
expect(helper.show_merge_request_count?(disabled: true)).to be_falsey
end
- it 'returns true if disabled flag is false' do
+ it "returns true if disabled flag is false" do
expect(helper.show_merge_request_count?).to be_truthy
end
end
end
- describe '#show_issue_count?' do
- context 'when the feature flag is enabled' do
+ describe "#show_issue_count?" do
+ context "when the feature flag is enabled" do
before do
stub_feature_flags(project_list_show_issue_count: true)
end
- it 'returns true if compact mode is disabled' do
+ it "returns true if compact mode is disabled" do
expect(helper.show_issue_count?).to be_truthy
end
- it 'returns false if compact mode is enabled' do
+ it "returns false if compact mode is enabled" do
expect(helper.show_issue_count?(compact_mode: true)).to be_falsey
end
end
- context 'when the feature flag is disabled' do
+ context "when the feature flag is disabled" do
before do
stub_feature_flags(project_list_show_issue_count: false)
end
- it 'always returns false' do
+ it "always returns false" do
expect(helper.show_issue_count?(disabled: false)).to be_falsy
expect(helper.show_issue_count?(disabled: true)).to be_falsy
end
end
- context 'disabled flag' do
+ context "disabled flag" do
before do
stub_feature_flags(project_list_show_issue_count: true)
end
- it 'returns false if disabled flag is true' do
+ it "returns false if disabled flag is true" do
expect(helper.show_issue_count?(disabled: true)).to be_falsey
end
- it 'returns true if disabled flag is false' do
+ it "returns true if disabled flag is false" do
expect(helper.show_issue_count?).to be_truthy
end
end
end
- describe '#show_auto_devops_implicitly_enabled_banner?' do
+ describe "#show_auto_devops_implicitly_enabled_banner?" do
using RSpec::Parameterized::TableSyntax
let(:user) { create(:user) }
@@ -653,7 +653,7 @@ describe ProjectsHelper do
let(:feature_visibilities) do
{
enabled: ProjectFeature::ENABLED,
- disabled: ProjectFeature::DISABLED
+ disabled: ProjectFeature::DISABLED,
}
end