Added some more functional tests for way and relation delete methods.

This commit is contained in:
Matt Amos 2008-10-14 14:34:17 +00:00
parent b56f57ec43
commit 44034cd781
2 changed files with 59 additions and 0 deletions

View file

@ -210,6 +210,22 @@ class RelationControllerTest < Test::Unit::TestCase
delete :delete, :id => current_relations(:visible_relation).id delete :delete, :id => current_relations(:visible_relation).id
assert_response :bad_request assert_response :bad_request
# try to delete without specifying a changeset
content "<osm><relation id='#{current_relations(:visible_relation).id}'/></osm>"
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 # this won't work because the relation is in-use by another relation
content(relations(:used_relation).to_xml) content(relations(:used_relation).to_xml)
delete :delete, :id => current_relations(:used_relation).id delete :delete, :id => current_relations(:used_relation).id
@ -243,4 +259,24 @@ class RelationControllerTest < Test::Unit::TestCase
assert_response :not_found assert_response :not_found
end 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 end

View file

@ -165,6 +165,17 @@ class WayControllerTest < Test::Unit::TestCase
delete :delete, :id => current_ways(:visible_way).id delete :delete, :id => current_ways(:visible_way).id
assert_response :bad_request 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 # Now try with a valid changeset
content current_ways(:visible_way).to_xml content current_ways(:visible_way).to_xml
delete :delete, :id => current_ways(:visible_way).id delete :delete, :id => current_ways(:visible_way).id
@ -192,4 +203,16 @@ class WayControllerTest < Test::Unit::TestCase
assert_response :not_found assert_response :not_found
end 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 end