Commit 2df3b310f9727956c3ce84322928f3360616f5ad

Authored by Robert Speicher
1 parent 5cea3e57

Rename branches and tags Repo methods to branch_names and tag_names

app/roles/repository.rb
@@ -46,18 +46,18 @@ module Repository @@ -46,18 +46,18 @@ module Repository
46 end 46 end
47 47
48 # Returns an Array of branch names 48 # Returns an Array of branch names
49 - def branches 49 + def branch_names
50 repo.branches.collect(&:name).sort 50 repo.branches.collect(&:name).sort
51 end 51 end
52 52
53 # Returns an Array of tag names 53 # Returns an Array of tag names
54 - def tags 54 + def tag_names
55 repo.tags.collect(&:name).sort.reverse 55 repo.tags.collect(&:name).sort.reverse
56 end 56 end
57 57
58 # Returns an Array of branch and tag names 58 # Returns an Array of branch and tag names
59 def ref_names 59 def ref_names
60 - [branches + tags].flatten 60 + [branch_names + tag_names].flatten
61 end 61 end
62 62
63 def repo 63 def repo
@@ -112,12 +112,12 @@ module Repository @@ -112,12 +112,12 @@ module Repository
112 # - If two or more branches are present, returns the one that has a name 112 # - If two or more branches are present, returns the one that has a name
113 # matching root_ref (default_branch or 'master' if default_branch is nil) 113 # matching root_ref (default_branch or 'master' if default_branch is nil)
114 def discover_default_branch 114 def discover_default_branch
115 - if branches.length == 0 115 + if branch_names.length == 0
116 nil 116 nil
117 - elsif branches.length == 1  
118 - branches.first 117 + elsif branch_names.length == 1
  118 + branch_names.first
119 else 119 else
120 - branches.select { |v| v == root_ref }.first 120 + branch_names.select { |v| v == root_ref }.first
121 end 121 end
122 end 122 end
123 123
spec/roles/repository_spec.rb
@@ -25,23 +25,23 @@ describe Project, "Repository" do @@ -25,23 +25,23 @@ describe Project, "Repository" do
25 let(:stable) { 'stable' } 25 let(:stable) { 'stable' }
26 26
27 it "returns 'master' when master exists" do 27 it "returns 'master' when master exists" do
28 - project.should_receive(:branches).at_least(:once).and_return([stable, master]) 28 + project.should_receive(:branch_names).at_least(:once).and_return([stable, master])
29 project.discover_default_branch.should == 'master' 29 project.discover_default_branch.should == 'master'
30 end 30 end
31 31
32 it "returns non-master when master exists but default branch is set to something else" do 32 it "returns non-master when master exists but default branch is set to something else" do
33 project.default_branch = 'stable' 33 project.default_branch = 'stable'
34 - project.should_receive(:branches).at_least(:once).and_return([stable, master]) 34 + project.should_receive(:branch_names).at_least(:once).and_return([stable, master])
35 project.discover_default_branch.should == 'stable' 35 project.discover_default_branch.should == 'stable'
36 end 36 end
37 37
38 it "returns a non-master branch when only one exists" do 38 it "returns a non-master branch when only one exists" do
39 - project.should_receive(:branches).at_least(:once).and_return([stable]) 39 + project.should_receive(:branch_names).at_least(:once).and_return([stable])
40 project.discover_default_branch.should == 'stable' 40 project.discover_default_branch.should == 'stable'
41 end 41 end
42 42
43 it "returns nil when no branch exists" do 43 it "returns nil when no branch exists" do
44 - project.should_receive(:branches).at_least(:once).and_return([]) 44 + project.should_receive(:branch_names).at_least(:once).and_return([])
45 project.discover_default_branch.should be_nil 45 project.discover_default_branch.should be_nil
46 end 46 end
47 end 47 end