@@ -0,0 +1,34 | |||
|
1 | # 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 ApplicationHelperTest < ActionView::TestCase | |
|
21 | include Redmine::Pagination::Helper | |
|
22 | ||
|
23 | def test_per_page_options_should_return_usefull_values | |
|
24 | with_settings :per_page_options => '10, 25, 50, 100' do | |
|
25 | assert_equal [], per_page_options(10, 3) | |
|
26 | assert_equal [], per_page_options(25, 3) | |
|
27 | assert_equal [10, 25], per_page_options(10, 22) | |
|
28 | assert_equal [10, 25], per_page_options(25, 22) | |
|
29 | assert_equal [10, 25, 50], per_page_options(50, 22) | |
|
30 | assert_equal [10, 25, 50], per_page_options(25, 26) | |
|
31 | assert_equal [10, 25, 50, 100], per_page_options(25, 120) | |
|
32 | end | |
|
33 | end | |
|
34 | end |
@@ -208,22 +208,30 module Redmine | |||
|
208 | 208 | |
|
209 | 209 | # Renders the "Per page" links. |
|
210 | 210 | def per_page_links(selected=nil, item_count=nil, &block) |
|
211 |
values = |
|
|
212 |
if |
|
|
213 | if item_count > values.first | |
|
214 | max = values.detect {|value| value >= item_count} || item_count | |
|
211 | values = per_page_options(selected, item_count) | |
|
212 | if values.any? | |
|
213 | links = values.collect do |n| | |
|
214 | n == selected ? n : yield(n, :per_page => n) | |
|
215 | end | |
|
216 | l(:label_display_per_page, links.join(', ')) | |
|
217 | end | |
|
218 | end | |
|
219 | ||
|
220 | def per_page_options(selected=nil, item_count=nil) | |
|
221 | options = Setting.per_page_options_array | |
|
222 | if item_count && options.any? | |
|
223 | if item_count > options.first | |
|
224 | max = options.detect {|value| value >= item_count} || item_count | |
|
215 | 225 | else |
|
216 | 226 | max = item_count |
|
217 | 227 | end |
|
218 |
|
|
|
228 | options = options.select {|value| value <= max || value == selected} | |
|
219 | 229 | end |
|
220 |
if |
|
|
221 |
|
|
|
222 |
e |
|
|
223 | links = values.collect do |n| | |
|
224 | n == selected ? n : yield(n, :per_page => n) | |
|
230 | if options.empty? || (options.size == 1 && options.first == selected) | |
|
231 | [] | |
|
232 | else | |
|
233 | options | |
|
225 | 234 | end |
|
226 | l(:label_display_per_page, links.join(', ')) | |
|
227 | 235 | end |
|
228 | 236 | end |
|
229 | 237 | end |
@@ -1146,19 +1146,4 RAW | |||
|
1146 | 1146 | def test_javascript_include_tag_for_plugin_should_pick_the_plugin_javascript |
|
1147 | 1147 | assert_match 'src="/plugin_assets/foo/javascripts/scripts.js"', javascript_include_tag("scripts", :plugin => :foo) |
|
1148 | 1148 | end |
|
1149 | ||
|
1150 | def test_per_page_links_should_show_usefull_values | |
|
1151 | set_language_if_valid 'en' | |
|
1152 | stubs(:link_to).returns("[link]") | |
|
1153 | ||
|
1154 | with_settings :per_page_options => '10, 25, 50, 100' do | |
|
1155 | assert_nil per_page_links(10, 3) | |
|
1156 | assert_nil per_page_links(25, 3) | |
|
1157 | assert_equal "Per page: 10, [link]", per_page_links(10, 22) | |
|
1158 | assert_equal "Per page: [link], 25", per_page_links(25, 22) | |
|
1159 | assert_equal "Per page: [link], [link], 50", per_page_links(50, 22) | |
|
1160 | assert_equal "Per page: [link], 25, [link]", per_page_links(25, 26) | |
|
1161 | assert_equal "Per page: [link], 25, [link], [link]", per_page_links(25, 120) | |
|
1162 | end | |
|
1163 | end | |
|
1164 | 1149 | end |
General Comments 0
You need to be logged in to leave comments.
Login now