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