BigW Consortium Gitlab

repository_spec.rb 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
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
22 23

  describe "#discover_default_branch" do
24 25
    let(:master) { 'master' }
    let(:stable) { 'stable' }
26 27

    it "returns 'master' when master exists" do
28
      project.should_receive(:branch_names).at_least(:once).and_return([stable, master])
29 30 31 32 33
      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'
34
      project.should_receive(:branch_names).at_least(:once).and_return([stable, master])
35 36 37 38
      project.discover_default_branch.should == 'stable'
    end

    it "returns a non-master branch when only one exists" do
39
      project.should_receive(:branch_names).at_least(:once).and_return([stable])
40 41 42 43
      project.discover_default_branch.should == 'stable'
    end

    it "returns nil when no branch exists" do
44
      project.should_receive(:branch_names).at_least(:once).and_return([])
45 46 47
      project.discover_default_branch.should be_nil
    end
  end
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

  describe "#root_ref" do
    it "returns default_branch when set" do
      project.default_branch = 'stable'
      project.root_ref.should == 'stable'
    end

    it "returns 'master' when default_branch is nil" do
      project.default_branch = nil
      project.root_ref.should == 'master'
    end
  end

  describe "#root_ref?" do
    it "returns true when branch is root_ref" do
      project.default_branch = 'stable'
      project.root_ref?('stable').should be_true
    end

    it "returns false when branch is not root_ref" do
      project.default_branch = nil
      project.root_ref?('stable').should be_false
    end
  end
72
end