X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/efcb56b68b4ec7b6d4e2986b141e69166c481aee..b556b054d1ac66ba5f8deebe27c60d14ea968b6d:/test/controllers/api/nodes_controller_test.rb diff --git a/test/controllers/api/nodes_controller_test.rb b/test/controllers/api/nodes_controller_test.rb index aee41d515..e2174a126 100644 --- a/test/controllers/api/nodes_controller_test.rb +++ b/test/controllers/api/nodes_controller_test.rb @@ -13,6 +13,10 @@ module Api { :path => "/api/0.6/node/1", :method => :get }, { :controller => "api/nodes", :action => "show", :id => "1" } ) + assert_routing( + { :path => "/api/0.6/node/1.json", :method => :get }, + { :controller => "api/nodes", :action => "show", :id => "1", :format => "json" } + ) assert_routing( { :path => "/api/0.6/node/1", :method => :put }, { :controller => "api/nodes", :action => "update", :id => "1" } @@ -25,6 +29,10 @@ module Api { :path => "/api/0.6/nodes", :method => :get }, { :controller => "api/nodes", :action => "index" } ) + assert_routing( + { :path => "/api/0.6/nodes.json", :method => :get }, + { :controller => "api/nodes", :action => "index", :format => "json" } + ) end def test_create @@ -464,6 +472,19 @@ module Api assert_select "node[id='#{node5.id}'][visible='false']", :count => 1 end + # test a working call with json format + get :index, :params => { :nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}", :format => "json" } + + js = ActiveSupport::JSON.decode(@response.body) + assert_not_nil js + assert_equal 5, js["elements"].count + assert_equal 5, (js["elements"].count { |a| a["type"] == "node" }) + assert_equal 1, (js["elements"].count { |a| a["id"] == node1.id && a["visible"].nil? }) + assert_equal 1, (js["elements"].count { |a| a["id"] == node2.id && a["visible"] == false }) + assert_equal 1, (js["elements"].count { |a| a["id"] == node3.id && a["visible"].nil? }) + assert_equal 1, (js["elements"].count { |a| a["id"] == node4.id && a["visible"].nil? }) + assert_equal 1, (js["elements"].count { |a| a["id"] == node5.id && a["visible"] == false }) + # check error when a non-existent node is included get :index, :params => { :nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id},0" } assert_response :not_found