Commit 54bc64ec00a402cb330f35df8e346d9448d4e2ca
Committed by
Daniela Feitosa
1 parent
f7a1b20d
Exists in
staging
and in
42 other branches
Sorting qualifiers and certifiers by name
(ActionItem1880)
Showing
6 changed files
with
67 additions
and
2 deletions
Show diff stats
app/helpers/manage_products_helper.rb
... | ... | @@ -217,10 +217,10 @@ module ManageProductsHelper |
217 | 217 | end |
218 | 218 | |
219 | 219 | def qualifiers_for_select |
220 | - [[_('Select...'), nil]] + environment.qualifiers.map{ |c| [c.name, c.id] } | |
220 | + [[_('Select...'), nil]] + environment.qualifiers.sort.map{ |c| [c.name, c.id] } | |
221 | 221 | end |
222 | 222 | def certifiers_for_select(qualifier) |
223 | - [[_('Self declared'), nil]] + qualifier.certifiers.map{ |c| [c.name, c.id] } | |
223 | + [[_('Self declared'), nil]] + qualifier.certifiers.sort.map{ |c| [c.name, c.id] } | |
224 | 224 | end |
225 | 225 | def select_qualifiers(product, selected = nil) |
226 | 226 | select_tag('selected_qualifier', options_for_select(qualifiers_for_select, selected), | ... | ... |
app/models/certifier.rb
app/models/qualifier.rb
test/unit/certifier_test.rb
... | ... | @@ -39,4 +39,23 @@ class CertifierTest < Test::Unit::TestCase |
39 | 39 | assert certifier.valid? |
40 | 40 | end |
41 | 41 | |
42 | + should 'sort by name' do | |
43 | + last = fast_create(Certifier, :name => "Zumm") | |
44 | + first = fast_create(Certifier, :name => "Atum") | |
45 | + assert_equal [first, last], Certifier.all.sort | |
46 | + end | |
47 | + | |
48 | + should 'sorting is not case sensitive' do | |
49 | + first = fast_create(Certifier, :name => "Aaaa") | |
50 | + second = fast_create(Certifier, :name => "abbb") | |
51 | + last = fast_create(Certifier, :name => "Accc") | |
52 | + assert_equal [first, second, last], Certifier.all.sort | |
53 | + end | |
54 | + | |
55 | + should 'discard non-ascii char when sorting' do | |
56 | + first = fast_create(Certifier, :name => "Áaaa") | |
57 | + last = fast_create(Certifier, :name => "Aáab") | |
58 | + assert_equal [first, last], Certifier.all.sort | |
59 | + end | |
60 | + | |
42 | 61 | end | ... | ... |
test/unit/manage_products_helper_test.rb
... | ... | @@ -149,6 +149,24 @@ class ManageProductsHelperTest < Test::Unit::TestCase |
149 | 149 | assert_equal 'Amount used in this product or service', label_amount_used(input) |
150 | 150 | end |
151 | 151 | |
152 | + should 'sort qualifiers by name' do | |
153 | + fast_create(Qualifier, :name => 'Organic') | |
154 | + fast_create(Qualifier, :name => 'Non Organic') | |
155 | + result = qualifiers_for_select | |
156 | + assert_equal ["Select...", "Non Organic", "Organic"], result.map{|i| i[0]} | |
157 | + end | |
158 | + | |
159 | + should 'sort certifiers by name' do | |
160 | + qualifier = fast_create(Qualifier, :name => 'Organic') | |
161 | + fbes = fast_create(Certifier, :name => 'FBES') | |
162 | + colivre = fast_create(Certifier, :name => 'Colivre') | |
163 | + QualifierCertifier.create!(:qualifier => qualifier, :certifier => colivre) | |
164 | + QualifierCertifier.create!(:qualifier => qualifier, :certifier => fbes) | |
165 | + | |
166 | + result = certifiers_for_select(qualifier) | |
167 | + assert_equal ["Self declared", "Colivre", "FBES"], result.map{|i| i[0]} | |
168 | + end | |
169 | + | |
152 | 170 | protected |
153 | 171 | include NoosferoTestHelper |
154 | 172 | include ActionView::Helpers::TextHelper | ... | ... |
test/unit/qualifier_test.rb
... | ... | @@ -30,4 +30,23 @@ class QualifierTest < Test::Unit::TestCase |
30 | 30 | assert qualifier.valid? |
31 | 31 | end |
32 | 32 | |
33 | + should 'sort by name' do | |
34 | + last = fast_create(Qualifier, :name => "Zumm") | |
35 | + first = fast_create(Qualifier, :name => "Atum") | |
36 | + assert_equal [first, last], Qualifier.all.sort | |
37 | + end | |
38 | + | |
39 | + should 'sorting is not case sensitive' do | |
40 | + first = fast_create(Qualifier, :name => "Aaaa") | |
41 | + second = fast_create(Qualifier, :name => "abbb") | |
42 | + last = fast_create(Qualifier, :name => "Accc") | |
43 | + assert_equal [first, second, last], Qualifier.all.sort | |
44 | + end | |
45 | + | |
46 | + should 'discard non-ascii char when sorting' do | |
47 | + first = fast_create(Qualifier, :name => "Áaaa") | |
48 | + last = fast_create(Qualifier, :name => "Aáab") | |
49 | + assert_equal [first, last], Qualifier.all.sort | |
50 | + end | |
51 | + | |
33 | 52 | end | ... | ... |