To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / 7a / 7a2b37fe2ff5ae9d62a418e469dc500c74dfab37.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (2.57 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

    
18
require File.expand_path('../../../test_helper', __FILE__)
19

    
20
class SortHelperTest < ActionView::TestCase
21
  include SortHelper
22

    
23
  def setup
24
    @session = nil
25
    @sort_param = nil
26
  end
27

    
28
  def test_default_sort_clause_with_array
29
    sort_init 'attr1', 'desc'
30
    sort_update(['attr1', 'attr2'])
31

    
32
    assert_equal 'attr1 DESC', sort_clause
33
  end
34

    
35
  def test_default_sort_clause_with_hash
36
    sort_init 'attr1', 'desc'
37
    sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
38

    
39
    assert_equal 'table1.attr1 DESC', sort_clause
40
  end
41

    
42
  def test_default_sort_clause_with_multiple_columns
43
    sort_init 'attr1', 'desc'
44
    sort_update({'attr1' => ['table1.attr1', 'table1.attr2'], 'attr2' => 'table2.attr2'})
45

    
46
    assert_equal 'table1.attr1 DESC, table1.attr2 DESC', sort_clause
47
  end
48

    
49
  def test_params_sort
50
    @sort_param = 'attr1,attr2:desc'
51

    
52
    sort_init 'attr1', 'desc'
53
    sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
54

    
55
    assert_equal 'table1.attr1, table2.attr2 DESC', sort_clause
56
    assert_equal 'attr1,attr2:desc', @session['foo_bar_sort']
57
  end
58

    
59
  def test_invalid_params_sort
60
    @sort_param = 'invalid_key'
61

    
62
    sort_init 'attr1', 'desc'
63
    sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
64

    
65
    assert_equal 'table1.attr1 DESC', sort_clause
66
    assert_equal 'attr1:desc', @session['foo_bar_sort']
67
  end
68

    
69
  def test_invalid_order_params_sort
70
    @sort_param = 'attr1:foo:bar,attr2'
71

    
72
    sort_init 'attr1', 'desc'
73
    sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
74

    
75
    assert_equal 'table1.attr1, table2.attr2', sort_clause
76
    assert_equal 'attr1,attr2', @session['foo_bar_sort']
77
  end
78

    
79
  private
80

    
81
  def controller_name; 'foo'; end
82
  def action_name; 'bar'; end
83
  def params; {:sort => @sort_param}; end
84
  def session; @session ||= {}; end
85
end