Commit 94a8486d authored by maeda's avatar maeda

Ajax Request Returns 200 but an error event is fired instead of success (#30073).

Patch by Pavel Rosický.


git-svn-id: https://svn.redmine.org/redmine/trunk@17849 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 91a81c07
...@@ -657,9 +657,9 @@ class ApplicationController < ActionController::Base ...@@ -657,9 +657,9 @@ 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 successful updates or deletions via the API # Renders a 204 response for successful updates or deletions via the API
def render_api_ok def render_api_ok
render_api_head :ok render_api_head :no_content
end end
# Renders a head API response # Renders a head API response
......
...@@ -49,7 +49,7 @@ class Redmine::ApiTest::ApiTest < Redmine::ApiTest::Base ...@@ -49,7 +49,7 @@ class Redmine::ApiTest::ApiTest < Redmine::ApiTest::Base
def test_head_response_should_have_empty_body def test_head_response_should_have_empty_body
put '/users/7.xml', :params => {:user => {:login => 'foo'}}, :headers => credentials('admin') put '/users/7.xml', :params => {:user => {:login => 'foo'}}, :headers => credentials('admin')
assert_response :ok assert_response :no_content
assert_equal '', response.body assert_equal '', response.body
end end
end end
...@@ -84,7 +84,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base ...@@ -84,7 +84,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
test "DELETE /attachments/:id.xml should return ok and delete Attachment" do test "DELETE /attachments/:id.xml should return ok and delete Attachment" do
assert_difference 'Attachment.count', -1 do assert_difference 'Attachment.count', -1 do
delete '/attachments/7.xml', :headers => credentials('jsmith') delete '/attachments/7.xml', :headers => credentials('jsmith')
assert_response :ok assert_response :no_content
assert_equal '', response.body assert_equal '', response.body
end end
assert_nil Attachment.find_by_id(7) assert_nil Attachment.find_by_id(7)
...@@ -93,7 +93,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base ...@@ -93,7 +93,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
test "DELETE /attachments/:id.json should return ok and delete Attachment" do test "DELETE /attachments/:id.json should return ok and delete Attachment" do
assert_difference 'Attachment.count', -1 do assert_difference 'Attachment.count', -1 do
delete '/attachments/7.json', :headers => credentials('jsmith') delete '/attachments/7.json', :headers => credentials('jsmith')
assert_response :ok assert_response :no_content
assert_equal '', response.body assert_equal '', response.body
end end
assert_nil Attachment.find_by_id(7) assert_nil Attachment.find_by_id(7)
...@@ -104,8 +104,8 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base ...@@ -104,8 +104,8 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
:params => {:attachment => {:filename => 'renamed.zip', :description => 'updated'}}, :params => {:attachment => {:filename => 'renamed.zip', :description => 'updated'}},
:headers => credentials('jsmith') :headers => credentials('jsmith')
assert_response :ok assert_response :no_content
assert_equal 'application/json', response.content_type assert_nil response.content_type
attachment = Attachment.find(7) attachment = Attachment.find(7)
assert_equal 'renamed.zip', attachment.filename assert_equal 'renamed.zip', attachment.filename
assert_equal 'updated', attachment.description assert_equal 'updated', attachment.description
......
...@@ -157,7 +157,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base ...@@ -157,7 +157,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
put "/groups/#{group.id}.xml", put "/groups/#{group.id}.xml",
:params => {:group => {:name => 'New name', :user_ids => [2, 3]}}, :params => {:group => {:name => 'New name', :user_ids => [2, 3]}},
:headers => credentials('admin') :headers => credentials('admin')
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
assert_equal 'New name', group.reload.name assert_equal 'New name', group.reload.name
...@@ -181,7 +181,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base ...@@ -181,7 +181,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
group = Group.generate! group = Group.generate!
assert_difference 'Group.count', -1 do assert_difference 'Group.count', -1 do
delete "/groups/#{group.id}.xml", :headers => credentials('admin') delete "/groups/#{group.id}.xml", :headers => credentials('admin')
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
end end
end end
...@@ -192,7 +192,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base ...@@ -192,7 +192,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
post "/groups/#{group.id}/users.xml", post "/groups/#{group.id}/users.xml",
:params => {:user_id => 5}, :params => {:user_id => 5},
:headers => credentials('admin') :headers => credentials('admin')
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
end end
assert_include User.find(5), group.reload.users assert_include User.find(5), group.reload.users
...@@ -220,7 +220,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base ...@@ -220,7 +220,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
assert_difference 'group.reload.users.count', -1 do assert_difference 'group.reload.users.count', -1 do
delete "/groups/#{group.id}/users/8.xml", :headers => credentials('admin') delete "/groups/#{group.id}/users/8.xml", :headers => credentials('admin')
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
end end
assert_not_include User.find(8), group.reload.users assert_not_include User.find(8), group.reload.users
......
...@@ -70,7 +70,7 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base ...@@ -70,7 +70,7 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
:params => {:issue_category => {:name => 'API Update'}}, :params => {:issue_category => {:name => 'API Update'}},
:headers => credentials('jsmith') :headers => credentials('jsmith')
end end
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
assert_equal 'API Update', IssueCategory.find(2).name assert_equal 'API Update', IssueCategory.find(2).name
end end
...@@ -91,7 +91,7 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base ...@@ -91,7 +91,7 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
assert_difference 'IssueCategory.count', -1 do assert_difference 'IssueCategory.count', -1 do
delete '/issue_categories/1.xml', :headers => credentials('jsmith') delete '/issue_categories/1.xml', :headers => credentials('jsmith')
end end
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
assert_nil IssueCategory.find_by_id(1) assert_nil IssueCategory.find_by_id(1)
end end
...@@ -107,7 +107,7 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base ...@@ -107,7 +107,7 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
:headers => credentials('jsmith') :headers => credentials('jsmith')
end end
end end
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
assert_nil IssueCategory.find_by_id(1) assert_nil IssueCategory.find_by_id(1)
end end
......
...@@ -77,7 +77,7 @@ class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base ...@@ -77,7 +77,7 @@ class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base
delete '/relations/2.xml', :headers => credentials('jsmith') delete '/relations/2.xml', :headers => credentials('jsmith')
end end
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
assert_nil IssueRelation.find_by_id(2) assert_nil IssueRelation.find_by_id(2)
end end
......
...@@ -795,7 +795,7 @@ JSON ...@@ -795,7 +795,7 @@ JSON
:params => {:issue => {:subject => 'API update', :notes => 'A new note'}}, :params => {:issue => {:subject => 'API update', :notes => 'A new note'}},
:headers => credentials('jsmith') :headers => credentials('jsmith')
assert_response :ok assert_response :no_content
assert_equal '', response.body assert_equal '', response.body
end end
...@@ -819,7 +819,7 @@ JSON ...@@ -819,7 +819,7 @@ JSON
assert_difference('Issue.count', -1) do assert_difference('Issue.count', -1) do
delete '/issues/6.xml', :headers => credentials('jsmith') delete '/issues/6.xml', :headers => credentials('jsmith')
assert_response :ok assert_response :no_content
assert_equal '', response.body assert_equal '', response.body
end end
assert_nil Issue.find_by_id(6) assert_nil Issue.find_by_id(6)
...@@ -829,7 +829,7 @@ JSON ...@@ -829,7 +829,7 @@ JSON
assert_difference('Issue.count', -1) do assert_difference('Issue.count', -1) do
delete '/issues/6.json', :headers => credentials('jsmith') delete '/issues/6.json', :headers => credentials('jsmith')
assert_response :ok assert_response :no_content
assert_equal '', response.body assert_equal '', response.body
end end
assert_nil Issue.find_by_id(6) assert_nil Issue.find_by_id(6)
...@@ -841,7 +841,7 @@ JSON ...@@ -841,7 +841,7 @@ JSON
:params => {:user_id => 3}, :params => {:user_id => 3},
:headers => credentials('jsmith') :headers => credentials('jsmith')
assert_response :ok assert_response :no_content
assert_equal '', response.body assert_equal '', response.body
end end
watcher = Watcher.order('id desc').first watcher = Watcher.order('id desc').first
...@@ -855,7 +855,7 @@ JSON ...@@ -855,7 +855,7 @@ JSON
assert_difference 'Watcher.count', -1 do assert_difference 'Watcher.count', -1 do
delete '/issues/1/watchers/3.xml', :headers => credentials('jsmith') delete '/issues/1/watchers/3.xml', :headers => credentials('jsmith')
assert_response :ok assert_response :no_content
assert_equal '', response.body assert_equal '', response.body
end end
assert_equal false, Issue.find(1).watched_by?(User.find(3)) assert_equal false, Issue.find(1).watched_by?(User.find(3))
...@@ -972,7 +972,7 @@ JSON ...@@ -972,7 +972,7 @@ JSON
:uploads => [{:token => token, :filename => 'test.txt', :uploads => [{:token => token, :filename => 'test.txt',
:content_type => 'text/plain'}]}}, :content_type => 'text/plain'}]}},
:headers => credentials('jsmith') :headers => credentials('jsmith')
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
end end
......
...@@ -135,7 +135,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base ...@@ -135,7 +135,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
:params => {:membership => {:user_id => 3, :role_ids => [1,2]}}, :params => {:membership => {:user_id => 3, :role_ids => [1,2]}},
:headers => credentials('jsmith') :headers => credentials('jsmith')
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
end end
member = Member.find(2) member = Member.find(2)
...@@ -156,7 +156,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base ...@@ -156,7 +156,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
assert_difference 'Member.count', -1 do assert_difference 'Member.count', -1 do
delete '/memberships/2.xml', :headers => credentials('jsmith') delete '/memberships/2.xml', :headers => credentials('jsmith')
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
end end
assert_nil Member.find_by_id(2) assert_nil Member.find_by_id(2)
......
...@@ -198,9 +198,9 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base ...@@ -198,9 +198,9 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
:params => {:project => {:name => 'API update'}}, :params => {:project => {:name => 'API update'}},
:headers => credentials('jsmith') :headers => credentials('jsmith')
end end
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
assert_equal 'application/xml', @response.content_type assert_nil @response.content_type
project = Project.find(2) project = Project.find(2)
assert_equal 'API update', project.name assert_equal 'API update', project.name
end end
...@@ -211,7 +211,7 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base ...@@ -211,7 +211,7 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
:params => {:project => {:name => 'API update', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}}, :params => {:project => {:name => 'API update', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}},
:headers => credentials('admin') :headers => credentials('admin')
end end
assert_response :ok assert_response :no_content
assert_equal '', @response.body 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
...@@ -223,7 +223,7 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base ...@@ -223,7 +223,7 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
:params => {:project => {:name => 'API update', :tracker_ids => [1, 3]}}, :params => {:project => {:name => 'API update', :tracker_ids => [1, 3]}},
:headers => credentials('admin') :headers => credentials('admin')
end end
assert_response :ok assert_response :no_content
assert_equal '', @response.body 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
...@@ -245,7 +245,7 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base ...@@ -245,7 +245,7 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
assert_difference('Project.count',-1) do assert_difference('Project.count',-1) do
delete '/projects/2.xml', :headers => credentials('admin') delete '/projects/2.xml', :headers => credentials('admin')
end end
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
assert_nil Project.find_by_id(2) assert_nil Project.find_by_id(2)
end end
......
...@@ -135,7 +135,7 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base ...@@ -135,7 +135,7 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
:params => {:time_entry => {:comments => 'API Update'}}, :params => {:time_entry => {:comments => 'API Update'}},
:headers => credentials('jsmith') :headers => credentials('jsmith')
end end
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
assert_equal 'API Update', TimeEntry.find(2).comments assert_equal 'API Update', TimeEntry.find(2).comments
end end
...@@ -164,7 +164,7 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base ...@@ -164,7 +164,7 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
assert_difference 'TimeEntry.count', -1 do assert_difference 'TimeEntry.count', -1 do
delete '/time_entries/2.xml', :headers => credentials('jsmith') delete '/time_entries/2.xml', :headers => credentials('jsmith')
end end
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
assert_nil TimeEntry.find_by_id(2) assert_nil TimeEntry.find_by_id(2)
end end
......
...@@ -256,7 +256,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base ...@@ -256,7 +256,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert_equal 'jsmith@somenet.foo', user.mail assert_equal 'jsmith@somenet.foo', user.mail
assert !user.admin? assert !user.admin?
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
end end
...@@ -279,7 +279,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base ...@@ -279,7 +279,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert_equal 'jsmith@somenet.foo', user.mail assert_equal 'jsmith@somenet.foo', user.mail
assert !user.admin? assert !user.admin?
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
end end
...@@ -325,7 +325,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base ...@@ -325,7 +325,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
delete '/users/2.xml', :headers => credentials('admin') delete '/users/2.xml', :headers => credentials('admin')
end end
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
end end
...@@ -334,7 +334,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base ...@@ -334,7 +334,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
delete '/users/2.json', :headers => credentials('admin') delete '/users/2.json', :headers => credentials('admin')
end end
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
end end
end end
...@@ -122,7 +122,7 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base ...@@ -122,7 +122,7 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
:params => {:version => {:name => 'API update'}}, :params => {:version => {:name => 'API update'}},
:headers => credentials('jsmith') :headers => credentials('jsmith')
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
assert_equal 'API update', Version.find(2).name assert_equal 'API update', Version.find(2).name
end end
...@@ -132,7 +132,7 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base ...@@ -132,7 +132,7 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
delete '/versions/3.xml', :headers => credentials('jsmith') delete '/versions/3.xml', :headers => credentials('jsmith')
end end
assert_response :ok assert_response :no_content
assert_equal '', @response.body assert_equal '', @response.body
assert_nil Version.find_by_id(3) assert_nil Version.find_by_id(3)
end end
......
...@@ -106,7 +106,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base ...@@ -106,7 +106,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
put '/projects/ecookbook/wiki/CookBook_documentation.xml', put '/projects/ecookbook/wiki/CookBook_documentation.xml',
:params => {:wiki_page => {:text => 'New content from API', :comments => 'API update'}}, :params => {:wiki_page => {:text => 'New content from API', :comments => 'API update'}},
:headers => credentials('jsmith') :headers => credentials('jsmith')
assert_response 200 assert_response :no_content
end end
end end
...@@ -123,7 +123,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base ...@@ -123,7 +123,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
put '/projects/ecookbook/wiki/CookBook_documentation.xml', put '/projects/ecookbook/wiki/CookBook_documentation.xml',
:params => {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '3'}}, :params => {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '3'}},
:headers => credentials('jsmith') :headers => credentials('jsmith')
assert_response 200 assert_response :no_content
end end
end end
...@@ -201,7 +201,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base ...@@ -201,7 +201,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
test "DELETE /projects/:project_id/wiki/:title.xml should destroy the page" do test "DELETE /projects/:project_id/wiki/:title.xml should destroy the page" do
assert_difference 'WikiPage.count', -1 do assert_difference 'WikiPage.count', -1 do
delete '/projects/ecookbook/wiki/CookBook_documentation.xml', :headers => credentials('jsmith') delete '/projects/ecookbook/wiki/CookBook_documentation.xml', :headers => credentials('jsmith')
assert_response 200 assert_response :no_content
end end
assert_nil WikiPage.find_by_id(1) assert_nil WikiPage.find_by_id(1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment