To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 5a / 5a957f080953e031edeca7e814ed596f2e38c506.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (2.59 KB)
| 1 | 1296:038ba2d95de8 | Chris | # Redmine - project management software |
|---|---|---|---|
| 2 | # Copyright (C) 2006-2012 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 | include ERB::Util |
||
| 23 | |||
| 24 | def setup |
||
| 25 | @session = nil |
||
| 26 | @sort_param = nil |
||
| 27 | end |
||
| 28 | |||
| 29 | def test_default_sort_clause_with_array |
||
| 30 | sort_init 'attr1', 'desc' |
||
| 31 | sort_update(['attr1', 'attr2']) |
||
| 32 | |||
| 33 | assert_equal 'attr1 DESC', sort_clause |
||
| 34 | end |
||
| 35 | |||
| 36 | def test_default_sort_clause_with_hash |
||
| 37 | sort_init 'attr1', 'desc' |
||
| 38 | sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
|
||
| 39 | |||
| 40 | assert_equal 'table1.attr1 DESC', sort_clause |
||
| 41 | end |
||
| 42 | |||
| 43 | def test_default_sort_clause_with_multiple_columns |
||
| 44 | sort_init 'attr1', 'desc' |
||
| 45 | sort_update({'attr1' => ['table1.attr1', 'table1.attr2'], 'attr2' => 'table2.attr2'})
|
||
| 46 | |||
| 47 | assert_equal 'table1.attr1 DESC, table1.attr2 DESC', sort_clause |
||
| 48 | end |
||
| 49 | |||
| 50 | def test_params_sort |
||
| 51 | @sort_param = 'attr1,attr2:desc' |
||
| 52 | |||
| 53 | sort_init 'attr1', 'desc' |
||
| 54 | sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
|
||
| 55 | |||
| 56 | assert_equal 'table1.attr1, table2.attr2 DESC', sort_clause |
||
| 57 | assert_equal 'attr1,attr2:desc', @session['foo_bar_sort'] |
||
| 58 | end |
||
| 59 | |||
| 60 | def test_invalid_params_sort |
||
| 61 | @sort_param = 'invalid_key' |
||
| 62 | |||
| 63 | sort_init 'attr1', 'desc' |
||
| 64 | sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
|
||
| 65 | |||
| 66 | assert_equal 'table1.attr1 DESC', sort_clause |
||
| 67 | assert_equal 'attr1:desc', @session['foo_bar_sort'] |
||
| 68 | end |
||
| 69 | |||
| 70 | def test_invalid_order_params_sort |
||
| 71 | @sort_param = 'attr1:foo:bar,attr2' |
||
| 72 | |||
| 73 | sort_init 'attr1', 'desc' |
||
| 74 | sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
|
||
| 75 | |||
| 76 | assert_equal 'table1.attr1, table2.attr2', sort_clause |
||
| 77 | assert_equal 'attr1,attr2', @session['foo_bar_sort'] |
||
| 78 | end |
||
| 79 | |||
| 80 | private |
||
| 81 | |||
| 82 | def controller_name; 'foo'; end |
||
| 83 | def action_name; 'bar'; end |
||
| 84 | def params; {:sort => @sort_param}; end
|
||
| 85 | def session; @session ||= {}; end
|
||
| 86 | end |