@@ -1,85 +1,85 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2009 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2009 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 < |
|
20 | class SortHelperTest < ActionView::TestCase | |
21 | include SortHelper |
|
21 | include SortHelper | |
22 |
|
22 | |||
23 | def setup |
|
23 | def setup | |
24 | @session = nil |
|
24 | @session = nil | |
25 | @sort_param = nil |
|
25 | @sort_param = nil | |
26 | end |
|
26 | end | |
27 |
|
27 | |||
28 | def test_default_sort_clause_with_array |
|
28 | def test_default_sort_clause_with_array | |
29 | sort_init 'attr1', 'desc' |
|
29 | sort_init 'attr1', 'desc' | |
30 | sort_update(['attr1', 'attr2']) |
|
30 | sort_update(['attr1', 'attr2']) | |
31 |
|
31 | |||
32 | assert_equal 'attr1 DESC', sort_clause |
|
32 | assert_equal 'attr1 DESC', sort_clause | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def test_default_sort_clause_with_hash |
|
35 | def test_default_sort_clause_with_hash | |
36 | sort_init 'attr1', 'desc' |
|
36 | sort_init 'attr1', 'desc' | |
37 | sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'}) |
|
37 | sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'}) | |
38 |
|
38 | |||
39 | assert_equal 'table1.attr1 DESC', sort_clause |
|
39 | assert_equal 'table1.attr1 DESC', sort_clause | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | def test_default_sort_clause_with_multiple_columns |
|
42 | def test_default_sort_clause_with_multiple_columns | |
43 | sort_init 'attr1', 'desc' |
|
43 | sort_init 'attr1', 'desc' | |
44 | sort_update({'attr1' => ['table1.attr1', 'table1.attr2'], 'attr2' => 'table2.attr2'}) |
|
44 | sort_update({'attr1' => ['table1.attr1', 'table1.attr2'], 'attr2' => 'table2.attr2'}) | |
45 |
|
45 | |||
46 | assert_equal 'table1.attr1 DESC, table1.attr2 DESC', sort_clause |
|
46 | assert_equal 'table1.attr1 DESC, table1.attr2 DESC', sort_clause | |
47 | end |
|
47 | end | |
48 |
|
48 | |||
49 | def test_params_sort |
|
49 | def test_params_sort | |
50 | @sort_param = 'attr1,attr2:desc' |
|
50 | @sort_param = 'attr1,attr2:desc' | |
51 |
|
51 | |||
52 | sort_init 'attr1', 'desc' |
|
52 | sort_init 'attr1', 'desc' | |
53 | sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'}) |
|
53 | sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'}) | |
54 |
|
54 | |||
55 | assert_equal 'table1.attr1, table2.attr2 DESC', sort_clause |
|
55 | assert_equal 'table1.attr1, table2.attr2 DESC', sort_clause | |
56 | assert_equal 'attr1,attr2:desc', @session['foo_bar_sort'] |
|
56 | assert_equal 'attr1,attr2:desc', @session['foo_bar_sort'] | |
57 | end |
|
57 | end | |
58 |
|
58 | |||
59 | def test_invalid_params_sort |
|
59 | def test_invalid_params_sort | |
60 | @sort_param = 'invalid_key' |
|
60 | @sort_param = 'invalid_key' | |
61 |
|
61 | |||
62 | sort_init 'attr1', 'desc' |
|
62 | sort_init 'attr1', 'desc' | |
63 | sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'}) |
|
63 | sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'}) | |
64 |
|
64 | |||
65 | assert_equal 'table1.attr1 DESC', sort_clause |
|
65 | assert_equal 'table1.attr1 DESC', sort_clause | |
66 | assert_equal 'attr1:desc', @session['foo_bar_sort'] |
|
66 | assert_equal 'attr1:desc', @session['foo_bar_sort'] | |
67 | end |
|
67 | end | |
68 |
|
68 | |||
69 | def test_invalid_order_params_sort |
|
69 | def test_invalid_order_params_sort | |
70 | @sort_param = 'attr1:foo:bar,attr2' |
|
70 | @sort_param = 'attr1:foo:bar,attr2' | |
71 |
|
71 | |||
72 | sort_init 'attr1', 'desc' |
|
72 | sort_init 'attr1', 'desc' | |
73 | sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'}) |
|
73 | sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'}) | |
74 |
|
74 | |||
75 | assert_equal 'table1.attr1, table2.attr2', sort_clause |
|
75 | assert_equal 'table1.attr1, table2.attr2', sort_clause | |
76 | assert_equal 'attr1,attr2', @session['foo_bar_sort'] |
|
76 | assert_equal 'attr1,attr2', @session['foo_bar_sort'] | |
77 | end |
|
77 | end | |
78 |
|
78 | |||
79 | private |
|
79 | private | |
80 |
|
80 | |||
81 | def controller_name; 'foo'; end |
|
81 | def controller_name; 'foo'; end | |
82 | def action_name; 'bar'; end |
|
82 | def action_name; 'bar'; end | |
83 | def params; {:sort => @sort_param}; end |
|
83 | def params; {:sort => @sort_param}; end | |
84 | def session; @session ||= {}; end |
|
84 | def session; @session ||= {}; end | |
85 | end |
|
85 | end |
General Comments 0
You need to be logged in to leave comments.
Login now