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) }
|
|
|
|
|
|
|
|
let(:fork_project) do
|
|
|
|
fork_project = create(:forked_project_with_submodules)
|
|
|
|
fork_project.build_forked_project_link(forked_to_project_id: fork_project.id, forked_from_project_id: project.id)
|
|
|
|
fork_project.save
|
|
|
|
|
|
|
|
fork_project
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
expect(link).to match(%r{/u/#{user.username}})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-10-08 10:21:40 -04:00
|
|
|
end
|