Change to relation.rb to bring element selection in-line with that of way, so to return nil to be caught later, rather than raise an error.
Change to way.rb to clarify which way on diff upload.
# use reflection to look up the appropriate class
model = Kernel.const_get(m[0].capitalize)
# get the element with that ID
- element = model.find(m[1])
+ element = model.find(:first, :conditions =>["id = ?", m[1]])
# and check that it is OK to use.
unless element and element.visible? and element.preconditions_ok?
self.nds.each do |n|
node = Node.find(:first, :conditions => ["id = ?", n])
unless node and node.visible
- raise OSM::APIPreconditionFailedError.new("The node with id #{n} either does not exist, or is not visible")
+ raise OSM::APIPreconditionFailedError.new("Way #{self.id} requires the node with id #{n}, which either does not exist, or is not visible.")
end
end
return true
post :upload, :id => 2
assert_response :precondition_failed,
"shouldn't be able to upload a invalid deletion diff: #{@response.body}"
+ assert_equal "Precondition failed: Way 3 still used by relation 1.", @response.body
# check that nothing was, in fact, deleted
assert_equal true, Node.find(current_nodes(:node_used_by_relationship).id).visible
delete :delete, :id => current_nodes(:used_node_1).id
assert_response :precondition_failed,
"shouldn't be able to delete a node used in a way (#{@response.body})"
+ assert_equal "Precondition failed: Node 3 is still used by way 1.", @response.body
# in a relation...
content(nodes(:node_used_by_relationship).to_xml)
delete :delete, :id => current_nodes(:node_used_by_relationship).id
assert_response :precondition_failed,
"shouldn't be able to delete a node used in a relation (#{@response.body})"
+ assert_equal "Precondition failed: Node 5 is still used by relation 3.", @response.body
end
##
# expect failure
assert_response :precondition_failed,
"relation upload with invalid node did not return 'precondition failed'"
+ assert_equal "Precondition failed: Cannot create relation: data or member data is invalid.", @response.body
end
# -------------------------------------
delete :delete, :id => current_relations(:public_used_relation).id
assert_response :precondition_failed,
"shouldn't be able to delete a relation used in a relation (#{@response.body})"
+ assert_equal "Precondition failed: The relation 5 is used in relation 6.", @response.body
# this should work when we provide the appropriate payload...
content(relations(:multi_tag_relation).to_xml)
# expect failure
assert_response :precondition_failed,
"way upload with invalid node did not return 'precondition failed'"
+ assert_equal "Precondition failed: Way requires the node with id 0, which either does not exist, or is not visible.", @response.body
# create a way with no nodes
content "<osm><way changeset='#{open_changeset_id}'>" +
# expect failure
assert_response :precondition_failed,
"way upload with no node did not return 'precondition failed'"
+ assert_equal "Precondition failed: Cannot create way: data is invalid.", @response.body
# create a way inside a closed changeset
content "<osm><way changeset='#{closed_changeset_id}'>" +
delete :delete, :id => current_ways(:used_way).id
assert_response :precondition_failed,
"shouldn't be able to delete a way used in a relation (#{@response.body})"
+ assert_equal "Precondition failed: Way 3 still used by relation 1.", @response.body
# this won't work since the way never existed
delete :delete, :id => 0