]> git.openstreetmap.org Git - rails.git/blobdiff - test/controllers/api/nodes_controller_test.rb
Fix rubocop-minitest warnings
[rails.git] / test / controllers / api / nodes_controller_test.rb
index aee41d51548e788bc6d6f389750f891025f8510f..5720ccb1fc482a01af71a2ca67f17430616bebf5 100644 (file)
@@ -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
 
     ##