]> git.openstreetmap.org Git - rails.git/commitdiff
Refactor some more amf_controller tests to use factories.
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 10 May 2017 15:57:29 +0000 (16:57 +0100)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 10 May 2017 17:17:30 +0000 (18:17 +0100)
The timestamp truncation thing was a pain to figure out.

test/controllers/amf_controller_test.rb

index aa1d43a32a8c27e1b5a08882226f463029f012d1..2d358d0113efbb6bd0b1211b8fcdf3a2060e55c2 100644 (file)
@@ -582,7 +582,8 @@ class AmfControllerTest < ActionController::TestCase
   end
 
   def test_getpoi_without_timestamp
   end
 
   def test_getpoi_without_timestamp
-    node = current_nodes(:node_with_versions)
+    node = create(:node, :with_history, :version => 4)
+    create(:node_tag, :node => node)
 
     amf_content "getpoi", "/1", [node.id, ""]
     post :amf_read
 
     amf_content "getpoi", "/1", [node.id, ""]
     post :amf_read
@@ -612,10 +613,14 @@ class AmfControllerTest < ActionController::TestCase
   end
 
   def test_getpoi_with_timestamp
   end
 
   def test_getpoi_with_timestamp
-    node = nodes(:node_with_versions_v2)
-    current_node = current_nodes(:node_with_versions)
+    current_node = create(:node, :with_history, :version => 4)
+    node = current_node.old_nodes.find_by(:version => 2)
 
 
-    amf_content "getpoi", "/1", [node.node_id, node.timestamp.xmlschema]
+    # Timestamps are stored with microseconds, but xmlschema truncates them to
+    # previous whole second, causing <= comparison to fail
+    timestamp = (node.timestamp + 1.second).xmlschema
+
+    amf_content "getpoi", "/1", [node.node_id, timestamp]
     post :amf_read
     assert_response :success
     amf_parse_response
     post :amf_read
     assert_response :success
     amf_parse_response
@@ -658,9 +663,10 @@ class AmfControllerTest < ActionController::TestCase
 
   # check that we can update a poi
   def test_putpoi_update_valid
 
   # check that we can update a poi
   def test_putpoi_update_valid
-    nd = current_nodes(:visible_node)
-    cs_id = changesets(:public_user_first_change).id
-    amf_content "putpoi", "/1", ["test@example.com:test", cs_id, nd.version, nd.id, nd.lon, nd.lat, nd.tags, nd.visible]
+    nd = create(:node)
+    cs_id = nd.changeset.id
+    user = nd.changeset.user
+    amf_content "putpoi", "/1", ["#{user.email}:test", cs_id, nd.version, nd.id, nd.lon, nd.lat, nd.tags, nd.visible]
     post :amf_write
     assert_response :success
     amf_parse_response
     post :amf_write
     assert_response :success
     amf_parse_response
@@ -676,7 +682,7 @@ class AmfControllerTest < ActionController::TestCase
     # Now try to update again, with a different lat/lon, using the updated version number
     lat = nd.lat + 0.1
     lon = nd.lon - 0.1
     # Now try to update again, with a different lat/lon, using the updated version number
     lat = nd.lat + 0.1
     lon = nd.lon - 0.1
-    amf_content "putpoi", "/2", ["test@example.com:test", cs_id, nd.version + 1, nd.id, lon, lat, nd.tags, nd.visible]
+    amf_content "putpoi", "/2", ["#{user.email}:test", cs_id, nd.version + 1, nd.id, lon, lat, nd.tags, nd.visible]
     post :amf_write
     assert_response :success
     amf_parse_response
     post :amf_write
     assert_response :success
     amf_parse_response
@@ -834,9 +840,11 @@ class AmfControllerTest < ActionController::TestCase
 
   # try deleting a node
   def test_putpoi_delete_valid
 
   # try deleting a node
   def test_putpoi_delete_valid
-    nd = current_nodes(:visible_node)
-    cs_id = changesets(:public_user_first_change).id
-    amf_content "putpoi", "/1", ["test@example.com:test", cs_id, nd.version, nd.id, nd.lon, nd.lat, nd.tags, false]
+    nd = create(:node)
+    cs_id = nd.changeset.id
+    user = nd.changeset.user
+
+    amf_content "putpoi", "/1", ["#{user.email}:test", cs_id, nd.version, nd.id, nd.lon, nd.lat, nd.tags, false]
     post :amf_write
     assert_response :success
     amf_parse_response
     post :amf_write
     assert_response :success
     amf_parse_response
@@ -855,9 +863,11 @@ class AmfControllerTest < ActionController::TestCase
 
   # try deleting a node that is already deleted
   def test_putpoi_delete_already_deleted
 
   # try deleting a node that is already deleted
   def test_putpoi_delete_already_deleted
-    nd = current_nodes(:invisible_node)
-    cs_id = changesets(:public_user_first_change).id
-    amf_content "putpoi", "/1", ["test@example.com:test", cs_id, nd.version, nd.id, nd.lon, nd.lat, nd.tags, false]
+    nd = create(:node, :deleted)
+    cs_id = nd.changeset.id
+    user = nd.changeset.user
+
+    amf_content "putpoi", "/1", ["#{user.email}:test", cs_id, nd.version, nd.id, nd.lon, nd.lat, nd.tags, false]
     post :amf_write
     assert_response :success
     amf_parse_response
     post :amf_write
     assert_response :success
     amf_parse_response
@@ -871,8 +881,11 @@ class AmfControllerTest < ActionController::TestCase
 
   # try deleting a node that has never existed
   def test_putpoi_delete_not_found
 
   # try deleting a node that has never existed
   def test_putpoi_delete_not_found
-    cs_id = changesets(:public_user_first_change).id
-    amf_content "putpoi", "/1", ["test@example.com:test", cs_id, 1, 999999, 0, 0, {}, false]
+    changeset = create(:changeset)
+    cs_id = changeset.id
+    user = changeset.user
+
+    amf_content "putpoi", "/1", ["#{user.email}:test", cs_id, 1, 999999, 0, 0, {}, false]
     post :amf_write
     assert_response :success
     amf_parse_response
     post :amf_write
     assert_response :success
     amf_parse_response
@@ -886,9 +899,11 @@ class AmfControllerTest < ActionController::TestCase
 
   # try setting an invalid location on a node
   def test_putpoi_invalid_latlon
 
   # try setting an invalid location on a node
   def test_putpoi_invalid_latlon
-    nd = current_nodes(:visible_node)
-    cs_id = changesets(:public_user_first_change).id
-    amf_content "putpoi", "/1", ["test@example.com:test", cs_id, nd.version, nd.id, 200, 100, nd.tags, true]
+    nd = create(:node)
+    cs_id = nd.changeset.id
+    user = nd.changeset.user
+
+    amf_content "putpoi", "/1", ["#{user.email}:test", cs_id, nd.version, nd.id, 200, 100, nd.tags, true]
     post :amf_write
     assert_response :success
     amf_parse_response
     post :amf_write
     assert_response :success
     amf_parse_response