Commit 2df3b310f9727956c3ce84322928f3360616f5ad
1 parent
5cea3e57
Exists in
master
and in
4 other branches
Rename branches and tags Repo methods to branch_names and tag_names
Showing
2 changed files
with
11 additions
and
11 deletions
Show diff stats
app/roles/repository.rb
| ... | ... | @@ -46,18 +46,18 @@ module Repository |
| 46 | 46 | end |
| 47 | 47 | |
| 48 | 48 | # Returns an Array of branch names |
| 49 | - def branches | |
| 49 | + def branch_names | |
| 50 | 50 | repo.branches.collect(&:name).sort |
| 51 | 51 | end |
| 52 | 52 | |
| 53 | 53 | # Returns an Array of tag names |
| 54 | - def tags | |
| 54 | + def tag_names | |
| 55 | 55 | repo.tags.collect(&:name).sort.reverse |
| 56 | 56 | end |
| 57 | 57 | |
| 58 | 58 | # Returns an Array of branch and tag names |
| 59 | 59 | def ref_names |
| 60 | - [branches + tags].flatten | |
| 60 | + [branch_names + tag_names].flatten | |
| 61 | 61 | end |
| 62 | 62 | |
| 63 | 63 | def repo |
| ... | ... | @@ -112,12 +112,12 @@ module Repository |
| 112 | 112 | # - If two or more branches are present, returns the one that has a name |
| 113 | 113 | # matching root_ref (default_branch or 'master' if default_branch is nil) |
| 114 | 114 | def discover_default_branch |
| 115 | - if branches.length == 0 | |
| 115 | + if branch_names.length == 0 | |
| 116 | 116 | nil |
| 117 | - elsif branches.length == 1 | |
| 118 | - branches.first | |
| 117 | + elsif branch_names.length == 1 | |
| 118 | + branch_names.first | |
| 119 | 119 | else |
| 120 | - branches.select { |v| v == root_ref }.first | |
| 120 | + branch_names.select { |v| v == root_ref }.first | |
| 121 | 121 | end |
| 122 | 122 | end |
| 123 | 123 | ... | ... |
spec/roles/repository_spec.rb
| ... | ... | @@ -25,23 +25,23 @@ describe Project, "Repository" do |
| 25 | 25 | let(:stable) { 'stable' } |
| 26 | 26 | |
| 27 | 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 | 29 | project.discover_default_branch.should == 'master' |
| 30 | 30 | end |
| 31 | 31 | |
| 32 | 32 | it "returns non-master when master exists but default branch is set to something else" do |
| 33 | 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 | 35 | project.discover_default_branch.should == 'stable' |
| 36 | 36 | end |
| 37 | 37 | |
| 38 | 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 | 40 | project.discover_default_branch.should == 'stable' |
| 41 | 41 | end |
| 42 | 42 | |
| 43 | 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 | 45 | project.discover_default_branch.should be_nil |
| 46 | 46 | end |
| 47 | 47 | end | ... | ... |