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
render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
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
render_api_head :ok
render_api_head :no_content
end
# Renders a head API response
......
......@@ -49,7 +49,7 @@ class Redmine::ApiTest::ApiTest < Redmine::ApiTest::Base
def test_head_response_should_have_empty_body
put '/users/7.xml', :params => {:user => {:login => 'foo'}}, :headers => credentials('admin')
assert_response :ok
assert_response :no_content
assert_equal '', response.body
end
end
......@@ -84,7 +84,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
test "DELETE /attachments/:id.xml should return ok and delete Attachment" do
assert_difference 'Attachment.count', -1 do
delete '/attachments/7.xml', :headers => credentials('jsmith')
assert_response :ok
assert_response :no_content
assert_equal '', response.body
end
assert_nil Attachment.find_by_id(7)
......@@ -93,7 +93,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
test "DELETE /attachments/:id.json should return ok and delete Attachment" do
assert_difference 'Attachment.count', -1 do
delete '/attachments/7.json', :headers => credentials('jsmith')
assert_response :ok
assert_response :no_content
assert_equal '', response.body
end
assert_nil Attachment.find_by_id(7)
......@@ -104,8 +104,8 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
:params => {:attachment => {:filename => 'renamed.zip', :description => 'updated'}},
:headers => credentials('jsmith')
assert_response :ok
assert_equal 'application/json', response.content_type
assert_response :no_content
assert_nil response.content_type
attachment = Attachment.find(7)
assert_equal 'renamed.zip', attachment.filename
assert_equal 'updated', attachment.description
......
......@@ -157,7 +157,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
put "/groups/#{group.id}.xml",
:params => {:group => {:name => 'New name', :user_ids => [2, 3]}},
:headers => credentials('admin')
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_equal 'New name', group.reload.name
......@@ -181,7 +181,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
group = Group.generate!
assert_difference 'Group.count', -1 do
delete "/groups/#{group.id}.xml", :headers => credentials('admin')
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
end
end
......@@ -192,7 +192,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
post "/groups/#{group.id}/users.xml",
:params => {:user_id => 5},
:headers => credentials('admin')
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
end
assert_include User.find(5), group.reload.users
......@@ -220,7 +220,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
assert_difference 'group.reload.users.count', -1 do
delete "/groups/#{group.id}/users/8.xml", :headers => credentials('admin')
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
end
assert_not_include User.find(8), group.reload.users
......
......@@ -70,7 +70,7 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
:params => {:issue_category => {:name => 'API Update'}},
:headers => credentials('jsmith')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_equal 'API Update', IssueCategory.find(2).name
end
......@@ -91,7 +91,7 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
assert_difference 'IssueCategory.count', -1 do
delete '/issue_categories/1.xml', :headers => credentials('jsmith')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_nil IssueCategory.find_by_id(1)
end
......@@ -107,7 +107,7 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
:headers => credentials('jsmith')
end
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_nil IssueCategory.find_by_id(1)
end
......
......@@ -77,7 +77,7 @@ class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base
delete '/relations/2.xml', :headers => credentials('jsmith')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_nil IssueRelation.find_by_id(2)
end
......
......@@ -795,7 +795,7 @@ JSON
:params => {:issue => {:subject => 'API update', :notes => 'A new note'}},
:headers => credentials('jsmith')
assert_response :ok
assert_response :no_content
assert_equal '', response.body
end
......@@ -819,7 +819,7 @@ JSON
assert_difference('Issue.count', -1) do
delete '/issues/6.xml', :headers => credentials('jsmith')
assert_response :ok
assert_response :no_content
assert_equal '', response.body
end
assert_nil Issue.find_by_id(6)
......@@ -829,7 +829,7 @@ JSON
assert_difference('Issue.count', -1) do
delete '/issues/6.json', :headers => credentials('jsmith')
assert_response :ok
assert_response :no_content
assert_equal '', response.body
end
assert_nil Issue.find_by_id(6)
......@@ -841,7 +841,7 @@ JSON
:params => {:user_id => 3},
:headers => credentials('jsmith')
assert_response :ok
assert_response :no_content
assert_equal '', response.body
end
watcher = Watcher.order('id desc').first
......@@ -855,7 +855,7 @@ JSON
assert_difference 'Watcher.count', -1 do
delete '/issues/1/watchers/3.xml', :headers => credentials('jsmith')
assert_response :ok
assert_response :no_content
assert_equal '', response.body
end
assert_equal false, Issue.find(1).watched_by?(User.find(3))
......@@ -972,7 +972,7 @@ JSON
:uploads => [{:token => token, :filename => 'test.txt',
:content_type => 'text/plain'}]}},
:headers => credentials('jsmith')
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
end
......
......@@ -135,7 +135,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
:params => {:membership => {:user_id => 3, :role_ids => [1,2]}},
:headers => credentials('jsmith')
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
end
member = Member.find(2)
......@@ -156,7 +156,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
assert_difference 'Member.count', -1 do
delete '/memberships/2.xml', :headers => credentials('jsmith')
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
end
assert_nil Member.find_by_id(2)
......
......@@ -198,9 +198,9 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
:params => {:project => {:name => 'API update'}},
:headers => credentials('jsmith')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_equal 'application/xml', @response.content_type
assert_nil @response.content_type
project = Project.find(2)
assert_equal 'API update', project.name
end
......@@ -211,7 +211,7 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
:params => {:project => {:name => 'API update', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}},
:headers => credentials('admin')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
project = Project.find(2)
assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
......@@ -223,7 +223,7 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
:params => {:project => {:name => 'API update', :tracker_ids => [1, 3]}},
:headers => credentials('admin')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
project = Project.find(2)
assert_equal [1, 3], project.trackers.map(&:id).sort
......@@ -245,7 +245,7 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
assert_difference('Project.count',-1) do
delete '/projects/2.xml', :headers => credentials('admin')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_nil Project.find_by_id(2)
end
......
......@@ -135,7 +135,7 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
:params => {:time_entry => {:comments => 'API Update'}},
:headers => credentials('jsmith')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_equal 'API Update', TimeEntry.find(2).comments
end
......@@ -164,7 +164,7 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
assert_difference 'TimeEntry.count', -1 do
delete '/time_entries/2.xml', :headers => credentials('jsmith')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_nil TimeEntry.find_by_id(2)
end
......
......@@ -256,7 +256,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert_equal 'jsmith@somenet.foo', user.mail
assert !user.admin?
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
end
......@@ -279,7 +279,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert_equal 'jsmith@somenet.foo', user.mail
assert !user.admin?
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
end
......@@ -325,7 +325,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
delete '/users/2.xml', :headers => credentials('admin')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
end
......@@ -334,7 +334,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
delete '/users/2.json', :headers => credentials('admin')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
end
end
......@@ -122,7 +122,7 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
:params => {:version => {:name => 'API update'}},
:headers => credentials('jsmith')
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_equal 'API update', Version.find(2).name
end
......@@ -132,7 +132,7 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
delete '/versions/3.xml', :headers => credentials('jsmith')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_nil Version.find_by_id(3)
end
......
......@@ -106,7 +106,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
put '/projects/ecookbook/wiki/CookBook_documentation.xml',
:params => {:wiki_page => {:text => 'New content from API', :comments => 'API update'}},
:headers => credentials('jsmith')
assert_response 200
assert_response :no_content
end
end
......@@ -123,7 +123,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
put '/projects/ecookbook/wiki/CookBook_documentation.xml',
:params => {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '3'}},
:headers => credentials('jsmith')
assert_response 200
assert_response :no_content
end
end
......@@ -201,7 +201,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
test "DELETE /projects/:project_id/wiki/:title.xml should destroy the page" do
assert_difference 'WikiPage.count', -1 do
delete '/projects/ecookbook/wiki/CookBook_documentation.xml', :headers => credentials('jsmith')
assert_response 200
assert_response :no_content
end
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