]> git.openstreetmap.org Git - rails.git/blobdiff - test/controllers/api/traces_controller_test.rb
Merge remote-tracking branch 'upstream/pull/5957'
[rails.git] / test / controllers / api / traces_controller_test.rb
index 367bb6d21e1fe0b057d5f7de06abfe7f46e8f9c7..ecb92d03b0819400350d8d85a23c6c5ad7580450 100644 (file)
@@ -17,6 +17,10 @@ module Api
         { :path => "/api/0.6/gpx/1", :method => :get },
         { :controller => "api/traces", :action => "show", :id => "1" }
       )
+      assert_routing(
+        { :path => "/api/0.6/gpx/1.json", :method => :get },
+        { :controller => "api/traces", :action => "show", :id => "1", :format => "json" }
+      )
       assert_routing(
         { :path => "/api/0.6/gpx/1", :method => :put },
         { :controller => "api/traces", :action => "update", :id => "1" }
@@ -44,11 +48,21 @@ module Api
       get api_trace_path(public_trace_file), :headers => auth_header
       assert_response :success
 
-      # And finally we should be able to do it with the owner of the trace
+      # We should be able to do it with the owner of the trace
       auth_header = bearer_authorization_header public_trace_file.user
       get api_trace_path(public_trace_file), :headers => auth_header
       assert_response :success
       assert_select "gpx_file[id='#{public_trace_file.id}'][uid='#{public_trace_file.user.id}']", 1
+
+      # We should be able to do it with the owner of the trace with json format
+      auth_header = bearer_authorization_header public_trace_file.user
+      get api_trace_path(public_trace_file, :format => "json"), :headers => auth_header
+      assert_response :success
+      assert_equal "application/json", response.media_type
+      js = ActiveSupport::JSON.decode(@response.body)
+      assert_not_nil js
+      assert_equal public_trace_file.id, js["trace"]["id"]
+      assert_equal public_trace_file.user.id, js["trace"]["uid"]
     end
 
     # Check an anonymous trace can't be specifically fetched by another user