]> git.openstreetmap.org Git - rails.git/commitdiff
Move api element index tests up
authorAnton Khorev <tony29@yandex.ru>
Sat, 1 Feb 2025 10:02:31 +0000 (13:02 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sun, 2 Feb 2025 09:17:47 +0000 (12:17 +0300)
test/controllers/api/nodes_controller_test.rb
test/controllers/api/relations_controller_test.rb
test/controllers/api/ways_controller_test.rb

index e70b431e6bfd4ba5806421c1fbfebf8f61bf1b07..075b8b61b37aae8278448fab0a90ec69e35ae756 100644 (file)
@@ -5,6 +5,14 @@ module Api
     ##
     # test all routes which lead to this controller
     def test_routes
+      assert_routing(
+        { :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" }
+      )
       assert_routing(
         { :path => "/api/0.6/node/create", :method => :put },
         { :controller => "api/nodes", :action => "create" }
@@ -25,14 +33,53 @@ module Api
         { :path => "/api/0.6/node/1", :method => :delete },
         { :controller => "api/nodes", :action => "delete", :id => "1" }
       )
-      assert_routing(
-        { :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
+
+    ##
+    # test fetching multiple nodes
+    def test_index
+      node1 = create(:node)
+      node2 = create(:node, :deleted)
+      node3 = create(:node)
+      node4 = create(:node, :with_history, :version => 2)
+      node5 = create(:node, :deleted, :with_history, :version => 2)
+
+      # check error when no parameter provided
+      get api_nodes_path
+      assert_response :bad_request
+
+      # check error when no parameter value provided
+      get api_nodes_path(:nodes => "")
+      assert_response :bad_request
+
+      # test a working call
+      get api_nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}")
+      assert_response :success
+      assert_select "osm" do
+        assert_select "node", :count => 5
+        assert_select "node[id='#{node1.id}'][visible='true']", :count => 1
+        assert_select "node[id='#{node2.id}'][visible='false']", :count => 1
+        assert_select "node[id='#{node3.id}'][visible='true']", :count => 1
+        assert_select "node[id='#{node4.id}'][visible='true']", :count => 1
+        assert_select "node[id='#{node5.id}'][visible='false']", :count => 1
+      end
+
+      # test a working call with json format
+      get api_nodes_path(: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 api_nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id},0")
+      assert_response :not_found
     end
 
     def test_create
@@ -424,53 +471,6 @@ module Api
       assert_response :success, "a valid update request failed"
     end
 
-    ##
-    # test fetching multiple nodes
-    def test_index
-      node1 = create(:node)
-      node2 = create(:node, :deleted)
-      node3 = create(:node)
-      node4 = create(:node, :with_history, :version => 2)
-      node5 = create(:node, :deleted, :with_history, :version => 2)
-
-      # check error when no parameter provided
-      get api_nodes_path
-      assert_response :bad_request
-
-      # check error when no parameter value provided
-      get api_nodes_path(:nodes => "")
-      assert_response :bad_request
-
-      # test a working call
-      get api_nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}")
-      assert_response :success
-      assert_select "osm" do
-        assert_select "node", :count => 5
-        assert_select "node[id='#{node1.id}'][visible='true']", :count => 1
-        assert_select "node[id='#{node2.id}'][visible='false']", :count => 1
-        assert_select "node[id='#{node3.id}'][visible='true']", :count => 1
-        assert_select "node[id='#{node4.id}'][visible='true']", :count => 1
-        assert_select "node[id='#{node5.id}'][visible='false']", :count => 1
-      end
-
-      # test a working call with json format
-      get api_nodes_path(: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 api_nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id},0")
-      assert_response :not_found
-    end
-
     ##
     # test adding tags to a node
     def test_duplicate_tags
index 2919641a977b958313a34a8cfe9a52fee26d0786..efe17f88587c904c27864e8d67d94f6bbf13dc67 100644 (file)
@@ -5,6 +5,14 @@ module Api
     ##
     # test all routes which lead to this controller
     def test_routes
+      assert_routing(
+        { :path => "/api/0.6/relations", :method => :get },
+        { :controller => "api/relations", :action => "index" }
+      )
+      assert_routing(
+        { :path => "/api/0.6/relations.json", :method => :get },
+        { :controller => "api/relations", :action => "index", :format => "json" }
+      )
       assert_routing(
         { :path => "/api/0.6/relation/create", :method => :put },
         { :controller => "api/relations", :action => "create" }
@@ -33,14 +41,6 @@ module Api
         { :path => "/api/0.6/relation/1", :method => :delete },
         { :controller => "api/relations", :action => "delete", :id => "1" }
       )
-      assert_routing(
-        { :path => "/api/0.6/relations", :method => :get },
-        { :controller => "api/relations", :action => "index" }
-      )
-      assert_routing(
-        { :path => "/api/0.6/relations.json", :method => :get },
-        { :controller => "api/relations", :action => "index", :format => "json" }
-      )
 
       assert_routing(
         { :path => "/api/0.6/node/1/relations", :method => :get },
@@ -68,6 +68,51 @@ module Api
       )
     end
 
+    ##
+    # test fetching multiple relations
+    def test_index
+      relation1 = create(:relation)
+      relation2 = create(:relation, :deleted)
+      relation3 = create(:relation, :with_history, :version => 2)
+      relation4 = create(:relation, :with_history, :version => 2)
+      relation4.old_relations.find_by(:version => 1).redact!(create(:redaction))
+
+      # check error when no parameter provided
+      get api_relations_path
+      assert_response :bad_request
+
+      # check error when no parameter value provided
+      get api_relations_path(:relations => "")
+      assert_response :bad_request
+
+      # test a working call
+      get api_relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}")
+      assert_response :success
+      assert_select "osm" do
+        assert_select "relation", :count => 4
+        assert_select "relation[id='#{relation1.id}'][visible='true']", :count => 1
+        assert_select "relation[id='#{relation2.id}'][visible='false']", :count => 1
+        assert_select "relation[id='#{relation3.id}'][visible='true']", :count => 1
+        assert_select "relation[id='#{relation4.id}'][visible='true']", :count => 1
+      end
+
+      # test a working call with json format
+      get api_relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}", :format => "json")
+
+      js = ActiveSupport::JSON.decode(@response.body)
+      assert_not_nil js
+      assert_equal 4, js["elements"].count
+      assert_equal 4, (js["elements"].count { |a| a["type"] == "relation" })
+      assert_equal 1, (js["elements"].count { |a| a["id"] == relation1.id && a["visible"].nil? })
+      assert_equal 1, (js["elements"].count { |a| a["id"] == relation2.id && a["visible"] == false })
+      assert_equal 1, (js["elements"].count { |a| a["id"] == relation3.id && a["visible"].nil? })
+      assert_equal 1, (js["elements"].count { |a| a["id"] == relation4.id && a["visible"].nil? })
+
+      # check error when a non-existent relation is included
+      get api_relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id},0")
+      assert_response :not_found
+    end
+
     # -------------------------------------
     # Test showing relations.
     # -------------------------------------
@@ -164,51 +209,6 @@ module Api
       # FIXME: check whether this contains the stuff we want!
     end
 
-    ##
-    # test fetching multiple relations
-    def test_index
-      relation1 = create(:relation)
-      relation2 = create(:relation, :deleted)
-      relation3 = create(:relation, :with_history, :version => 2)
-      relation4 = create(:relation, :with_history, :version => 2)
-      relation4.old_relations.find_by(:version => 1).redact!(create(:redaction))
-
-      # check error when no parameter provided
-      get api_relations_path
-      assert_response :bad_request
-
-      # check error when no parameter value provided
-      get api_relations_path(:relations => "")
-      assert_response :bad_request
-
-      # test a working call
-      get api_relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}")
-      assert_response :success
-      assert_select "osm" do
-        assert_select "relation", :count => 4
-        assert_select "relation[id='#{relation1.id}'][visible='true']", :count => 1
-        assert_select "relation[id='#{relation2.id}'][visible='false']", :count => 1
-        assert_select "relation[id='#{relation3.id}'][visible='true']", :count => 1
-        assert_select "relation[id='#{relation4.id}'][visible='true']", :count => 1
-      end
-
-      # test a working call with json format
-      get api_relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}", :format => "json")
-
-      js = ActiveSupport::JSON.decode(@response.body)
-      assert_not_nil js
-      assert_equal 4, js["elements"].count
-      assert_equal 4, (js["elements"].count { |a| a["type"] == "relation" })
-      assert_equal 1, (js["elements"].count { |a| a["id"] == relation1.id && a["visible"].nil? })
-      assert_equal 1, (js["elements"].count { |a| a["id"] == relation2.id && a["visible"] == false })
-      assert_equal 1, (js["elements"].count { |a| a["id"] == relation3.id && a["visible"].nil? })
-      assert_equal 1, (js["elements"].count { |a| a["id"] == relation4.id && a["visible"].nil? })
-
-      # check error when a non-existent relation is included
-      get api_relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id},0")
-      assert_response :not_found
-    end
-
     # -------------------------------------
     # Test simple relation creation.
     # -------------------------------------
index b3dab44db7c41590bfacc94989c5233a3a74e9ec..a63b6a1564299b191beab4c2759b4c2a9a79db3f 100644 (file)
@@ -5,6 +5,14 @@ module Api
     ##
     # test all routes which lead to this controller
     def test_routes
+      assert_routing(
+        { :path => "/api/0.6/ways", :method => :get },
+        { :controller => "api/ways", :action => "index" }
+      )
+      assert_routing(
+        { :path => "/api/0.6/ways.json", :method => :get },
+        { :controller => "api/ways", :action => "index", :format => "json" }
+      )
       assert_routing(
         { :path => "/api/0.6/way/create", :method => :put },
         { :controller => "api/ways", :action => "create" }
@@ -33,14 +41,50 @@ module Api
         { :path => "/api/0.6/way/1", :method => :delete },
         { :controller => "api/ways", :action => "delete", :id => "1" }
       )
-      assert_routing(
-        { :path => "/api/0.6/ways", :method => :get },
-        { :controller => "api/ways", :action => "index" }
-      )
-      assert_routing(
-        { :path => "/api/0.6/ways.json", :method => :get },
-        { :controller => "api/ways", :action => "index", :format => "json" }
-      )
+    end
+
+    ##
+    # test fetching multiple ways
+    def test_index
+      way1 = create(:way)
+      way2 = create(:way, :deleted)
+      way3 = create(:way)
+      way4 = create(:way)
+
+      # check error when no parameter provided
+      get api_ways_path
+      assert_response :bad_request
+
+      # check error when no parameter value provided
+      get api_ways_path(:ways => "")
+      assert_response :bad_request
+
+      # test a working call
+      get api_ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}")
+      assert_response :success
+      assert_select "osm" do
+        assert_select "way", :count => 4
+        assert_select "way[id='#{way1.id}'][visible='true']", :count => 1
+        assert_select "way[id='#{way2.id}'][visible='false']", :count => 1
+        assert_select "way[id='#{way3.id}'][visible='true']", :count => 1
+        assert_select "way[id='#{way4.id}'][visible='true']", :count => 1
+      end
+
+      # test a working call with json format
+      get api_ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}", :format => "json")
+
+      js = ActiveSupport::JSON.decode(@response.body)
+      assert_not_nil js
+      assert_equal 4, js["elements"].count
+      assert_equal 4, (js["elements"].count { |a| a["type"] == "way" })
+      assert_equal 1, (js["elements"].count { |a| a["id"] == way1.id && a["visible"].nil? })
+      assert_equal 1, (js["elements"].count { |a| a["id"] == way2.id && a["visible"] == false })
+      assert_equal 1, (js["elements"].count { |a| a["id"] == way3.id && a["visible"].nil? })
+      assert_equal 1, (js["elements"].count { |a| a["id"] == way4.id && a["visible"].nil? })
+
+      # check error when a non-existent way is included
+      get api_ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id},0")
+      assert_response :not_found
     end
 
     # -------------------------------------
@@ -89,50 +133,6 @@ module Api
       assert_response :gone
     end
 
-    ##
-    # test fetching multiple ways
-    def test_index
-      way1 = create(:way)
-      way2 = create(:way, :deleted)
-      way3 = create(:way)
-      way4 = create(:way)
-
-      # check error when no parameter provided
-      get api_ways_path
-      assert_response :bad_request
-
-      # check error when no parameter value provided
-      get api_ways_path(:ways => "")
-      assert_response :bad_request
-
-      # test a working call
-      get api_ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}")
-      assert_response :success
-      assert_select "osm" do
-        assert_select "way", :count => 4
-        assert_select "way[id='#{way1.id}'][visible='true']", :count => 1
-        assert_select "way[id='#{way2.id}'][visible='false']", :count => 1
-        assert_select "way[id='#{way3.id}'][visible='true']", :count => 1
-        assert_select "way[id='#{way4.id}'][visible='true']", :count => 1
-      end
-
-      # test a working call with json format
-      get api_ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}", :format => "json")
-
-      js = ActiveSupport::JSON.decode(@response.body)
-      assert_not_nil js
-      assert_equal 4, js["elements"].count
-      assert_equal 4, (js["elements"].count { |a| a["type"] == "way" })
-      assert_equal 1, (js["elements"].count { |a| a["id"] == way1.id && a["visible"].nil? })
-      assert_equal 1, (js["elements"].count { |a| a["id"] == way2.id && a["visible"] == false })
-      assert_equal 1, (js["elements"].count { |a| a["id"] == way3.id && a["visible"].nil? })
-      assert_equal 1, (js["elements"].count { |a| a["id"] == way4.id && a["visible"].nil? })
-
-      # check error when a non-existent way is included
-      get api_ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id},0")
-      assert_response :not_found
-    end
-
     # -------------------------------------
     # Test simple way creation.
     # -------------------------------------