gitlabhq/spec/roles/repository_spec.rb

49 lines
1.5 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe Project, "Repository" do
let(:project) { build(:project) }
describe "#empty_repo?" do
it "should return true if the repo doesn't exist" do
project.stub(repo_exists?: false, has_commits?: true)
project.should be_empty_repo
end
it "should return true if the repo has commits" do
project.stub(repo_exists?: true, has_commits?: false)
project.should be_empty_repo
end
it "should return false if the repo exists and has commits" do
project.stub(repo_exists?: true, has_commits?: true)
project.should_not be_empty_repo
end
end
describe "#discover_default_branch" do
let(:master) { double(name: 'master') }
let(:stable) { double(name: 'stable') }
it "returns 'master' when master exists" do
project.should_receive(:heads).and_return([stable, master])
project.discover_default_branch.should == 'master'
end
it "returns non-master when master exists but default branch is set to something else" do
project.default_branch = 'stable'
project.should_receive(:heads).and_return([stable, master])
project.discover_default_branch.should == 'stable'
end
it "returns a non-master branch when only one exists" do
project.should_receive(:heads).and_return([stable])
project.discover_default_branch.should == 'stable'
end
it "returns nil when no branch exists" do
project.should_receive(:heads).and_return([])
project.discover_default_branch.should be_nil
end
end
end