Commit d33d550e3e515c0caddefc3e0398db031aedd4e5
Exists in
spb-stable
and in
3 other branches
Merge pull request #6500 from tsigo/natural-tag-sorting
Natural version sorting
Showing
4 changed files
with
44 additions
and
4 deletions
Show diff stats
Gemfile
Gemfile.lock
... | ... | @@ -537,6 +537,7 @@ GEM |
537 | 537 | raindrops (~> 0.7) |
538 | 538 | unicorn-worker-killer (0.4.2) |
539 | 539 | unicorn (~> 4) |
540 | + version_sorter (1.1.0) | |
540 | 541 | virtus (1.0.1) |
541 | 542 | axiom-types (~> 0.0.5) |
542 | 543 | coercible (~> 1.0) |
... | ... | @@ -662,4 +663,5 @@ DEPENDENCIES |
662 | 663 | underscore-rails (~> 1.4.4) |
663 | 664 | unicorn (~> 4.6.3) |
664 | 665 | unicorn-worker-killer |
666 | + version_sorter | |
665 | 667 | webmock | ... | ... |
app/helpers/application_helper.rb
... | ... | @@ -89,16 +89,15 @@ module ApplicationHelper |
89 | 89 | "Never" |
90 | 90 | end |
91 | 91 | |
92 | - def grouped_options_refs(destination = :tree) | |
92 | + def grouped_options_refs | |
93 | 93 | repository = @project.repository |
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 | ... | ... |