]> source.dussan.org Git - redmine.git/commitdiff
Respond with errors and appropriate content type on /issues API calls with invalid...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 23 Jul 2011 19:45:23 +0000 (19:45 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 23 Jul 2011 19:45:23 +0000 (19:45 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6309 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issues_controller.rb
test/integration/api_test/issues_test.rb

index 7e65103418142a4217727a6fdc2251ff01f62004..c8778b47380b7a365cc27789c32f5d360cc6dcb7 100644 (file)
@@ -96,8 +96,10 @@ class IssuesController < ApplicationController
         format.pdf  { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
       end
     else
-      # Send html if the query is not valid
-      render(:template => 'issues/index.rhtml', :layout => !request.xhr?)
+      respond_to do |format|
+        format.any(:html, :atom, :csv, :pdf) { render(:template => 'issues/index.rhtml', :layout => !request.xhr?) }
+        format.api { render_validation_errors(@query) }
+      end
     end
   rescue ActiveRecord::RecordNotFound
     render_404
index 763cf34d550c0a8e64f18e70ea9f170d0d6711bd..3dbd229a254a56f00fdea3c07467e7dc3d5cd5f3 100644 (file)
@@ -101,6 +101,16 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
           }
       end
     end
+    
+    context "with invalid query params" do
+      should "return errors" do
+        get '/issues.xml', {:f => ['start_date'], :op => {:start_date => '='}}
+        
+        assert_response :unprocessable_entity
+        assert_equal 'application/xml', @response.content_type
+        assert_tag 'errors', :child => {:tag => 'error', :content => "Start date can't be blank"}
+      end
+    end
   end
 
   context "/index.json" do