Mercurial > hg > soundsoftware-site
comparison test/unit/helpers/sort_helper_test.rb @ 1464:261b3d9a4903 redmine-2.4
Update to Redmine 2.4 branch rev 12663
author | Chris Cannam |
---|---|
date | Tue, 14 Jan 2014 14:37:42 +0000 |
parents | 433d4f72a19b |
children | e248c7af89ec |
comparison
equal
deleted
inserted
replaced
1296:038ba2d95de8 | 1464:261b3d9a4903 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2013 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. |
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 ERB::Util | 23 include ERB::Util |
23 | 24 |
24 def setup | 25 def setup |
25 @session = nil | 26 @session = nil |
26 @sort_param = nil | 27 @sort_param = nil |
28 | 29 |
29 def test_default_sort_clause_with_array | 30 def test_default_sort_clause_with_array |
30 sort_init 'attr1', 'desc' | 31 sort_init 'attr1', 'desc' |
31 sort_update(['attr1', 'attr2']) | 32 sort_update(['attr1', 'attr2']) |
32 | 33 |
33 assert_equal 'attr1 DESC', sort_clause | 34 assert_equal ['attr1 DESC'], sort_clause |
34 end | 35 end |
35 | 36 |
36 def test_default_sort_clause_with_hash | 37 def test_default_sort_clause_with_hash |
37 sort_init 'attr1', 'desc' | 38 sort_init 'attr1', 'desc' |
38 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'}) | 39 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'}) |
39 | 40 |
40 assert_equal 'table1.attr1 DESC', sort_clause | 41 assert_equal ['table1.attr1 DESC'], sort_clause |
41 end | 42 end |
42 | 43 |
43 def test_default_sort_clause_with_multiple_columns | 44 def test_default_sort_clause_with_multiple_columns |
44 sort_init 'attr1', 'desc' | 45 sort_init 'attr1', 'desc' |
45 sort_update({'attr1' => ['table1.attr1', 'table1.attr2'], 'attr2' => 'table2.attr2'}) | 46 sort_update({'attr1' => ['table1.attr1', 'table1.attr2'], 'attr2' => 'table2.attr2'}) |
46 | 47 |
47 assert_equal 'table1.attr1 DESC, table1.attr2 DESC', sort_clause | 48 assert_equal ['table1.attr1 DESC', 'table1.attr2 DESC'], sort_clause |
48 end | 49 end |
49 | 50 |
50 def test_params_sort | 51 def test_params_sort |
51 @sort_param = 'attr1,attr2:desc' | 52 @sort_param = 'attr1,attr2:desc' |
52 | 53 |
53 sort_init 'attr1', 'desc' | 54 sort_init 'attr1', 'desc' |
54 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'}) | 55 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'}) |
55 | 56 |
56 assert_equal 'table1.attr1, table2.attr2 DESC', sort_clause | 57 assert_equal ['table1.attr1', 'table2.attr2 DESC'], sort_clause |
57 assert_equal 'attr1,attr2:desc', @session['foo_bar_sort'] | 58 assert_equal 'attr1,attr2:desc', @session['foo_bar_sort'] |
58 end | 59 end |
59 | 60 |
60 def test_invalid_params_sort | 61 def test_invalid_params_sort |
61 @sort_param = 'invalid_key' | 62 @sort_param = 'invalid_key' |
62 | 63 |
63 sort_init 'attr1', 'desc' | 64 sort_init 'attr1', 'desc' |
64 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'}) | 65 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'}) |
65 | 66 |
66 assert_equal 'table1.attr1 DESC', sort_clause | 67 assert_equal ['table1.attr1 DESC'], sort_clause |
67 assert_equal 'attr1:desc', @session['foo_bar_sort'] | 68 assert_equal 'attr1:desc', @session['foo_bar_sort'] |
68 end | 69 end |
69 | 70 |
70 def test_invalid_order_params_sort | 71 def test_invalid_order_params_sort |
71 @sort_param = 'attr1:foo:bar,attr2' | 72 @sort_param = 'attr1:foo:bar,attr2' |
72 | 73 |
73 sort_init 'attr1', 'desc' | 74 sort_init 'attr1', 'desc' |
74 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'}) | 75 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'}) |
75 | 76 |
76 assert_equal 'table1.attr1, table2.attr2', sort_clause | 77 assert_equal ['table1.attr1', 'table2.attr2'], sort_clause |
77 assert_equal 'attr1,attr2', @session['foo_bar_sort'] | 78 assert_equal 'attr1,attr2', @session['foo_bar_sort'] |
78 end | 79 end |
79 | 80 |
80 private | 81 private |
81 | 82 |