X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/9f280be82b251522bc8e6a28b24d2e44988bf680..d7eac9b5a8f4cbbeb4ed3d73464993bfd5888935:/test/controllers/api/users_controller_test.rb diff --git a/test/controllers/api/users_controller_test.rb b/test/controllers/api/users_controller_test.rb index abe7a7412..5ce30d6a6 100644 --- a/test/controllers/api/users_controller_test.rb +++ b/test/controllers/api/users_controller_test.rb @@ -9,10 +9,18 @@ module Api { :path => "/api/0.6/user/1", :method => :get }, { :controller => "api/users", :action => "show", :id => "1" } ) + assert_routing( + { :path => "/api/0.6/user/1.json", :method => :get }, + { :controller => "api/users", :action => "show", :id => "1", :format => "json" } + ) assert_routing( { :path => "/api/0.6/user/details", :method => :get }, { :controller => "api/users", :action => "details" } ) + assert_routing( + { :path => "/api/0.6/user/details.json", :method => :get }, + { :controller => "api/users", :action => "details", :format => "json" } + ) assert_routing( { :path => "/api/0.6/user/gpx_files", :method => :get }, { :controller => "api/users", :action => "gpx_files" } @@ -21,6 +29,10 @@ module Api { :path => "/api/0.6/users", :method => :get }, { :controller => "api/users", :action => "index" } ) + assert_routing( + { :path => "/api/0.6/users.json", :method => :get }, + { :controller => "api/users", :action => "index", :format => "json" } + ) end def test_show @@ -69,6 +81,15 @@ module Api # check that a non-existent user is not returned get api_user_path(:id => 0) assert_response :not_found + + # check that a visible user is returned properly in json + get api_user_path(:id => user.id, :format => "json") + assert_response :success + assert_equal "application/json", response.media_type + + js = ActiveSupport::JSON.decode(@response.body) + assert_not_nil js + assert_equal user.id, js["user"]["id"] end def test_details @@ -137,6 +158,15 @@ module Api assert_select "user[id='#{user3.id}']", :count => 0 end + # Test json + get api_users_path(:users => user1.id, :format => "json") + assert_response :success + assert_equal "application/json", response.media_type + + js = ActiveSupport::JSON.decode(@response.body) + assert_not_nil js + assert_equal 1, js["users"].count + get api_users_path(:users => user2.id) assert_response :success assert_equal "application/xml", response.media_type