Fixed that 200 API responses have a body containing one space (#11388).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9975 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-07-14 08:13:55 +00:00
parent 6bf60e8c20
commit 18f693f9f7
19 changed files with 48 additions and 19 deletions

View File

@ -520,6 +520,12 @@ class ApplicationController < ActionController::Base
render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator." render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
end end
# Renders a 200 response for successfull updates or deletions via the API
def render_api_ok
# head :ok would return a response body with one space
render :text => '', :status => :ok, :layout => nil
end
# Renders API response on validation failure # Renders API response on validation failure
def render_validation_errors(objects) def render_validation_errors(objects)
if objects.is_a?(Array) if objects.is_a?(Array)

View File

@ -72,7 +72,7 @@ class GroupsController < ApplicationController
if @group.save if @group.save
flash[:notice] = l(:notice_successful_update) flash[:notice] = l(:notice_successful_update)
format.html { redirect_to(groups_path) } format.html { redirect_to(groups_path) }
format.api { head :ok } format.api { render_api_ok }
else else
format.html { render :action => "edit" } format.html { render :action => "edit" }
format.api { render_validation_errors(@group) } format.api { render_validation_errors(@group) }
@ -85,7 +85,7 @@ class GroupsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html { redirect_to(groups_url) } format.html { redirect_to(groups_url) }
format.api { head :ok } format.api { render_api_ok }
end end
end end
@ -100,7 +100,7 @@ class GroupsController < ApplicationController
users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") } users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") }
} }
} }
format.api { head :ok } format.api { render_api_ok }
end end
end end
@ -109,7 +109,7 @@ class GroupsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} } format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} }
format.api { head :ok } format.api { render_api_ok }
end end
end end

View File

@ -98,7 +98,7 @@ class IssueCategoriesController < ApplicationController
flash[:notice] = l(:notice_successful_update) flash[:notice] = l(:notice_successful_update)
redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
} }
format.api { head :ok } format.api { render_api_ok }
end end
else else
respond_to do |format| respond_to do |format|
@ -118,7 +118,7 @@ class IssueCategoriesController < ApplicationController
@category.destroy(reassign_to) @category.destroy(reassign_to)
respond_to do |format| respond_to do |format|
format.html { redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories' } format.html { redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories' }
format.api { head :ok } format.api { render_api_ok }
end end
return return
end end

View File

@ -76,7 +76,7 @@ class IssueRelationsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html { redirect_to issue_path } # TODO : does this really work since @issue is always nil? What is it useful to? format.html { redirect_to issue_path } # TODO : does this really work since @issue is always nil? What is it useful to?
format.js { render(:update) {|page| page.remove "relation-#{@relation.id}"} } format.js { render(:update) {|page| page.remove "relation-#{@relation.id}"} }
format.api { head :ok } format.api { render_api_ok }
end end
end end

View File

@ -197,7 +197,7 @@ class IssuesController < ApplicationController
respond_to do |format| respond_to do |format|
format.html { redirect_back_or_default({:action => 'show', :id => @issue}) } format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
format.api { head :ok } format.api { render_api_ok }
end end
else else
respond_to do |format| respond_to do |format|
@ -307,7 +307,7 @@ class IssuesController < ApplicationController
end end
respond_to do |format| respond_to do |format|
format.html { redirect_back_or_default(:action => 'index', :project_id => @project) } format.html { redirect_back_or_default(:action => 'index', :project_id => @project) }
format.api { head :ok } format.api { render_api_ok }
end end
end end

View File

@ -107,7 +107,7 @@ class MembersController < ApplicationController
} }
format.api { format.api {
if saved if saved
head :ok render_api_ok
else else
render_validation_errors(@member) render_validation_errors(@member)
end end
@ -128,7 +128,7 @@ class MembersController < ApplicationController
} }
format.api { format.api {
if @member.destroyed? if @member.destroyed?
head :ok render_api_ok
else else
head :unprocessable_entity head :unprocessable_entity
end end

View File

@ -191,7 +191,7 @@ class ProjectsController < ApplicationController
flash[:notice] = l(:notice_successful_update) flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'settings', :id => @project redirect_to :action => 'settings', :id => @project
} }
format.api { head :ok } format.api { render_api_ok }
end end
else else
respond_to do |format| respond_to do |format|
@ -241,7 +241,7 @@ class ProjectsController < ApplicationController
@project_to_destroy.destroy @project_to_destroy.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to :controller => 'admin', :action => 'projects' } format.html { redirect_to :controller => 'admin', :action => 'projects' }
format.api { head :ok } format.api { render_api_ok }
end end
end end
# hide project in layout # hide project in layout

View File

@ -171,7 +171,7 @@ class TimelogController < ApplicationController
flash[:notice] = l(:notice_successful_update) flash[:notice] = l(:notice_successful_update)
redirect_back_or_default :action => 'index', :project_id => @time_entry.project redirect_back_or_default :action => 'index', :project_id => @time_entry.project
} }
format.api { head :ok } format.api { render_api_ok }
end end
else else
respond_to do |format| respond_to do |format|
@ -223,7 +223,7 @@ class TimelogController < ApplicationController
} }
format.api { format.api {
if destroyed if destroyed
head :ok render_api_ok
else else
render_validation_errors(@time_entries) render_validation_errors(@time_entries)
end end

View File

@ -156,7 +156,7 @@ class UsersController < ApplicationController
flash[:notice] = l(:notice_successful_update) flash[:notice] = l(:notice_successful_update)
redirect_to_referer_or edit_user_path(@user) redirect_to_referer_or edit_user_path(@user)
} }
format.api { head :ok } format.api { render_api_ok }
end end
else else
@auth_sources = AuthSource.find(:all) @auth_sources = AuthSource.find(:all)
@ -175,7 +175,7 @@ class UsersController < ApplicationController
@user.destroy @user.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to_referer_or(users_url) } format.html { redirect_to_referer_or(users_url) }
format.api { head :ok } format.api { render_api_ok }
end end
end end

View File

@ -144,7 +144,7 @@ class VersionsController < ApplicationController
flash[:notice] = l(:notice_successful_update) flash[:notice] = l(:notice_successful_update)
redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
} }
format.api { head :ok } format.api { render_api_ok }
end end
else else
respond_to do |format| respond_to do |format|
@ -167,7 +167,7 @@ class VersionsController < ApplicationController
@version.destroy @version.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project } format.html { redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project }
format.api { head :ok } format.api { render_api_ok }
end end
else else
respond_to do |format| respond_to do |format|

View File

@ -148,6 +148,7 @@ class ApiTest::GroupsTest < ActionController::IntegrationTest
should "update the group" do should "update the group" do
put '/groups/10.xml', {:group => {:name => 'New name', :user_ids => [2, 3]}}, credentials('admin') put '/groups/10.xml', {:group => {:name => 'New name', :user_ids => [2, 3]}}, credentials('admin')
assert_response :ok assert_response :ok
assert_equal '', @response.body
group = Group.find(10) group = Group.find(10)
assert_equal 'New name', group.name assert_equal 'New name', group.name
@ -177,6 +178,7 @@ class ApiTest::GroupsTest < ActionController::IntegrationTest
assert_difference 'Group.count', -1 do assert_difference 'Group.count', -1 do
delete '/groups/10.xml', {}, credentials('admin') delete '/groups/10.xml', {}, credentials('admin')
assert_response :ok assert_response :ok
assert_equal '', @response.body
end end
end end
end end
@ -188,6 +190,7 @@ class ApiTest::GroupsTest < ActionController::IntegrationTest
assert_difference 'Group.find(10).users.count' do assert_difference 'Group.find(10).users.count' do
post '/groups/10/users.xml', {:user_id => 5}, credentials('admin') post '/groups/10/users.xml', {:user_id => 5}, credentials('admin')
assert_response :ok assert_response :ok
assert_equal '', @response.body
end end
assert_include User.find(5), Group.find(10).users assert_include User.find(5), Group.find(10).users
end end
@ -200,6 +203,7 @@ class ApiTest::GroupsTest < ActionController::IntegrationTest
assert_difference 'Group.find(10).users.count', -1 do assert_difference 'Group.find(10).users.count', -1 do
delete '/groups/10/users/8.xml', {}, credentials('admin') delete '/groups/10/users/8.xml', {}, credentials('admin')
assert_response :ok assert_response :ok
assert_equal '', @response.body
end end
assert_not_include User.find(8), Group.find(10).users assert_not_include User.find(8), Group.find(10).users
end end

View File

@ -81,6 +81,7 @@ class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest
put '/issue_categories/2.xml', {:issue_category => {:name => 'API Update'}}, credentials('jsmith') put '/issue_categories/2.xml', {:issue_category => {:name => 'API Update'}}, credentials('jsmith')
end end
assert_response :ok assert_response :ok
assert_equal '', @response.body
assert_equal 'API Update', IssueCategory.find(2).name assert_equal 'API Update', IssueCategory.find(2).name
end end
end end
@ -104,6 +105,7 @@ class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest
delete '/issue_categories/1.xml', {}, credentials('jsmith') delete '/issue_categories/1.xml', {}, credentials('jsmith')
end end
assert_response :ok assert_response :ok
assert_equal '', @response.body
assert_nil IssueCategory.find_by_id(1) assert_nil IssueCategory.find_by_id(1)
end end
@ -117,6 +119,7 @@ class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest
end end
end end
assert_response :ok assert_response :ok
assert_equal '', @response.body
assert_nil IssueCategory.find_by_id(1) assert_nil IssueCategory.find_by_id(1)
end end
end end

View File

@ -99,6 +99,7 @@ class ApiTest::IssueRelationsTest < ActionController::IntegrationTest
end end
assert_response :ok assert_response :ok
assert_equal '', @response.body
assert_nil IssueRelation.find_by_id(2) assert_nil IssueRelation.find_by_id(2)
end end
end end

View File

@ -770,6 +770,7 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
{:issue => {:notes => 'Attachment added', :uploads => [{:token => token, :filename => 'test.txt', :content_type => 'text/plain'}]}}, {:issue => {:notes => 'Attachment added', :uploads => [{:token => token, :filename => 'test.txt', :content_type => 'text/plain'}]}},
credentials('jsmith') credentials('jsmith')
assert_response :ok assert_response :ok
assert_equal '', @response.body
end end
issue = Issue.find(1) issue = Issue.find(1)

View File

@ -157,6 +157,7 @@ class ApiTest::MembershipsTest < ActionController::IntegrationTest
put '/memberships/2.xml', {:membership => {:user_id => 3, :role_ids => [1,2]}}, credentials('jsmith') put '/memberships/2.xml', {:membership => {:user_id => 3, :role_ids => [1,2]}}, credentials('jsmith')
assert_response :ok assert_response :ok
assert_equal '', @response.body
end end
member = Member.find(2) member = Member.find(2)
assert_equal [1,2], member.role_ids.sort assert_equal [1,2], member.role_ids.sort
@ -179,6 +180,7 @@ class ApiTest::MembershipsTest < ActionController::IntegrationTest
delete '/memberships/2.xml', {}, credentials('jsmith') delete '/memberships/2.xml', {}, credentials('jsmith')
assert_response :ok assert_response :ok
assert_equal '', @response.body
end end
assert_nil Member.find_by_id(2) assert_nil Member.find_by_id(2)
end end

View File

@ -226,6 +226,7 @@ class ApiTest::ProjectsTest < ActionController::IntegrationTest
put '/projects/2.xml', @parameters, credentials('jsmith') put '/projects/2.xml', @parameters, credentials('jsmith')
end end
assert_response :ok assert_response :ok
assert_equal '', @response.body
assert_equal 'application/xml', @response.content_type assert_equal 'application/xml', @response.content_type
project = Project.find(2) project = Project.find(2)
assert_equal 'API update', project.name assert_equal 'API update', project.name
@ -238,6 +239,7 @@ class ApiTest::ProjectsTest < ActionController::IntegrationTest
put '/projects/2.xml', @parameters, credentials('admin') put '/projects/2.xml', @parameters, credentials('admin')
end end
assert_response :ok assert_response :ok
assert_equal '', @response.body
project = Project.find(2) project = Project.find(2)
assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
end end
@ -249,6 +251,7 @@ class ApiTest::ProjectsTest < ActionController::IntegrationTest
put '/projects/2.xml', @parameters, credentials('admin') put '/projects/2.xml', @parameters, credentials('admin')
end end
assert_response :ok assert_response :ok
assert_equal '', @response.body
project = Project.find(2) project = Project.find(2)
assert_equal [1, 3], project.trackers.map(&:id).sort assert_equal [1, 3], project.trackers.map(&:id).sort
end end
@ -286,6 +289,7 @@ class ApiTest::ProjectsTest < ActionController::IntegrationTest
delete '/projects/2.xml', {}, credentials('admin') delete '/projects/2.xml', {}, credentials('admin')
end end
assert_response :ok assert_response :ok
assert_equal '', @response.body
assert_nil Project.find_by_id(2) assert_nil Project.find_by_id(2)
end end
end end

View File

@ -134,6 +134,7 @@ class ApiTest::TimeEntriesTest < ActionController::IntegrationTest
put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, credentials('jsmith') put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, credentials('jsmith')
end end
assert_response :ok assert_response :ok
assert_equal '', @response.body
assert_equal 'API Update', TimeEntry.find(2).comments assert_equal 'API Update', TimeEntry.find(2).comments
end end
end end
@ -157,6 +158,7 @@ class ApiTest::TimeEntriesTest < ActionController::IntegrationTest
delete '/time_entries/2.xml', {}, credentials('jsmith') delete '/time_entries/2.xml', {}, credentials('jsmith')
end end
assert_response :ok assert_response :ok
assert_equal '', @response.body
assert_nil TimeEntry.find_by_id(2) assert_nil TimeEntry.find_by_id(2)
end end
end end

View File

@ -238,6 +238,7 @@ class ApiTest::UsersTest < ActionController::IntegrationTest
assert !user.admin? assert !user.admin?
assert_response :ok assert_response :ok
assert_equal '', @response.body
end end
end end
@ -263,6 +264,7 @@ class ApiTest::UsersTest < ActionController::IntegrationTest
assert !user.admin? assert !user.admin?
assert_response :ok assert_response :ok
assert_equal '', @response.body
end end
end end
end end
@ -322,6 +324,7 @@ class ApiTest::UsersTest < ActionController::IntegrationTest
end end
assert_response :ok assert_response :ok
assert_equal '', @response.body
end end
end end
@ -337,6 +340,7 @@ class ApiTest::UsersTest < ActionController::IntegrationTest
end end
assert_response :ok assert_response :ok
assert_equal '', @response.body
end end
end end
end end

View File

@ -120,6 +120,7 @@ class ApiTest::VersionsTest < ActionController::IntegrationTest
put '/versions/2.xml', {:version => {:name => 'API update'}}, credentials('jsmith') put '/versions/2.xml', {:version => {:name => 'API update'}}, credentials('jsmith')
assert_response :ok assert_response :ok
assert_equal '', @response.body
assert_equal 'API update', Version.find(2).name assert_equal 'API update', Version.find(2).name
end end
end end
@ -131,6 +132,7 @@ class ApiTest::VersionsTest < ActionController::IntegrationTest
end end
assert_response :ok assert_response :ok
assert_equal '', @response.body
assert_nil Version.find_by_id(3) assert_nil Version.find_by_id(3)
end end
end end