@@ -1,103 +1,100 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 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 | require 'application_controller' |
|
19 | require 'application_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
|||
22 | class ApplicationController; def rescue_action(e) raise e end; end |
|
|||
23 |
|
||||
24 | class ApplicationControllerTest < ActionController::TestCase |
|
21 | class ApplicationControllerTest < ActionController::TestCase | |
25 | include Redmine::I18n |
|
22 | include Redmine::I18n | |
26 |
|
23 | |||
27 | def setup |
|
24 | def setup | |
28 | @controller = ApplicationController.new |
|
25 | @controller = ApplicationController.new | |
29 | @request = ActionController::TestRequest.new |
|
26 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
27 | @response = ActionController::TestResponse.new | |
31 | end |
|
28 | end | |
32 |
|
29 | |||
33 | # check that all language files are valid |
|
30 | # check that all language files are valid | |
34 | def test_localization |
|
31 | def test_localization | |
35 | lang_files_count = Dir["#{Rails.root}/config/locales/*.yml"].size |
|
32 | lang_files_count = Dir["#{Rails.root}/config/locales/*.yml"].size | |
36 | assert_equal lang_files_count, valid_languages.size |
|
33 | assert_equal lang_files_count, valid_languages.size | |
37 | valid_languages.each do |lang| |
|
34 | valid_languages.each do |lang| | |
38 | assert set_language_if_valid(lang) |
|
35 | assert set_language_if_valid(lang) | |
39 | end |
|
36 | end | |
40 | set_language_if_valid('en') |
|
37 | set_language_if_valid('en') | |
41 | end |
|
38 | end | |
42 |
|
39 | |||
43 | def test_call_hook_mixed_in |
|
40 | def test_call_hook_mixed_in | |
44 | assert @controller.respond_to?(:call_hook) |
|
41 | assert @controller.respond_to?(:call_hook) | |
45 | end |
|
42 | end | |
46 |
|
43 | |||
47 | context "test_api_offset_and_limit" do |
|
44 | context "test_api_offset_and_limit" do | |
48 | context "without params" do |
|
45 | context "without params" do | |
49 | should "return 0, 25" do |
|
46 | should "return 0, 25" do | |
50 | assert_equal [0, 25], @controller.api_offset_and_limit({}) |
|
47 | assert_equal [0, 25], @controller.api_offset_and_limit({}) | |
51 | end |
|
48 | end | |
52 | end |
|
49 | end | |
53 |
|
50 | |||
54 | context "with limit" do |
|
51 | context "with limit" do | |
55 | should "return 0, limit" do |
|
52 | should "return 0, limit" do | |
56 | assert_equal [0, 30], @controller.api_offset_and_limit({:limit => 30}) |
|
53 | assert_equal [0, 30], @controller.api_offset_and_limit({:limit => 30}) | |
57 | end |
|
54 | end | |
58 |
|
55 | |||
59 | should "not exceed 100" do |
|
56 | should "not exceed 100" do | |
60 | assert_equal [0, 100], @controller.api_offset_and_limit({:limit => 120}) |
|
57 | assert_equal [0, 100], @controller.api_offset_and_limit({:limit => 120}) | |
61 | end |
|
58 | end | |
62 |
|
59 | |||
63 | should "not be negative" do |
|
60 | should "not be negative" do | |
64 | assert_equal [0, 25], @controller.api_offset_and_limit({:limit => -10}) |
|
61 | assert_equal [0, 25], @controller.api_offset_and_limit({:limit => -10}) | |
65 | end |
|
62 | end | |
66 | end |
|
63 | end | |
67 |
|
64 | |||
68 | context "with offset" do |
|
65 | context "with offset" do | |
69 | should "return offset, 25" do |
|
66 | should "return offset, 25" do | |
70 | assert_equal [10, 25], @controller.api_offset_and_limit({:offset => 10}) |
|
67 | assert_equal [10, 25], @controller.api_offset_and_limit({:offset => 10}) | |
71 | end |
|
68 | end | |
72 |
|
69 | |||
73 | should "not be negative" do |
|
70 | should "not be negative" do | |
74 | assert_equal [0, 25], @controller.api_offset_and_limit({:offset => -10}) |
|
71 | assert_equal [0, 25], @controller.api_offset_and_limit({:offset => -10}) | |
75 | end |
|
72 | end | |
76 |
|
73 | |||
77 | context "and limit" do |
|
74 | context "and limit" do | |
78 | should "return offset, limit" do |
|
75 | should "return offset, limit" do | |
79 | assert_equal [10, 50], @controller.api_offset_and_limit({:offset => 10, :limit => 50}) |
|
76 | assert_equal [10, 50], @controller.api_offset_and_limit({:offset => 10, :limit => 50}) | |
80 | end |
|
77 | end | |
81 | end |
|
78 | end | |
82 | end |
|
79 | end | |
83 |
|
80 | |||
84 | context "with page" do |
|
81 | context "with page" do | |
85 | should "return offset, 25" do |
|
82 | should "return offset, 25" do | |
86 | assert_equal [0, 25], @controller.api_offset_and_limit({:page => 1}) |
|
83 | assert_equal [0, 25], @controller.api_offset_and_limit({:page => 1}) | |
87 | assert_equal [50, 25], @controller.api_offset_and_limit({:page => 3}) |
|
84 | assert_equal [50, 25], @controller.api_offset_and_limit({:page => 3}) | |
88 | end |
|
85 | end | |
89 |
|
86 | |||
90 | should "not be negative" do |
|
87 | should "not be negative" do | |
91 | assert_equal [0, 25], @controller.api_offset_and_limit({:page => 0}) |
|
88 | assert_equal [0, 25], @controller.api_offset_and_limit({:page => 0}) | |
92 | assert_equal [0, 25], @controller.api_offset_and_limit({:page => -2}) |
|
89 | assert_equal [0, 25], @controller.api_offset_and_limit({:page => -2}) | |
93 | end |
|
90 | end | |
94 |
|
91 | |||
95 | context "and limit" do |
|
92 | context "and limit" do | |
96 | should "return offset, limit" do |
|
93 | should "return offset, limit" do | |
97 | assert_equal [0, 100], @controller.api_offset_and_limit({:page => 1, :limit => 100}) |
|
94 | assert_equal [0, 100], @controller.api_offset_and_limit({:page => 1, :limit => 100}) | |
98 | assert_equal [200, 100], @controller.api_offset_and_limit({:page => 3, :limit => 100}) |
|
95 | assert_equal [200, 100], @controller.api_offset_and_limit({:page => 3, :limit => 100}) | |
99 | end |
|
96 | end | |
100 | end |
|
97 | end | |
101 | end |
|
98 | end | |
102 | end |
|
99 | end | |
103 | end |
|
100 | end |
General Comments 0
You need to be logged in to leave comments.
Login now