[ARVADOS] updated: 8adde5132926e8f9cc1b01d79f9307614cc6021e

git at public.curoverse.com git at public.curoverse.com
Tue Apr 29 16:45:52 EDT 2014


Summary of changes:
 .../api/app/controllers/application_controller.rb  |    8 ++++++
 .../api/test/integration/login_workflow_test.rb    |   25 ++++++++++++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)
 create mode 100644 services/api/test/integration/login_workflow_test.rb

       via  8adde5132926e8f9cc1b01d79f9307614cc6021e (commit)
      from  8eaad00b025167a7505ba11ad6a05b52a43c2399 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 8adde5132926e8f9cc1b01d79f9307614cc6021e
Author: Brett Smith <brett at curoverse.com>
Date:   Tue Apr 29 16:28:50 2014 -0400

    api: Make JSON the default response format.
    
    Rails assumes that the request should be sent in HTML unless a format
    parameter or the Accept header expressly overrides that.  This change
    makes JSON the default unless the request specified it would like
    HTML.

diff --git a/services/api/app/controllers/application_controller.rb b/services/api/app/controllers/application_controller.rb
index 4c30960..d40c6de 100644
--- a/services/api/app/controllers/application_controller.rb
+++ b/services/api/app/controllers/application_controller.rb
@@ -6,6 +6,7 @@ class ApplicationController < ActionController::Base
   protect_from_forgery
   around_filter :thread_with_auth_info, :except => [:render_error, :render_not_found]
 
+  before_filter :respond_with_json_by_default
   before_filter :remote_ip
   before_filter :require_auth_scope, :except => :render_not_found
   before_filter :catch_redirect_hint
@@ -476,6 +477,13 @@ class ApplicationController < ActionController::Base
   end
   # /Authentication
 
+  def respond_with_json_by_default
+    html_index = request.accepts.index(Mime::HTML)
+    if html_index.nil? or request.accepts[0...html_index].include?(Mime::JSON)
+      request.format = :json
+    end
+  end
+
   def model_class
     controller_name.classify.constantize
   end
diff --git a/services/api/test/integration/login_workflow_test.rb b/services/api/test/integration/login_workflow_test.rb
new file mode 100644
index 0000000..e0d6968
--- /dev/null
+++ b/services/api/test/integration/login_workflow_test.rb
@@ -0,0 +1,25 @@
+require 'test_helper'
+
+class LoginWorkflowTest < ActionDispatch::IntegrationTest
+  test "default prompt to login is JSON" do
+    post('/arvados/v1/specimens', {specimen: {}},
+         {'HTTP_ACCEPT' => ''})
+    assert_response 401
+    assert_includes(json_response['errors'], "Not logged in")
+  end
+
+  test "login prompt respects JSON Accept header" do
+    post('/arvados/v1/specimens', {specimen: {}},
+         {'HTTP_ACCEPT' => 'application/json'})
+    assert_response 401
+    assert_includes(json_response['errors'], "Not logged in")
+  end
+
+  test "login prompt respects HTML Accept header" do
+    post('/arvados/v1/specimens', {specimen: {}},
+         {'HTTP_ACCEPT' => 'text/html'})
+    assert_response 302
+    assert_match(%r{/auth/joshid$}, @response.headers['Location'],
+                 "HTML login prompt did not include expected redirect")
+  end
+end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list