Commit 74d2085cdfab5c929ca68f37375af6d3d3345bba
1 parent
a37c6794
Exists in
spb-stable
and in
3 other branches
Sort tag names using VersionSorter
Showing
2 changed files
with
40 additions
and
3 deletions
Show diff stats
app/helpers/application_helper.rb
... | ... | @@ -94,11 +94,10 @@ module ApplicationHelper |
94 | 94 | |
95 | 95 | options = [ |
96 | 96 | ["Branches", repository.branch_names], |
97 | - ["Tags", repository.tag_names] | |
97 | + ["Tags", VersionSorter.rsort(repository.tag_names)] | |
98 | 98 | ] |
99 | 99 | |
100 | - # If reference is commit id - | |
101 | - # we should add it to branch/tag selectbox | |
100 | + # If reference is commit id - we should add it to branch/tag selectbox | |
102 | 101 | if(@ref && !options.flatten.include?(@ref) && |
103 | 102 | @ref =~ /^[0-9a-zA-Z]{6,52}$/) |
104 | 103 | options << ["Commit", [@ref]] | ... | ... |
spec/helpers/application_helper_spec.rb
... | ... | @@ -116,7 +116,45 @@ describe ApplicationHelper do |
116 | 116 | allow(self).to receive(:request).and_return(double(:ssl? => false)) |
117 | 117 | gravatar_icon(user_email).should == gravatar_icon(user_email.upcase + " ") |
118 | 118 | end |
119 | + end | |
120 | + | |
121 | + describe "grouped_options_refs" do | |
122 | + # Override Rails' grouped_options_for_select helper since HTML is harder to work with | |
123 | + def grouped_options_for_select(options, *args) | |
124 | + options | |
125 | + end | |
126 | + | |
127 | + let(:options) { grouped_options_refs } | |
128 | + | |
129 | + before do | |
130 | + # Must be an instance variable | |
131 | + @project = create(:project) | |
132 | + end | |
133 | + | |
134 | + it "includes a list of branch names" do | |
135 | + options[0][0].should == 'Branches' | |
136 | + options[0][1].should include('master', 'stable') | |
137 | + end | |
138 | + | |
139 | + it "includes a list of tag names" do | |
140 | + options[1][0].should == 'Tags' | |
141 | + options[1][1].should include('v0.9.4','v1.2.0') | |
142 | + end | |
143 | + | |
144 | + it "includes a specific commit ref if defined" do | |
145 | + # Must be an instance variable | |
146 | + @ref = '2ed06dc41dbb5936af845b87d79e05bbf24c73b8' | |
119 | 147 | |
148 | + options[2][0].should == 'Commit' | |
149 | + options[2][1].should == [@ref] | |
150 | + end | |
151 | + | |
152 | + it "sorts tags in a natural order" do | |
153 | + # Stub repository.tag_names to make sure we get some valid testing data | |
154 | + expect(@project.repository).to receive(:tag_names).and_return(["v1.0.9", "v1.0.10", "v2.0", "v3.1.4.2", "v1.0.9a"]) | |
155 | + | |
156 | + options[1][1].should == ["v3.1.4.2", "v2.0", "v1.0.10", "v1.0.9a", "v1.0.9"] | |
157 | + end | |
120 | 158 | end |
121 | 159 | |
122 | 160 | describe "user_color_scheme_class" do | ... | ... |