Tests for PreconditionFailed error messages.

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.
This commit is contained in:
Thomas Wood 2009-05-06 21:08:50 +00:00
parent d7fd3fb6e5
commit c273b4b1fa
6 changed files with 10 additions and 2 deletions

View file

@ -298,7 +298,7 @@ class Relation < ActiveRecord::Base
# 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?

View file

@ -235,7 +235,7 @@ class Way < ActiveRecord::Base
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

View file

@ -397,6 +397,7 @@ EOF
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

View file

@ -197,12 +197,14 @@ class NodeControllerTest < ActionController::TestCase
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
##

View file

@ -341,6 +341,7 @@ class RelationControllerTest < ActionController::TestCase
# 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
# -------------------------------------
@ -465,6 +466,7 @@ class RelationControllerTest < ActionController::TestCase
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)

View file

@ -164,6 +164,7 @@ class WayControllerTest < ActionController::TestCase
# 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}'>" +
@ -172,6 +173,7 @@ class WayControllerTest < ActionController::TestCase
# 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}'>" +
@ -286,6 +288,7 @@ class WayControllerTest < ActionController::TestCase
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