2013-10-08 10:21:40 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ProjectsHelper do
|
2018-01-22 16:33:54 -05:00
|
|
|
include ProjectForksHelper
|
|
|
|
|
2014-12-31 08:07:48 -05:00
|
|
|
describe "#project_status_css_class" do
|
|
|
|
it "returns appropriate class" do
|
2018-06-05 21:09:58 -04:00
|
|
|
expect(project_status_css_class("started")).to eq("table-active")
|
|
|
|
expect(project_status_css_class("failed")).to eq("table-danger")
|
|
|
|
expect(project_status_css_class("finished")).to eq("table-success")
|
2014-12-31 08:07:48 -05:00
|
|
|
end
|
|
|
|
end
|
2015-07-06 08:38:43 -04:00
|
|
|
|
|
|
|
describe "can_change_visibility_level?" do
|
2018-01-22 16:33:54 -05:00
|
|
|
let(:project) { create(:project) }
|
2016-09-19 14:28:41 -04:00
|
|
|
let(:user) { create(:project_member, :reporter, user: create(:user), project: project).user }
|
2018-01-22 16:33:54 -05:00
|
|
|
let(:forked_project) { fork_project(project, user) }
|
2015-07-06 08:38:43 -04:00
|
|
|
|
2015-07-24 02:52:21 -04:00
|
|
|
it "returns false if there are no appropriate permissions" do
|
2015-07-06 08:38:43 -04:00
|
|
|
allow(helper).to receive(:can?) { false }
|
|
|
|
|
|
|
|
expect(helper.can_change_visibility_level?(project, user)).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true if there are permissions and it is not fork" do
|
|
|
|
allow(helper).to receive(:can?) { true }
|
|
|
|
|
|
|
|
expect(helper.can_change_visibility_level?(project, user)).to be_truthy
|
|
|
|
end
|
|
|
|
|
2018-01-22 16:33:54 -05:00
|
|
|
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 }
|
2018-01-22 17:01:48 -05:00
|
|
|
project.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
|
2018-01-22 16:33:54 -05:00
|
|
|
fork_project(project)
|
|
|
|
|
|
|
|
expect(helper.can_change_visibility_level?(project, user)).to be_truthy
|
|
|
|
end
|
|
|
|
|
2015-07-06 08:38:43 -04:00
|
|
|
context "forks" do
|
|
|
|
it "returns false if there are permissions and origin project is PRIVATE" do
|
|
|
|
allow(helper).to receive(:can?) { true }
|
|
|
|
|
2018-01-22 17:01:48 -05:00
|
|
|
project.update(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
|
2015-07-06 08:38:43 -04:00
|
|
|
|
2018-01-22 16:33:54 -05:00
|
|
|
expect(helper.can_change_visibility_level?(forked_project, user)).to be_falsey
|
2015-07-06 08:38:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true if there are permissions and origin project is INTERNAL" do
|
|
|
|
allow(helper).to receive(:can?) { true }
|
|
|
|
|
2018-01-22 17:01:48 -05:00
|
|
|
project.update(visibility_level: Gitlab::VisibilityLevel::INTERNAL)
|
2015-07-06 08:38:43 -04:00
|
|
|
|
2018-01-22 16:33:54 -05:00
|
|
|
expect(helper.can_change_visibility_level?(forked_project, user)).to be_truthy
|
2015-07-06 08:38:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-07-24 02:52:21 -04:00
|
|
|
|
|
|
|
describe "readme_cache_key" do
|
2017-08-01 14:51:52 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
2015-07-24 02:52:21 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
helper.instance_variable_set(:@project, project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a valid cach key" do
|
2017-07-20 05:34:09 -04:00
|
|
|
expect(helper.send(:readme_cache_key)).to eq("#{project.full_path}-#{project.commit.id}-readme")
|
2015-07-24 02:52:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a valid cache key if HEAD does not exist" do
|
|
|
|
allow(project).to receive(:commit) { nil }
|
|
|
|
|
2017-07-20 05:34:09 -04:00
|
|
|
expect(helper.send(:readme_cache_key)).to eq("#{project.full_path}-nil-readme")
|
2015-07-24 02:52:21 -04:00
|
|
|
end
|
|
|
|
end
|
2017-03-16 05:53:48 -04:00
|
|
|
|
2017-10-03 04:35:01 -04:00
|
|
|
describe "#project_list_cache_key", :clean_gitlab_redis_shared_state do
|
2017-08-01 14:51:52 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
2017-12-11 09:21:06 -05:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
|
|
|
allow(helper).to receive(:can?).with(user, :read_cross_project) { true }
|
2018-07-06 03:51:31 -04:00
|
|
|
allow(user).to receive(:max_member_access_for_project).and_return(40)
|
2017-12-11 09:21:06 -05:00
|
|
|
end
|
2017-03-16 05:53:48 -04:00
|
|
|
|
2017-05-12 11:26:01 -04:00
|
|
|
it "includes the route" do
|
|
|
|
expect(helper.project_list_cache_key(project)).to include(project.route.cache_key)
|
2017-05-12 06:33:26 -04:00
|
|
|
end
|
|
|
|
|
2017-03-16 05:53:48 -04:00
|
|
|
it "includes the project" do
|
|
|
|
expect(helper.project_list_cache_key(project)).to include(project.cache_key)
|
|
|
|
end
|
|
|
|
|
2018-06-13 12:57:18 -04:00
|
|
|
it "includes the last activity date" do
|
|
|
|
expect(helper.project_list_cache_key(project)).to include(project.last_activity_date)
|
|
|
|
end
|
|
|
|
|
2017-03-16 05:53:48 -04:00
|
|
|
it "includes the controller name" do
|
|
|
|
expect(helper.controller).to receive(:controller_name).and_return("testcontroller")
|
|
|
|
|
|
|
|
expect(helper.project_list_cache_key(project)).to include("testcontroller")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes the controller action" do
|
|
|
|
expect(helper.controller).to receive(:action_name).and_return("testaction")
|
|
|
|
|
|
|
|
expect(helper.project_list_cache_key(project)).to include("testaction")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes the application settings" do
|
|
|
|
settings = Gitlab::CurrentSettings.current_application_settings
|
|
|
|
|
|
|
|
expect(helper.project_list_cache_key(project)).to include(settings.cache_key)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes a version" do
|
2017-01-02 20:55:26 -05:00
|
|
|
expect(helper.project_list_cache_key(project).last).to start_with('v')
|
2017-03-16 05:53:48 -04:00
|
|
|
end
|
|
|
|
|
2017-12-11 09:21:06 -05:00
|
|
|
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
|
|
|
|
|
2017-03-16 05:53:48 -04:00
|
|
|
it "includes the pipeline status when there is a status" do
|
|
|
|
create(:ci_pipeline, :success, project: project, sha: project.commit.sha)
|
|
|
|
|
|
|
|
expect(helper.project_list_cache_key(project)).to include("pipeline-status/#{project.commit.sha}-success")
|
|
|
|
end
|
2018-07-06 03:51:31 -04:00
|
|
|
|
|
|
|
it "includes the user max member access" do
|
|
|
|
expect(helper.project_list_cache_key(project)).to include('access:40')
|
|
|
|
end
|
2017-03-16 05:53:48 -04:00
|
|
|
end
|
2015-10-12 11:22:22 -04:00
|
|
|
|
2017-04-26 08:04:22 -04:00
|
|
|
describe '#load_pipeline_status' do
|
|
|
|
it 'loads the pipeline status in batch' do
|
2017-08-02 15:55:11 -04:00
|
|
|
project = build(:project)
|
2017-04-26 08:04:22 -04:00
|
|
|
|
|
|
|
helper.load_pipeline_status([project])
|
|
|
|
# Skip lazy loading of the `pipeline_status` attribute
|
|
|
|
pipeline_status = project.instance_variable_get('@pipeline_status')
|
|
|
|
|
|
|
|
expect(pipeline_status).to be_a(Gitlab::Cache::Ci::ProjectPipelineStatus)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-12 12:13:22 -04:00
|
|
|
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
|
|
|
|
expect(helper.show_no_ssh_key_message?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
expect(helper.show_no_password_message?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-23 08:16:14 -05:00
|
|
|
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
|
2017-06-12 12:13:22 -04:00
|
|
|
|
2017-11-23 08:16:14 -05:00
|
|
|
context 'user requires a password for Git' do
|
2017-06-12 12:13:22 -04:00
|
|
|
it 'returns true' do
|
2017-11-23 08:16:14 -05:00
|
|
|
allow(user).to receive(:require_password_creation_for_git?).and_return(true)
|
|
|
|
|
2017-06-12 12:13:22 -04:00
|
|
|
expect(helper.show_no_password_message?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-23 08:16:14 -05:00
|
|
|
context 'user requires a personal access token for Git' do
|
2017-06-12 12:13:22 -04:00
|
|
|
it 'returns true' do
|
2017-11-23 08:16:14 -05:00
|
|
|
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)
|
2017-06-12 12:13:22 -04:00
|
|
|
|
|
|
|
expect(helper.show_no_password_message?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#link_to_set_password' do
|
2017-11-23 08:16:14 -05:00
|
|
|
let(:user) { create(:user, password_automatically_set: true) }
|
|
|
|
|
2017-06-12 12:13:22 -04:00
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
2017-11-23 08:16:14 -05:00
|
|
|
context 'password authentication is enabled for Git' do
|
2017-06-12 12:13:22 -04:00
|
|
|
it 'returns link to set a password' do
|
2017-11-23 08:16:14 -05:00
|
|
|
stub_application_setting(password_authentication_enabled_for_git?: true)
|
|
|
|
|
2017-06-12 12:13:22 -04:00
|
|
|
expect(helper.link_to_set_password).to match %r{<a href="#{edit_profile_password_path}">set a password</a>}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-23 08:16:14 -05:00
|
|
|
context 'password authentication is disabled for Git' do
|
2017-06-12 12:13:22 -04:00
|
|
|
it 'returns link to create a personal access token' do
|
2017-11-23 08:16:14 -05:00
|
|
|
stub_application_setting(password_authentication_enabled_for_git?: false)
|
2017-06-12 12:13:22 -04:00
|
|
|
|
|
|
|
expect(helper.link_to_set_password).to match %r{<a href="#{profile_personal_access_tokens_path}">create a personal access token</a>}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-14 00:07:35 -05:00
|
|
|
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
|
|
|
|
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')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-31 17:43:13 -04:00
|
|
|
describe '#link_to_member_avatar' do
|
2017-09-05 16:17:53 -04:00
|
|
|
let(:user) { build_stubbed(:user) }
|
2017-09-06 12:26:01 -04:00
|
|
|
let(:expected) { double }
|
2017-08-31 17:43:13 -04:00
|
|
|
|
2017-09-07 06:27:23 -04:00
|
|
|
before do
|
2018-02-09 05:43:12 -05:00
|
|
|
expect(helper).to receive(:avatar_icon_for_user).with(user, 16).and_return(expected)
|
2017-09-07 06:27:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns image tag for member avatar' do
|
2017-09-20 12:18:10 -04:00
|
|
|
expect(helper).to receive(:image_tag).with(expected, { width: 16, class: ["avatar", "avatar-inline", "s16"], alt: "", "data-src" => anything })
|
2017-09-05 16:17:53 -04:00
|
|
|
|
|
|
|
helper.link_to_member_avatar(user)
|
2017-08-31 17:43:13 -04:00
|
|
|
end
|
2017-09-06 12:26:01 -04:00
|
|
|
|
|
|
|
it 'returns image tag with avatar class' do
|
2017-09-20 12:18:10 -04:00
|
|
|
expect(helper).to receive(:image_tag).with(expected, { width: 16, class: ["avatar", "avatar-inline", "s16", "any-avatar-class"], alt: "", "data-src" => anything })
|
2017-09-06 12:26:01 -04:00
|
|
|
|
|
|
|
helper.link_to_member_avatar(user, avatar_class: "any-avatar-class")
|
|
|
|
end
|
2017-08-31 17:43:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#link_to_member' do
|
2017-09-05 16:17:53 -04:00
|
|
|
let(:group) { build_stubbed(:group) }
|
|
|
|
let(:project) { build_stubbed(:project, group: group) }
|
2018-06-15 04:44:59 -04:00
|
|
|
let(:user) { build_stubbed(:user, name: '<h1>Administrator</h1>') }
|
2015-10-12 11:22:22 -04:00
|
|
|
|
|
|
|
describe 'using the default options' do
|
|
|
|
it 'returns an HTML link to the user' do
|
|
|
|
link = helper.link_to_member(project, user)
|
|
|
|
|
2016-10-06 08:14:24 -04:00
|
|
|
expect(link).to match(%r{/#{user.username}})
|
2015-10-12 11:22:22 -04:00
|
|
|
end
|
2018-06-15 04:44:59 -04:00
|
|
|
|
|
|
|
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))
|
|
|
|
expect(link).not_to include(user.name)
|
|
|
|
end
|
2015-10-12 11:22:22 -04:00
|
|
|
end
|
|
|
|
end
|
2016-03-19 15:30:00 -04:00
|
|
|
|
|
|
|
describe 'default_clone_protocol' do
|
2016-05-04 17:05:16 -04:00
|
|
|
context 'when user is not logged in and gitlab protocol is HTTP' do
|
2016-03-19 15:30:00 -04:00
|
|
|
it 'returns HTTP' do
|
2016-05-04 17:05:16 -04:00
|
|
|
allow(helper).to receive(:current_user).and_return(nil)
|
2016-03-19 15:30:00 -04:00
|
|
|
|
|
|
|
expect(helper.send(:default_clone_protocol)).to eq('http')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-04 17:05:16 -04:00
|
|
|
context 'when user is not logged in and gitlab protocol is HTTPS' do
|
2016-03-19 15:30:00 -04:00
|
|
|
it 'returns HTTPS' do
|
2016-05-04 17:05:16 -04:00
|
|
|
stub_config_setting(protocol: 'https')
|
|
|
|
allow(helper).to receive(:current_user).and_return(nil)
|
2016-03-19 15:30:00 -04:00
|
|
|
|
|
|
|
expect(helper.send(:default_clone_protocol)).to eq('https')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-04-22 09:03:54 -04:00
|
|
|
|
2016-08-24 07:13:26 -04:00
|
|
|
describe '#last_push_event' do
|
|
|
|
let(:user) { double(:user, fork_of: nil) }
|
|
|
|
let(:project) { double(:project, id: 1) }
|
|
|
|
|
|
|
|
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
|
|
|
|
let(:user) { nil }
|
|
|
|
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(helper.last_push_event).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns recent push on the current project' do
|
|
|
|
event = double(:event)
|
2017-09-01 06:50:14 -04:00
|
|
|
expect(user).to receive(:recent_push).with(project).and_return(event)
|
2016-08-24 07:13:26 -04:00
|
|
|
|
|
|
|
expect(helper.last_push_event).to eq(event)
|
|
|
|
end
|
|
|
|
end
|
2016-09-02 11:30:54 -04:00
|
|
|
|
2017-06-07 06:32:16 -04:00
|
|
|
describe '#get_project_nav_tabs' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2017-06-07 06:32:16 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:can?) { true }
|
|
|
|
end
|
|
|
|
|
|
|
|
subject do
|
|
|
|
helper.send(:get_project_nav_tabs, project, user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when builds feature is enabled' do
|
|
|
|
before do
|
|
|
|
allow(project).to receive(:builds_enabled?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does include pipelines tab" do
|
|
|
|
is_expected.to include(:pipelines)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when builds feature is disabled' do
|
|
|
|
before do
|
|
|
|
allow(project).to receive(:builds_enabled?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "do not include pipelines tab" do
|
|
|
|
is_expected.not_to include(:pipelines)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-04 09:40:33 -04:00
|
|
|
|
2017-09-21 06:03:14 -04:00
|
|
|
describe '#show_projects' do
|
2017-08-04 09:40:33 -04:00
|
|
|
let(:projects) do
|
|
|
|
create(:project)
|
|
|
|
Project.all
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true when there are projects' do
|
2017-09-21 06:03:14 -04:00
|
|
|
expect(helper.show_projects?(projects, {})).to eq(true)
|
2017-08-04 09:40:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true when there are no projects but a name is given' do
|
2017-09-21 06:03:14 -04:00
|
|
|
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)
|
2017-08-04 09:40:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when there are no projects and there is no name' do
|
2017-09-21 06:03:14 -04:00
|
|
|
expect(helper.show_projects?(Project.none, {})).to eq(false)
|
2017-08-04 09:40:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-23 04:00:19 -05:00
|
|
|
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' }
|
|
|
|
|
|
|
|
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' }
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-08-04 09:40:33 -04:00
|
|
|
describe '#any_projects?' do
|
2017-08-15 06:33:07 -04:00
|
|
|
let!(:project) { create(:project) }
|
2017-08-04 09:40:33 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
expect(helper.any_projects?(Project.none)).to eq(false)
|
|
|
|
end
|
|
|
|
|
2017-08-15 06:33:07 -04:00
|
|
|
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
|
|
|
|
expect(helper.any_projects?([])).to eq(false)
|
|
|
|
end
|
|
|
|
|
2017-08-04 09:40:33 -04:00
|
|
|
it 'only executes a single query when a LIMIT is applied' do
|
|
|
|
relation = Project.limit(1)
|
|
|
|
recorder = ActiveRecord::QueryRecorder.new do
|
|
|
|
2.times do
|
|
|
|
helper.any_projects?(relation)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(recorder.count).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
2017-09-13 08:39:50 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
expect(helper.send(:git_user_name)).to eq('John \"A\" Doe53')
|
|
|
|
end
|
|
|
|
end
|
2018-06-05 06:10:34 -04:00
|
|
|
|
|
|
|
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' }
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
before do
|
|
|
|
allow(project.repository).to receive(:xcode_project?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
allow(helper).to receive(:browser).and_return(Browser.new(mac_ua))
|
|
|
|
|
|
|
|
expect(helper.show_xcode_link?(project)).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-09-04 09:42:23 -04:00
|
|
|
|
2018-11-19 10:03:58 -05:00
|
|
|
describe 'link_to_bfg' do
|
|
|
|
subject { helper.link_to_bfg }
|
|
|
|
|
|
|
|
it 'generates a hardcoded link to the BFG Repo-Cleaner' do
|
|
|
|
result = helper.link_to_bfg
|
|
|
|
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://rtyley.github.io/bfg-repo-cleaner/')
|
|
|
|
expect(link.inner_html).to eq('BFG')
|
|
|
|
|
|
|
|
expect(result).to be_html_safe
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-04 09:42:23 -04:00
|
|
|
describe '#legacy_render_context' do
|
|
|
|
it 'returns the redcarpet engine' do
|
|
|
|
params = { legacy_render: '1' }
|
|
|
|
|
|
|
|
expect(helper.legacy_render_context(params)).to include(markdown_engine: :redcarpet)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nothing' do
|
|
|
|
expect(helper.legacy_render_context({})).to be_empty
|
|
|
|
end
|
|
|
|
end
|
2018-12-19 14:37:08 -05:00
|
|
|
|
|
|
|
describe '#explore_projects_tab?' do
|
|
|
|
subject { helper.explore_projects_tab? }
|
|
|
|
|
|
|
|
it 'returns true when on the "All" tab under "Explore projects"' do
|
|
|
|
allow(@request).to receive(:path) { explore_projects_path }
|
|
|
|
|
|
|
|
expect(subject).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true when on the "Trending" tab under "Explore projects"' do
|
|
|
|
allow(@request).to receive(:path) { trending_explore_projects_path }
|
|
|
|
|
|
|
|
expect(subject).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true when on the "Starred" tab under "Explore projects"' do
|
|
|
|
allow(@request).to receive(:path) { starred_explore_projects_path }
|
|
|
|
|
|
|
|
expect(subject).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when on the "Your projects" tab' do
|
|
|
|
allow(@request).to receive(:path) { dashboard_projects_path }
|
|
|
|
|
|
|
|
expect(subject).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
expect(helper.show_merge_request_count?).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
before do
|
|
|
|
stub_feature_flags(project_list_show_mr_count: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
before do
|
|
|
|
stub_feature_flags(project_list_show_mr_count: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
before do
|
|
|
|
stub_feature_flags(project_list_show_issue_count: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
expect(helper.show_issue_count?(compact_mode: true)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
before do
|
|
|
|
stub_feature_flags(project_list_show_issue_count: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
expect(helper.show_issue_count?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-10-08 10:21:40 -04:00
|
|
|
end
|