##// END OF EJS Templates
Fixed test failures (#19544)....
Jean-Philippe Lang -
r13784:94a9e2848f09
parent child
Show More
@@ -1,109 +1,109
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2015 Jean-Philippe Lang
2 # Copyright (C) 2006-2015 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../../test_helper', __FILE__)
18 require File.expand_path('../../../test_helper', __FILE__)
19
19
20 class SortHelperTest < ActionView::TestCase
20 class SortHelperTest < ActionView::TestCase
21 include SortHelper
21 include SortHelper
22 include Redmine::I18n
22 include Redmine::I18n
23 include ERB::Util
23 include ERB::Util
24
24
25 def setup
25 def setup
26 @session = nil
26 @session = nil
27 @sort_param = nil
27 @sort_param = nil
28 end
28 end
29
29
30 def test_default_sort_clause_with_array
30 def test_default_sort_clause_with_array
31 sort_init 'attr1', 'desc'
31 sort_init 'attr1', 'desc'
32 sort_update(['attr1', 'attr2'])
32 sort_update(['attr1', 'attr2'])
33
33
34 assert_equal ['attr1 DESC'], sort_clause
34 assert_equal ['attr1 DESC'], sort_clause
35 end
35 end
36
36
37 def test_default_sort_clause_with_hash
37 def test_default_sort_clause_with_hash
38 sort_init 'attr1', 'desc'
38 sort_init 'attr1', 'desc'
39 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
39 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
40
40
41 assert_equal ['table1.attr1 DESC'], sort_clause
41 assert_equal ['table1.attr1 DESC'], sort_clause
42 end
42 end
43
43
44 def test_default_sort_clause_with_multiple_columns
44 def test_default_sort_clause_with_multiple_columns
45 sort_init 'attr1', 'desc'
45 sort_init 'attr1', 'desc'
46 sort_update({'attr1' => ['table1.attr1', 'table1.attr2'], 'attr2' => 'table2.attr2'})
46 sort_update({'attr1' => ['table1.attr1', 'table1.attr2'], 'attr2' => 'table2.attr2'})
47
47
48 assert_equal ['table1.attr1 DESC', 'table1.attr2 DESC'], sort_clause
48 assert_equal ['table1.attr1 DESC', 'table1.attr2 DESC'], sort_clause
49 end
49 end
50
50
51 def test_params_sort
51 def test_params_sort
52 @sort_param = 'attr1,attr2:desc'
52 @sort_param = 'attr1,attr2:desc'
53
53
54 sort_init 'attr1', 'desc'
54 sort_init 'attr1', 'desc'
55 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
55 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
56
56
57 assert_equal ['table1.attr1', 'table2.attr2 DESC'], sort_clause
57 assert_equal ['table1.attr1 ASC', 'table2.attr2 DESC'], sort_clause
58 assert_equal 'attr1,attr2:desc', @session['foo_bar_sort']
58 assert_equal 'attr1,attr2:desc', @session['foo_bar_sort']
59 end
59 end
60
60
61 def test_invalid_params_sort
61 def test_invalid_params_sort
62 @sort_param = 'invalid_key'
62 @sort_param = 'invalid_key'
63
63
64 sort_init 'attr1', 'desc'
64 sort_init 'attr1', 'desc'
65 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
65 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
66
66
67 assert_equal ['table1.attr1 DESC'], sort_clause
67 assert_equal ['table1.attr1 DESC'], sort_clause
68 assert_equal 'attr1:desc', @session['foo_bar_sort']
68 assert_equal 'attr1:desc', @session['foo_bar_sort']
69 end
69 end
70
70
71 def test_invalid_order_params_sort
71 def test_invalid_order_params_sort
72 @sort_param = 'attr1:foo:bar,attr2'
72 @sort_param = 'attr1:foo:bar,attr2'
73
73
74 sort_init 'attr1', 'desc'
74 sort_init 'attr1', 'desc'
75 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
75 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
76
76
77 assert_equal ['table1.attr1', 'table2.attr2'], sort_clause
77 assert_equal ['table1.attr1 ASC', 'table2.attr2 ASC'], sort_clause
78 assert_equal 'attr1,attr2', @session['foo_bar_sort']
78 assert_equal 'attr1,attr2', @session['foo_bar_sort']
79 end
79 end
80
80
81 def test_sort_css_without_params_should_use_default_sort
81 def test_sort_css_without_params_should_use_default_sort
82 sort_init 'attr1', 'desc'
82 sort_init 'attr1', 'desc'
83 sort_update(['attr1', 'attr2'])
83 sort_update(['attr1', 'attr2'])
84
84
85 assert_equal 'sort-by-attr1 sort-desc', sort_css_classes
85 assert_equal 'sort-by-attr1 sort-desc', sort_css_classes
86 end
86 end
87
87
88 def test_sort_css_should_use_params
88 def test_sort_css_should_use_params
89 @sort_param = 'attr2,attr1'
89 @sort_param = 'attr2,attr1'
90 sort_init 'attr1', 'desc'
90 sort_init 'attr1', 'desc'
91 sort_update(['attr1', 'attr2'])
91 sort_update(['attr1', 'attr2'])
92
92
93 assert_equal 'sort-by-attr2 sort-asc', sort_css_classes
93 assert_equal 'sort-by-attr2 sort-asc', sort_css_classes
94 end
94 end
95
95
96 def test_sort_css_should_dasherize_sort_name
96 def test_sort_css_should_dasherize_sort_name
97 sort_init 'foo_bar'
97 sort_init 'foo_bar'
98 sort_update(['foo_bar'])
98 sort_update(['foo_bar'])
99
99
100 assert_equal 'sort-by-foo-bar sort-asc', sort_css_classes
100 assert_equal 'sort-by-foo-bar sort-asc', sort_css_classes
101 end
101 end
102
102
103 private
103 private
104
104
105 def controller_name; 'foo'; end
105 def controller_name; 'foo'; end
106 def action_name; 'bar'; end
106 def action_name; 'bar'; end
107 def params; {:sort => @sort_param}; end
107 def params; {:sort => @sort_param}; end
108 def session; @session ||= {}; end
108 def session; @session ||= {}; end
109 end
109 end
General Comments 0
You need to be logged in to leave comments. Login now