X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/f1c6a87aa137c11d0aff5a4b0e563ac2c2a8f82d..7a1615bc55aee72dd03a5dd43c08b4f13f669f06:/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..5720ccb1f 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 @@ -74,7 +82,7 @@ module Api assert_in_delta lat * 10000000, checknode.latitude, 1, "saved node does not match requested latitude" assert_in_delta lon * 10000000, checknode.longitude, 1, "saved node does not match requested longitude" assert_equal changeset.id, checknode.changeset_id, "saved node does not belong to changeset that it was created in" - assert_equal true, checknode.visible, "saved node is not visible" + assert checknode.visible, "saved node is not visible" end def test_create_invalid_xml @@ -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 @@ -473,7 +494,7 @@ module Api # test adding tags to a node def test_duplicate_tags existing_tag = create(:node_tag) - assert_equal true, existing_tag.node.changeset.user.data_public + assert existing_tag.node.changeset.user.data_public # setup auth basic_authorization existing_tag.node.changeset.user.email, "test" @@ -535,7 +556,7 @@ module Api # check the tags are not corrupted assert_equal checknode.tags, apinode.tags - assert apinode.tags.include?("\#{@user.inspect}") + assert_includes apinode.tags, "\#{@user.inspect}" end ##