]> git.openstreetmap.org Git - rails.git/blobdiff - test/functional/node_controller_test.rb
Fixed node functional tests. A couple of changes to the old_node model and node contr...
[rails.git] / test / functional / node_controller_test.rb
index bd1be9e69931b9cf75fc253da28c9cdd2ff5a344..a8ef700a3aba3f364c33e07b2541656297052ae1 100644 (file)
@@ -15,22 +15,28 @@ class NodeControllerTest < Test::Unit::TestCase
 
   def test_create
     # cannot read password from fixture as it is stored as MD5 digest
 
   def test_create
     # cannot read password from fixture as it is stored as MD5 digest
-    basic_authorization("test@openstreetmap.org", "test");  
+    basic_authorization(users(:normal_user).email, "test");
+    # FIXME we need to create a changeset first argh
+    
     # create a node with random lat/lon
     lat = rand(100)-50 + rand
     lon = rand(100)-50 + rand
     # create a node with random lat/lon
     lat = rand(100)-50 + rand
     lon = rand(100)-50 + rand
-    content("<osm><node lat='#{lat}' lon='#{lon}' /></osm>")
+    # normal user has a changeset open, so we'll use that.
+    changeset = changesets(:normal_user_first_change)
+    # create a minimal xml file
+    content("<osm><node lat='#{lat}' lon='#{lon}' changeset='#{changeset.id}'/></osm>")
     put :create
     # hope for success
     assert_response :success, "node upload did not return success status"
     put :create
     # hope for success
     assert_response :success, "node upload did not return success status"
+
     # read id of created node and search for it
     nodeid = @response.body
     checknode = Node.find(nodeid)
     assert_not_nil checknode, "uploaded node not found in data base after upload"
     # compare values
     # read id of created node and search for it
     nodeid = @response.body
     checknode = Node.find(nodeid)
     assert_not_nil checknode, "uploaded node not found in data base after upload"
     # compare values
-    assert_in_delta lat, checknode.latitude, 1E-8, "saved node does not match requested latitude"
-    assert_in_delta lon, checknode.longitude, 1E-8, "saved node does not match requested longitude"
-    assert_equal users(:normal_user).id, checknode.user_id, "saved node does not belong to user that created it"
+    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 changesets(:normal_user_first_change).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"
   end
 
     assert_equal true, checknode.visible, "saved node is not visible"
   end
 
@@ -57,13 +63,15 @@ class NodeControllerTest < Test::Unit::TestCase
     assert_response :unauthorized
 
     # now set auth
     assert_response :unauthorized
 
     # now set auth
-    basic_authorization("test@openstreetmap.org", "test");  
+    basic_authorization(users(:normal_user).email, "test");  
 
 
-    # this should work
+    # delete now takes a payload
+    content(nodes(:visible_node).to_xml)
     delete :delete, :id => current_nodes(:visible_node).id
     assert_response :success
 
     # this won't work since the node is already deleted
     delete :delete, :id => current_nodes(:visible_node).id
     assert_response :success
 
     # this won't work since the node is already deleted
+    content(nodes(:invisible_node).to_xml)
     delete :delete, :id => current_nodes(:invisible_node).id
     assert_response :gone
 
     delete :delete, :id => current_nodes(:invisible_node).id
     assert_response :gone
 
@@ -72,6 +80,7 @@ class NodeControllerTest < Test::Unit::TestCase
     assert_response :not_found
 
     # this won't work since the node is in use
     assert_response :not_found
 
     # this won't work since the node is in use
+    content(nodes(:used_node_1).to_xml)
     delete :delete, :id => current_nodes(:used_node_1).id
     assert_response :precondition_failed
   end
     delete :delete, :id => current_nodes(:used_node_1).id
     assert_response :precondition_failed
   end
@@ -82,6 +91,6 @@ class NodeControllerTest < Test::Unit::TestCase
   end
 
   def content(c)
   end
 
   def content(c)
-    @request.env["RAW_POST_DATA"] = c
+    @request.env["RAW_POST_DATA"] = c.to_s
   end
 end
   end
 end