@@ -654,8 +654,7 class ApplicationController < ActionController::Base | |||
|
654 | 654 | |
|
655 | 655 | # Renders a head API response |
|
656 | 656 | def render_api_head(status) |
|
657 | # #head would return a response body with one space | |
|
658 | render :text => '', :status => status, :layout => nil | |
|
657 | head :status => status | |
|
659 | 658 | end |
|
660 | 659 | |
|
661 | 660 | # Renders API response on validation failure |
@@ -38,7 +38,7 class MailHandlerController < ActionController::Base | |||
|
38 | 38 | def check_credential |
|
39 | 39 | User.current = nil |
|
40 | 40 | unless Setting.mail_handler_api_enabled? && params[:key].to_s == Setting.mail_handler_api_key |
|
41 |
render : |
|
|
41 | render :plain => 'Access denied. Incoming emails WS is disabled or key is invalid.', :status => 403 | |
|
42 | 42 | end |
|
43 | 43 | end |
|
44 | 44 | end |
@@ -74,7 +74,7 class SysController < ActionController::Base | |||
|
74 | 74 | def check_enabled |
|
75 | 75 | User.current = nil |
|
76 | 76 | unless Setting.sys_api_enabled? && params[:key].to_s == Setting.sys_api_key |
|
77 |
render : |
|
|
77 | render :plain => 'Access denied. Repository management WS is disabled or key is invalid.', :status => 403 | |
|
78 | 78 | return false |
|
79 | 79 | end |
|
80 | 80 | end |
@@ -47,7 +47,7 class WatchersController < ApplicationController | |||
|
47 | 47 | end |
|
48 | 48 | end |
|
49 | 49 | respond_to do |format| |
|
50 |
format.html { redirect_to_referer_or {render : |
|
|
50 | format.html { redirect_to_referer_or {render :html => 'Watcher added.', :status => 200, :layout => true}} | |
|
51 | 51 | format.js { @users = users_for_new_watcher } |
|
52 | 52 | format.api { render_api_ok } |
|
53 | 53 | end |
@@ -69,7 +69,7 class WatchersController < ApplicationController | |||
|
69 | 69 | watchable.set_watcher(user, false) |
|
70 | 70 | end |
|
71 | 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 | 73 | format.js |
|
74 | 74 | format.api { render_api_ok } |
|
75 | 75 | end |
@@ -108,7 +108,10 class WatchersController < ApplicationController | |||
|
108 | 108 | watchable.set_watcher(user, watching) |
|
109 | 109 | end |
|
110 | 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 | 115 | format.js { render :partial => 'set_watcher', :locals => {:user => user, :watched => watchables} } |
|
113 | 116 | end |
|
114 | 117 | end |
@@ -74,6 +74,7 class MailHandlerControllerTest < Redmine::ControllerTest | |||
|
74 | 74 | post :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml')) |
|
75 | 75 | end |
|
76 | 76 | assert_response 403 |
|
77 | assert_include 'Access denied', response.body | |
|
77 | 78 | end |
|
78 | 79 | |
|
79 | 80 | def test_should_not_allow_with_wrong_key |
@@ -84,6 +85,7 class MailHandlerControllerTest < Redmine::ControllerTest | |||
|
84 | 85 | post :index, :key => 'wrong', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml')) |
|
85 | 86 | end |
|
86 | 87 | assert_response 403 |
|
88 | assert_include 'Access denied', response.body | |
|
87 | 89 | end |
|
88 | 90 | |
|
89 | 91 | def test_new |
@@ -113,6 +113,7 class SysControllerTest < Redmine::ControllerTest | |||
|
113 | 113 | with_settings :sys_api_enabled => '0' do |
|
114 | 114 | get :projects |
|
115 | 115 | assert_response 403 |
|
116 | assert_include 'Access denied', response.body | |
|
116 | 117 | end |
|
117 | 118 | end |
|
118 | 119 | |
@@ -127,6 +128,7 class SysControllerTest < Redmine::ControllerTest | |||
|
127 | 128 | with_settings :sys_api_enabled => 'my_secret_key' do |
|
128 | 129 | get :projects, :params => {:key => 'wrong_key'} |
|
129 | 130 | assert_response 403 |
|
131 | assert_include 'Access denied', response.body | |
|
130 | 132 | end |
|
131 | 133 | end |
|
132 | 134 | end |
@@ -25,6 +25,16 class WatchersControllerTest < Redmine::ControllerTest | |||
|
25 | 25 | User.current = nil |
|
26 | 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 | 38 | def test_watch_a_single_object |
|
29 | 39 | @request.session[:user_id] = 3 |
|
30 | 40 | assert_difference('Watcher.count') do |
@@ -102,6 +112,16 class WatchersControllerTest < Redmine::ControllerTest | |||
|
102 | 112 | end |
|
103 | 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 | 125 | def test_unwatch |
|
106 | 126 | @request.session[:user_id] = 3 |
|
107 | 127 | assert_difference('Watcher.count', -1) do |
@@ -154,6 +174,19 class WatchersControllerTest < Redmine::ControllerTest | |||
|
154 | 174 | assert_match /ajax-modal/, response.body |
|
155 | 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 | 190 | def test_create |
|
158 | 191 | @request.session[:user_id] = 2 |
|
159 | 192 | assert_difference('Watcher.count') do |
@@ -295,6 +328,18 class WatchersControllerTest < Redmine::ControllerTest | |||
|
295 | 328 | assert response.body.blank? |
|
296 | 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 | 343 | def test_destroy |
|
299 | 344 | @request.session[:user_id] = 2 |
|
300 | 345 | assert_difference('Watcher.count', -1) do |
@@ -44,4 +44,13 class Redmine::ApiTest::ApiTest < Redmine::ApiTest::Base | |||
|
44 | 44 | get '/users/1.xml', {}, credentials('admin') |
|
45 | 45 | assert_include '<created_on>2006-07-19T17:12:21Z</created_on>', response.body |
|
46 | 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 | 56 | end |
General Comments 0
You need to be logged in to leave comments.
Login now