From: Matt Amos Date: Tue, 14 Oct 2008 14:34:17 +0000 (+0000) Subject: Added some more functional tests for way and relation delete methods. X-Git-Tag: live~7569^2~267 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/44034cd78197a48e561104ceafa5b441748fbedf Added some more functional tests for way and relation delete methods. --- diff --git a/test/functional/relation_controller_test.rb b/test/functional/relation_controller_test.rb index b54d9bc98..ffd65f6cc 100644 --- a/test/functional/relation_controller_test.rb +++ b/test/functional/relation_controller_test.rb @@ -210,6 +210,22 @@ class RelationControllerTest < Test::Unit::TestCase delete :delete, :id => current_relations(:visible_relation).id assert_response :bad_request + # try to delete without specifying a changeset + content "" + delete :delete, :id => current_relations(:visible_relation).id + assert_response :conflict + + # try to delete with an invalid (closed) changeset + content update_changeset(current_relations(:visible_relation).to_xml, + changesets(:normal_user_closed_change).id) + delete :delete, :id => current_relations(:visible_relation).id + assert_response :conflict + + # try to delete with an invalid (non-existent) changeset + content update_changeset(current_relations(:visible_relation).to_xml,0) + delete :delete, :id => current_relations(:visible_relation).id + assert_response :conflict + # this won't work because the relation is in-use by another relation content(relations(:used_relation).to_xml) delete :delete, :id => current_relations(:used_relation).id @@ -243,4 +259,24 @@ class RelationControllerTest < Test::Unit::TestCase assert_response :not_found end + ## + # update the changeset_id of a node element + def update_changeset(xml, changeset_id) + xml_attr_rewrite(xml, 'changeset', changeset_id) + end + + ## + # update an attribute in the node element + def xml_attr_rewrite(xml, name, value) + xml.find("//osm/relation").first[name] = value.to_s + return xml + end + + ## + # parse some xml + def xml_parse(xml) + parser = XML::Parser.new + parser.string = xml + parser.parse + end end diff --git a/test/functional/way_controller_test.rb b/test/functional/way_controller_test.rb index d889be2ba..2049ba0cb 100644 --- a/test/functional/way_controller_test.rb +++ b/test/functional/way_controller_test.rb @@ -165,6 +165,17 @@ class WayControllerTest < Test::Unit::TestCase delete :delete, :id => current_ways(:visible_way).id assert_response :bad_request + # try to delete with an invalid (closed) changeset + content update_changeset(current_ways(:visible_way).to_xml, + changesets(:normal_user_closed_change).id) + delete :delete, :id => current_ways(:visible_way).id + assert_response :conflict + + # try to delete with an invalid (non-existent) changeset + content update_changeset(current_ways(:visible_way).to_xml,0) + delete :delete, :id => current_ways(:visible_way).id + assert_response :conflict + # Now try with a valid changeset content current_ways(:visible_way).to_xml delete :delete, :id => current_ways(:visible_way).id @@ -192,4 +203,16 @@ class WayControllerTest < Test::Unit::TestCase assert_response :not_found end + ## + # update the changeset_id of a node element + def update_changeset(xml, changeset_id) + xml_attr_rewrite(xml, 'changeset', changeset_id) + end + + ## + # update an attribute in the node element + def xml_attr_rewrite(xml, name, value) + xml.find("//osm/way").first[name] = value.to_s + return xml + end end