From: mmd-osm Date: Wed, 16 Sep 2020 20:13:19 +0000 (+0200) Subject: Json user details: unit tests X-Git-Tag: live~1997^2~1 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/dff8effc13d16e4b0fb4992863993cdddc23ec99?hp=9f280be82b251522bc8e6a28b24d2e44988bf680 Json user details: unit tests --- diff --git a/test/controllers/api/users_controller_test.rb b/test/controllers/api/users_controller_test.rb index abe7a7412..2824c40b2 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 @@ -137,6 +149,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