##// END OF EJS Templates
Test failure (#21148)....
Jean-Philippe Lang -
r14499:dc1397c58c9d
parent child
Show More
@@ -1,176 +1,175
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2015 Jean-Philippe Lang
2 # Copyright (C) 2006-2015 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 WelcomeControllerTest < ActionController::TestCase
20 class WelcomeControllerTest < ActionController::TestCase
21 fixtures :projects, :news, :users, :members
21 fixtures :projects, :news, :users, :members
22
22
23 def setup
23 def setup
24 Setting.default_language = 'en'
24 Setting.default_language = 'en'
25 User.current = nil
25 User.current = nil
26 end
26 end
27
27
28 def test_index
28 def test_index
29 get :index
29 get :index
30 assert_response :success
30 assert_response :success
31 assert_template 'index'
31 assert_template 'index'
32 assert_not_nil assigns(:news)
32 assert_not_nil assigns(:news)
33 assert !assigns(:projects).include?(Project.where(:is_public => false).first)
34 end
33 end
35
34
36 def test_browser_language
35 def test_browser_language
37 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
36 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
38 get :index
37 get :index
39 assert_equal :fr, @controller.current_language
38 assert_equal :fr, @controller.current_language
40 end
39 end
41
40
42 def test_browser_language_alternate
41 def test_browser_language_alternate
43 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'zh-TW'
42 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'zh-TW'
44 get :index
43 get :index
45 assert_equal :"zh-TW", @controller.current_language
44 assert_equal :"zh-TW", @controller.current_language
46 end
45 end
47
46
48 def test_browser_language_alternate_not_valid
47 def test_browser_language_alternate_not_valid
49 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr-CA'
48 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr-CA'
50 get :index
49 get :index
51 assert_equal :fr, @controller.current_language
50 assert_equal :fr, @controller.current_language
52 end
51 end
53
52
54 def test_browser_language_should_be_ignored_with_force_default_language_for_anonymous
53 def test_browser_language_should_be_ignored_with_force_default_language_for_anonymous
55 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
54 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
56 with_settings :force_default_language_for_anonymous => '1' do
55 with_settings :force_default_language_for_anonymous => '1' do
57 get :index
56 get :index
58 assert_equal :en, @controller.current_language
57 assert_equal :en, @controller.current_language
59 end
58 end
60 end
59 end
61
60
62 def test_user_language_should_be_used
61 def test_user_language_should_be_used
63 user = User.find(2).update_attribute :language, 'it'
62 user = User.find(2).update_attribute :language, 'it'
64 @request.session[:user_id] = 2
63 @request.session[:user_id] = 2
65 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
64 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
66 with_settings :default_language => 'fi' do
65 with_settings :default_language => 'fi' do
67 get :index
66 get :index
68 assert_equal :it, @controller.current_language
67 assert_equal :it, @controller.current_language
69 end
68 end
70 end
69 end
71
70
72 def test_user_language_should_be_ignored_if_force_default_language_for_loggedin
71 def test_user_language_should_be_ignored_if_force_default_language_for_loggedin
73 user = User.find(2).update_attribute :language, 'it'
72 user = User.find(2).update_attribute :language, 'it'
74 @request.session[:user_id] = 2
73 @request.session[:user_id] = 2
75 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
74 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
76 with_settings :force_default_language_for_loggedin => '1', :default_language => 'fi' do
75 with_settings :force_default_language_for_loggedin => '1', :default_language => 'fi' do
77 get :index
76 get :index
78 assert_equal :fi, @controller.current_language
77 assert_equal :fi, @controller.current_language
79 end
78 end
80 end
79 end
81
80
82 def test_robots
81 def test_robots
83 get :robots
82 get :robots
84 assert_response :success
83 assert_response :success
85 assert_equal 'text/plain', @response.content_type
84 assert_equal 'text/plain', @response.content_type
86 assert @response.body.match(%r{^Disallow: /projects/ecookbook/issues\r?$})
85 assert @response.body.match(%r{^Disallow: /projects/ecookbook/issues\r?$})
87 end
86 end
88
87
89 def test_warn_on_leaving_unsaved_turn_on
88 def test_warn_on_leaving_unsaved_turn_on
90 user = User.find(2)
89 user = User.find(2)
91 user.pref.warn_on_leaving_unsaved = '1'
90 user.pref.warn_on_leaving_unsaved = '1'
92 user.pref.save!
91 user.pref.save!
93 @request.session[:user_id] = 2
92 @request.session[:user_id] = 2
94
93
95 get :index
94 get :index
96 assert_select 'script', :text => %r{warnLeavingUnsaved}
95 assert_select 'script', :text => %r{warnLeavingUnsaved}
97 end
96 end
98
97
99 def test_warn_on_leaving_unsaved_turn_off
98 def test_warn_on_leaving_unsaved_turn_off
100 user = User.find(2)
99 user = User.find(2)
101 user.pref.warn_on_leaving_unsaved = '0'
100 user.pref.warn_on_leaving_unsaved = '0'
102 user.pref.save!
101 user.pref.save!
103 @request.session[:user_id] = 2
102 @request.session[:user_id] = 2
104
103
105 get :index
104 get :index
106 assert_select 'script', :text => %r{warnLeavingUnsaved}, :count => 0
105 assert_select 'script', :text => %r{warnLeavingUnsaved}, :count => 0
107 end
106 end
108
107
109 def test_logout_link_should_post
108 def test_logout_link_should_post
110 @request.session[:user_id] = 2
109 @request.session[:user_id] = 2
111
110
112 get :index
111 get :index
113 assert_select 'a[href="/logout"][data-method=post]', :text => 'Sign out'
112 assert_select 'a[href="/logout"][data-method=post]', :text => 'Sign out'
114 end
113 end
115
114
116 def test_call_hook_mixed_in
115 def test_call_hook_mixed_in
117 assert @controller.respond_to?(:call_hook)
116 assert @controller.respond_to?(:call_hook)
118 end
117 end
119
118
120 def test_project_jump_box_should_escape_names_once
119 def test_project_jump_box_should_escape_names_once
121 Project.find(1).update_attribute :name, 'Foo & Bar'
120 Project.find(1).update_attribute :name, 'Foo & Bar'
122 @request.session[:user_id] = 2
121 @request.session[:user_id] = 2
123
122
124 get :index
123 get :index
125 assert_select "#header select" do
124 assert_select "#header select" do
126 assert_select "option", :text => 'Foo & Bar'
125 assert_select "option", :text => 'Foo & Bar'
127 end
126 end
128 end
127 end
129
128
130 def test_api_offset_and_limit_without_params
129 def test_api_offset_and_limit_without_params
131 assert_equal [0, 25], @controller.api_offset_and_limit({})
130 assert_equal [0, 25], @controller.api_offset_and_limit({})
132 end
131 end
133
132
134 def test_api_offset_and_limit_with_limit
133 def test_api_offset_and_limit_with_limit
135 assert_equal [0, 30], @controller.api_offset_and_limit({:limit => 30})
134 assert_equal [0, 30], @controller.api_offset_and_limit({:limit => 30})
136 assert_equal [0, 100], @controller.api_offset_and_limit({:limit => 120})
135 assert_equal [0, 100], @controller.api_offset_and_limit({:limit => 120})
137 assert_equal [0, 25], @controller.api_offset_and_limit({:limit => -10})
136 assert_equal [0, 25], @controller.api_offset_and_limit({:limit => -10})
138 end
137 end
139
138
140 def test_api_offset_and_limit_with_offset
139 def test_api_offset_and_limit_with_offset
141 assert_equal [10, 25], @controller.api_offset_and_limit({:offset => 10})
140 assert_equal [10, 25], @controller.api_offset_and_limit({:offset => 10})
142 assert_equal [0, 25], @controller.api_offset_and_limit({:offset => -10})
141 assert_equal [0, 25], @controller.api_offset_and_limit({:offset => -10})
143 end
142 end
144
143
145 def test_api_offset_and_limit_with_offset_and_limit
144 def test_api_offset_and_limit_with_offset_and_limit
146 assert_equal [10, 50], @controller.api_offset_and_limit({:offset => 10, :limit => 50})
145 assert_equal [10, 50], @controller.api_offset_and_limit({:offset => 10, :limit => 50})
147 end
146 end
148
147
149 def test_api_offset_and_limit_with_page
148 def test_api_offset_and_limit_with_page
150 assert_equal [0, 25], @controller.api_offset_and_limit({:page => 1})
149 assert_equal [0, 25], @controller.api_offset_and_limit({:page => 1})
151 assert_equal [50, 25], @controller.api_offset_and_limit({:page => 3})
150 assert_equal [50, 25], @controller.api_offset_and_limit({:page => 3})
152 assert_equal [0, 25], @controller.api_offset_and_limit({:page => 0})
151 assert_equal [0, 25], @controller.api_offset_and_limit({:page => 0})
153 assert_equal [0, 25], @controller.api_offset_and_limit({:page => -2})
152 assert_equal [0, 25], @controller.api_offset_and_limit({:page => -2})
154 end
153 end
155
154
156 def test_api_offset_and_limit_with_page_and_limit
155 def test_api_offset_and_limit_with_page_and_limit
157 assert_equal [0, 100], @controller.api_offset_and_limit({:page => 1, :limit => 100})
156 assert_equal [0, 100], @controller.api_offset_and_limit({:page => 1, :limit => 100})
158 assert_equal [200, 100], @controller.api_offset_and_limit({:page => 3, :limit => 100})
157 assert_equal [200, 100], @controller.api_offset_and_limit({:page => 3, :limit => 100})
159 end
158 end
160
159
161 def test_unhautorized_exception_with_anonymous_should_redirect_to_login
160 def test_unhautorized_exception_with_anonymous_should_redirect_to_login
162 WelcomeController.any_instance.stubs(:index).raises(::Unauthorized)
161 WelcomeController.any_instance.stubs(:index).raises(::Unauthorized)
163
162
164 get :index
163 get :index
165 assert_response 302
164 assert_response 302
166 assert_redirected_to('/login?back_url='+CGI.escape('http://test.host/'))
165 assert_redirected_to('/login?back_url='+CGI.escape('http://test.host/'))
167 end
166 end
168
167
169 def test_unhautorized_exception_with_anonymous_and_xmlhttprequest_should_respond_with_401_to_anonymous
168 def test_unhautorized_exception_with_anonymous_and_xmlhttprequest_should_respond_with_401_to_anonymous
170 WelcomeController.any_instance.stubs(:index).raises(::Unauthorized)
169 WelcomeController.any_instance.stubs(:index).raises(::Unauthorized)
171
170
172 @request.env["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest"
171 @request.env["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest"
173 get :index
172 get :index
174 assert_response 401
173 assert_response 401
175 end
174 end
176 end
175 end
General Comments 0
You need to be logged in to leave comments. Login now