##// END OF EJS Templates
Don't use render :text => ""....
Jean-Philippe Lang -
r15349:8b107b605825
parent child
Show More
@@ -654,8 +654,7 class ApplicationController < ActionController::Base
654
654
655 # Renders a head API response
655 # Renders a head API response
656 def render_api_head(status)
656 def render_api_head(status)
657 # #head would return a response body with one space
657 head :status => status
658 render :text => '', :status => status, :layout => nil
659 end
658 end
660
659
661 # Renders API response on validation failure
660 # Renders API response on validation failure
@@ -38,7 +38,7 class MailHandlerController < ActionController::Base
38 def check_credential
38 def check_credential
39 User.current = nil
39 User.current = nil
40 unless Setting.mail_handler_api_enabled? && params[:key].to_s == Setting.mail_handler_api_key
40 unless Setting.mail_handler_api_enabled? && params[:key].to_s == Setting.mail_handler_api_key
41 render :text => 'Access denied. Incoming emails WS is disabled or key is invalid.', :status => 403
41 render :plain => 'Access denied. Incoming emails WS is disabled or key is invalid.', :status => 403
42 end
42 end
43 end
43 end
44 end
44 end
@@ -74,7 +74,7 class SysController < ActionController::Base
74 def check_enabled
74 def check_enabled
75 User.current = nil
75 User.current = nil
76 unless Setting.sys_api_enabled? && params[:key].to_s == Setting.sys_api_key
76 unless Setting.sys_api_enabled? && params[:key].to_s == Setting.sys_api_key
77 render :text => 'Access denied. Repository management WS is disabled or key is invalid.', :status => 403
77 render :plain => 'Access denied. Repository management WS is disabled or key is invalid.', :status => 403
78 return false
78 return false
79 end
79 end
80 end
80 end
@@ -47,7 +47,7 class WatchersController < ApplicationController
47 end
47 end
48 end
48 end
49 respond_to do |format|
49 respond_to do |format|
50 format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
50 format.html { redirect_to_referer_or {render :html => 'Watcher added.', :status => 200, :layout => true}}
51 format.js { @users = users_for_new_watcher }
51 format.js { @users = users_for_new_watcher }
52 format.api { render_api_ok }
52 format.api { render_api_ok }
53 end
53 end
@@ -69,7 +69,7 class WatchersController < ApplicationController
69 watchable.set_watcher(user, false)
69 watchable.set_watcher(user, false)
70 end
70 end
71 respond_to do |format|
71 respond_to do |format|
72 format.html { redirect_to :back }
72 format.html { redirect_to_referer_or {render :html => 'Watcher removed.', :status => 200, :layout => true} }
73 format.js
73 format.js
74 format.api { render_api_ok }
74 format.api { render_api_ok }
75 end
75 end
@@ -108,7 +108,10 class WatchersController < ApplicationController
108 watchable.set_watcher(user, watching)
108 watchable.set_watcher(user, watching)
109 end
109 end
110 respond_to do |format|
110 respond_to do |format|
111 format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
111 format.html {
112 text = watching ? 'Watcher added.' : 'Watcher removed.'
113 redirect_to_referer_or {render :html => text, :status => 200, :layout => true}
114 }
112 format.js { render :partial => 'set_watcher', :locals => {:user => user, :watched => watchables} }
115 format.js { render :partial => 'set_watcher', :locals => {:user => user, :watched => watchables} }
113 end
116 end
114 end
117 end
@@ -74,6 +74,7 class MailHandlerControllerTest < Redmine::ControllerTest
74 post :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
74 post :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
75 end
75 end
76 assert_response 403
76 assert_response 403
77 assert_include 'Access denied', response.body
77 end
78 end
78
79
79 def test_should_not_allow_with_wrong_key
80 def test_should_not_allow_with_wrong_key
@@ -84,6 +85,7 class MailHandlerControllerTest < Redmine::ControllerTest
84 post :index, :key => 'wrong', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
85 post :index, :key => 'wrong', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
85 end
86 end
86 assert_response 403
87 assert_response 403
88 assert_include 'Access denied', response.body
87 end
89 end
88
90
89 def test_new
91 def test_new
@@ -113,6 +113,7 class SysControllerTest < Redmine::ControllerTest
113 with_settings :sys_api_enabled => '0' do
113 with_settings :sys_api_enabled => '0' do
114 get :projects
114 get :projects
115 assert_response 403
115 assert_response 403
116 assert_include 'Access denied', response.body
116 end
117 end
117 end
118 end
118
119
@@ -127,6 +128,7 class SysControllerTest < Redmine::ControllerTest
127 with_settings :sys_api_enabled => 'my_secret_key' do
128 with_settings :sys_api_enabled => 'my_secret_key' do
128 get :projects, :params => {:key => 'wrong_key'}
129 get :projects, :params => {:key => 'wrong_key'}
129 assert_response 403
130 assert_response 403
131 assert_include 'Access denied', response.body
130 end
132 end
131 end
133 end
132 end
134 end
@@ -25,6 +25,16 class WatchersControllerTest < Redmine::ControllerTest
25 User.current = nil
25 User.current = nil
26 end
26 end
27
27
28 def test_watch_a_single_object_as_html
29 @request.session[:user_id] = 3
30 assert_difference('Watcher.count') do
31 post :watch, :params => {:object_type => 'issue', :object_id => '1'}
32 assert_response :success
33 assert_include 'Watcher added', response.body
34 end
35 assert Issue.find(1).watched_by?(User.find(3))
36 end
37
28 def test_watch_a_single_object
38 def test_watch_a_single_object
29 @request.session[:user_id] = 3
39 @request.session[:user_id] = 3
30 assert_difference('Watcher.count') do
40 assert_difference('Watcher.count') do
@@ -102,6 +112,16 class WatchersControllerTest < Redmine::ControllerTest
102 end
112 end
103 end
113 end
104
114
115 def test_unwatch_as_html
116 @request.session[:user_id] = 3
117 assert_difference('Watcher.count', -1) do
118 delete :unwatch, :params => {:object_type => 'issue', :object_id => '2'}
119 assert_response :success
120 assert_include 'Watcher removed', response.body
121 end
122 assert !Issue.find(1).watched_by?(User.find(3))
123 end
124
105 def test_unwatch
125 def test_unwatch
106 @request.session[:user_id] = 3
126 @request.session[:user_id] = 3
107 assert_difference('Watcher.count', -1) do
127 assert_difference('Watcher.count', -1) do
@@ -154,6 +174,19 class WatchersControllerTest < Redmine::ControllerTest
154 assert_match /ajax-modal/, response.body
174 assert_match /ajax-modal/, response.body
155 end
175 end
156
176
177 def test_create_as_html
178 @request.session[:user_id] = 2
179 assert_difference('Watcher.count') do
180 post :create, :params => {
181 :object_type => 'issue', :object_id => '2',
182 :watcher => {:user_id => '4'}
183 }
184 assert_response :success
185 assert_include 'Watcher added', response.body
186 end
187 assert Issue.find(2).watched_by?(User.find(4))
188 end
189
157 def test_create
190 def test_create
158 @request.session[:user_id] = 2
191 @request.session[:user_id] = 2
159 assert_difference('Watcher.count') do
192 assert_difference('Watcher.count') do
@@ -295,6 +328,18 class WatchersControllerTest < Redmine::ControllerTest
295 assert response.body.blank?
328 assert response.body.blank?
296 end
329 end
297
330
331 def test_destroy_as_html
332 @request.session[:user_id] = 2
333 assert_difference('Watcher.count', -1) do
334 delete :destroy, :params => {
335 :object_type => 'issue', :object_id => '2', :user_id => '3'
336 }
337 assert_response :success
338 assert_include 'Watcher removed', response.body
339 end
340 assert !Issue.find(2).watched_by?(User.find(3))
341 end
342
298 def test_destroy
343 def test_destroy
299 @request.session[:user_id] = 2
344 @request.session[:user_id] = 2
300 assert_difference('Watcher.count', -1) do
345 assert_difference('Watcher.count', -1) do
@@ -44,4 +44,13 class Redmine::ApiTest::ApiTest < Redmine::ApiTest::Base
44 get '/users/1.xml', {}, credentials('admin')
44 get '/users/1.xml', {}, credentials('admin')
45 assert_include '<created_on>2006-07-19T17:12:21Z</created_on>', response.body
45 assert_include '<created_on>2006-07-19T17:12:21Z</created_on>', response.body
46 end
46 end
47
48 def test_head_response_should_have_empty_body
49 assert_difference('Issue.count', -1) do
50 delete '/issues/6.xml', {}, credentials('jsmith')
51
52 assert_response :ok
53 assert_equal '', response.body
54 end
55 end
47 end
56 end
General Comments 0
You need to be logged in to leave comments. Login now