gitlab-org--gitlab-foss/spec/helpers/projects_helper_spec.rb
Stan Hu a5e8ea54ec Fix Error 500 when browsing projects with no HEAD
Steps to reproduce:
1. Create a project with a README
2. In the actual remote, type: `git symbolic-ref HEAD refs/heads/nowhere`
3. Check that HEAD is gone via `git ls-remote .`
4. Go to the projects page and see the Error 500

Closes https://github.com/gitlabhq/gitlabhq/issues/9484
2015-07-24 10:14:58 -07:00

73 lines
2.2 KiB
Ruby

require 'spec_helper'
describe ProjectsHelper do
describe "#project_status_css_class" do
it "returns appropriate class" do
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")
end
end
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) }
it "returns false if there are no appropriate permissions" do
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
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
expect(helper.send(:readme_cache_key)).to eq("#{project.id}-#{project.commit.id}-readme")
end
it "returns a valid cache key if HEAD does not exist" do
allow(project).to receive(:commit) { nil }
expect(helper.send(:readme_cache_key)).to eq("#{project.id}-nil-readme")
end
end
end