##// END OF EJS Templates
Don't fail if new filter is added....
Jean-Philippe Lang -
r11171:723e21243e8d
parent child
Show More
@@ -1,64 +1,69
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 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.
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 QueriesHelperTest < ActionView::TestCase
20 class QueriesHelperTest < ActionView::TestCase
21 include QueriesHelper
21 include QueriesHelper
22 include Redmine::I18n
22 include Redmine::I18n
23
23
24 fixtures :projects, :enabled_modules, :users, :members,
24 fixtures :projects, :enabled_modules, :users, :members,
25 :member_roles, :roles, :trackers, :issue_statuses,
25 :member_roles, :roles, :trackers, :issue_statuses,
26 :issue_categories, :enumerations, :issues,
26 :issue_categories, :enumerations, :issues,
27 :watchers, :custom_fields, :custom_values, :versions,
27 :watchers, :custom_fields, :custom_values, :versions,
28 :queries,
28 :queries,
29 :projects_trackers,
29 :projects_trackers,
30 :custom_fields_trackers
30 :custom_fields_trackers
31
31
32 def test_filters_options_should_be_ordered
32 def test_filters_options_should_be_ordered
33 User.current = User.find_by_login('admin')
33 set_language_if_valid 'en'
34 query = IssueQuery.new(:project => nil, :name => '_')
34 query = IssueQuery.new
35 assert_equal 30, query.available_filters.size
35 filter_count = query.available_filters.size
36 fo = filters_options(query)
36 fo = filters_options(query)
37 assert_equal 31, fo.size
37 assert_equal filter_count + 1, fo.size
38 assert_equal [], fo[0]
38 assert_equal [], fo[0]
39 assert_equal "status_id", fo[1][1]
39
40 assert_equal "project_id", fo[2][1]
40 expected_order = [
41 assert_equal "tracker_id", fo[3][1]
41 "Status",
42 assert_equal "priority_id", fo[4][1]
42 "Project",
43 assert_equal "is_private", fo[17][1]
43 "Tracker",
44 assert_equal "watcher_id", fo[18][1]
44 "Priority"
45 ]
46 assert_equal expected_order, (fo.map(&:first) & expected_order)
45 end
47 end
46
48
47 def test_filters_options_should_be_ordered_with_custom_fields
49 def test_filters_options_should_be_ordered_with_custom_fields
48 set_language_if_valid 'en'
50 set_language_if_valid 'en'
49 field = UserCustomField.create!(
51 field = UserCustomField.create!(
50 :name => 'order test', :field_format => 'string',
52 :name => 'order test', :field_format => 'string',
51 :is_for_all => true, :is_filter => true
53 :is_for_all => true, :is_filter => true
52 )
54 )
53 User.current = User.find_by_login('admin')
55 query = IssueQuery.new
54 query = IssueQuery.new(:project => nil, :name => '_')
56 filter_count = query.available_filters.size
55 assert_equal 32, query.available_filters.size
56 fo = filters_options(query)
57 fo = filters_options(query)
57 assert_equal 33, fo.size
58 assert_equal filter_count + 1, fo.size
58 assert_equal "Searchable field", fo[19][0]
59
59 assert_equal "Database", fo[20][0]
60 expected_order = [
60 assert_equal "Project's Development status", fo[21][0]
61 "Searchable field",
61 assert_equal "Author's order test", fo[22][0]
62 "Database",
62 assert_equal "Assignee's order test", fo[23][0]
63 "Project's Development status",
64 "Author's order test",
65 "Assignee's order test"
66 ]
67 assert_equal expected_order, (fo.map(&:first) & expected_order)
63 end
68 end
64 end
69 end
General Comments 0
You need to be logged in to leave comments. Login now