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