2013-10-08 10:21:40 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ProjectsHelper do
|
2014-12-31 08:07:48 -05:00
|
|
|
describe "#project_status_css_class" do
|
|
|
|
it "returns appropriate class" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(project_status_css_class("started")).to eq("active")
|
|
|
|
expect(project_status_css_class("failed")).to eq("danger")
|
|
|
|
expect(project_status_css_class("finished")).to eq("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
|
|
|
|
let(:project) { create(:project) }
|
2016-09-19 14:28:41 -04:00
|
|
|
let(:user) { create(:project_member, :reporter, user: create(:user), project: project).user }
|
2016-03-20 18:26:58 -04:00
|
|
|
let(:fork_project) { Projects::ForkService.new(project, user).execute }
|
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
|
|
|
|
|
|
|
|
context "forks" do
|
|
|
|
it "returns false if there are permissions and origin project is PRIVATE" do
|
|
|
|
allow(helper).to receive(:can?) { true }
|
|
|
|
|
|
|
|
project.update visibility_level: Gitlab::VisibilityLevel::PRIVATE
|
|
|
|
|
|
|
|
expect(helper.can_change_visibility_level?(fork_project, user)).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true if there are permissions and origin project is INTERNAL" do
|
|
|
|
allow(helper).to receive(:can?) { true }
|
|
|
|
|
|
|
|
project.update visibility_level: Gitlab::VisibilityLevel::INTERNAL
|
|
|
|
|
|
|
|
expect(helper.can_change_visibility_level?(fork_project, user)).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-07-24 02:52:21 -04:00
|
|
|
|
|
|
|
describe "readme_cache_key" do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
helper.instance_variable_set(:@project, project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a valid cach key" do
|
2015-10-02 16:03:51 -04:00
|
|
|
expect(helper.send(:readme_cache_key)).to eq("#{project.path_with_namespace}-#{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 }
|
|
|
|
|
2015-10-02 16:03:51 -04:00
|
|
|
expect(helper.send(:readme_cache_key)).to eq("#{project.path_with_namespace}-nil-readme")
|
2015-07-24 02:52:21 -04:00
|
|
|
end
|
|
|
|
end
|
2015-10-12 11:22:22 -04:00
|
|
|
|
|
|
|
describe 'link_to_member' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:project) { create(:empty_project, group: group) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
describe '#license_short_name' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
context 'when project.repository has a license_key' do
|
|
|
|
it 'returns the nickname of the license if present' do
|
|
|
|
allow(project.repository).to receive(:license_key).and_return('agpl-3.0')
|
|
|
|
|
|
|
|
expect(helper.license_short_name(project)).to eq('GNU AGPLv3')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the name of the license if nickname is not present' do
|
|
|
|
allow(project.repository).to receive(:license_key).and_return('mit')
|
|
|
|
|
|
|
|
expect(helper.license_short_name(project)).to eq('MIT License')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project.repository has no license_key but a license_blob' do
|
|
|
|
it 'returns LICENSE' do
|
|
|
|
allow(project.repository).to receive(:license_key).and_return(nil)
|
|
|
|
|
|
|
|
expect(helper.license_short_name(project)).to eq('LICENSE')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-05-04 00:32:49 -04:00
|
|
|
|
|
|
|
describe '#sanitized_import_error' do
|
2016-06-22 17:04:51 -04:00
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(project).to receive(:repository_storage_path).and_return('/base/repo/path')
|
|
|
|
end
|
|
|
|
|
2016-05-04 00:32:49 -04:00
|
|
|
it 'removes the repo path' do
|
2016-06-22 17:04:51 -04:00
|
|
|
repo = '/base/repo/path/namespace/test.git'
|
2016-05-04 00:32:49 -04:00
|
|
|
import_error = "Could not clone #{repo}\n"
|
|
|
|
|
2016-06-22 17:04:51 -04:00
|
|
|
expect(sanitize_repo_path(project, import_error)).to eq('Could not clone [REPOS PATH]/namespace/test.git')
|
2016-05-04 00:32:49 -04:00
|
|
|
end
|
|
|
|
end
|
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)
|
|
|
|
expect(user).to receive(:recent_push).with([project.id]).and_return(event)
|
|
|
|
|
|
|
|
expect(helper.last_push_event).to eq(event)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when current user has a fork of the current project' do
|
|
|
|
let(:fork) { double(:fork, id: 2) }
|
|
|
|
|
|
|
|
it 'returns recent push considering fork events' do
|
|
|
|
expect(user).to receive(:fork_of).with(project).and_return(fork)
|
|
|
|
|
|
|
|
event_on_fork = double(:event)
|
|
|
|
expect(user).to receive(:recent_push).with([project.id, fork.id]).and_return(event_on_fork)
|
|
|
|
|
|
|
|
expect(helper.last_push_event).to eq(event_on_fork)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-09-02 11:30:54 -04:00
|
|
|
|
|
|
|
describe "#project_feature_access_select" do
|
|
|
|
let(:project) { create(:empty_project, :public) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
context "when project is internal or public" do
|
|
|
|
it "shows all options" do
|
|
|
|
helper.instance_variable_set(:@project, project)
|
|
|
|
result = helper.project_feature_access_select(:issues_access_level)
|
|
|
|
expect(result).to include("Disabled")
|
|
|
|
expect(result).to include("Only team members")
|
|
|
|
expect(result).to include("Everyone with access")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when project is private" do
|
|
|
|
before { project.update_attributes(visibility_level: Gitlab::VisibilityLevel::PRIVATE) }
|
|
|
|
|
|
|
|
it "shows only allowed options" do
|
|
|
|
helper.instance_variable_set(:@project, project)
|
|
|
|
result = helper.project_feature_access_select(:issues_access_level)
|
|
|
|
expect(result).to include("Disabled")
|
|
|
|
expect(result).to include("Only team members")
|
|
|
|
expect(result).not_to include("Everyone with access")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when project moves from public to private" do
|
|
|
|
before do
|
|
|
|
project.project_feature.update_attributes(issues_access_level: ProjectFeature::ENABLED)
|
|
|
|
project.update_attributes(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows the highest allowed level selected" do
|
|
|
|
helper.instance_variable_set(:@project, project)
|
|
|
|
result = helper.project_feature_access_select(:issues_access_level)
|
|
|
|
|
|
|
|
expect(result).to include("Disabled")
|
|
|
|
expect(result).to include("Only team members")
|
|
|
|
expect(result).not_to include("Everyone with access")
|
|
|
|
expect(result).to have_selector('option[selected]', text: "Only team members")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-10-08 10:21:40 -04:00
|
|
|
end
|