index=AMF.getstring(req) # | get index in response sequence
bytes=AMF.getlong(req) # | get total size in bytes
args=AMF.getvalue(req) # | get response (probably an array)
+ logger.info "Executing AMF #{message}:#{index}"
case message
when 'getpresets'; results[index]=AMF.putdata(index,getpresets())
when 'getpoi'; results[index]=AMF.putdata(index,getpoi(*args))
end
end
+ logger.info("encoding AMF results")
sendresponse(results)
end
# Get an old version of a way, and all constituent nodes.
#
- # For undelete (version=0), always uses the most recent version of each node,
- # even if it's moved. For revert (version=1+), uses the node in existence
+ # For undelete (version<0), always uses the most recent version of each node,
+ # even if it's moved. For revert (version >= 0), uses the node in existence
# at the time, generating a new id if it's still visible and has been moved/
# retagged.
def getway_old(id, version) #:doc:
if version < 0
old_way = OldWay.find(:first, :conditions => ['visible = ? AND id = ?', true, id], :order => 'version DESC')
- points = old_way.get_nodes_undelete
+ points = old_way.get_nodes_undelete unless old_way.nil?
else
old_way = OldWay.find(:first, :conditions => ['id = ? AND version = ?', id, version])
- points = old_way.get_nodes_revert
+ points = old_way.get_nodes_revert unless old_way.nil?
end
- old_way.tags['history'] = "Retrieved from v#{old_way.version}"
-
- [0, id, points, old_way.tags, old_way.version]
+ if old_way.nil?
+ return [0, id, [], {}, -1]
+ else
+ old_way.tags['history'] = "Retrieved from v#{old_way.version}"
+ return [0, id, points, old_way.tags, old_way.version]
+ end
end
# Find history of a way. Returns 'way', id, and
assert rel[1].empty? and rel[2].empty?
end
+ def test_getway_old
+ # try to get the last visible version (specified by <0) (should be current version)
+ latest = current_ways(:way_with_versions)
+ # try to get version 1
+ v1 = ways(:way_with_versions_v1)
+ {latest => -1, v1 => v1.version}.each do |way, v|
+ amf_content "getway_old", "/1", [way.id, v]
+ post :amf_read
+ assert_response :success
+ amf_parse_response
+ returned_way = amf_result("/1")
+ assert_equal returned_way[1], way.id
+ assert_equal returned_way[4], way.version
+ end
+ end
+
+ def test_getway_old_nonexistent
+ # try to get the last version+10 (shoudn't exist)
+ latest = current_ways(:way_with_versions)
+ # try to get last visible version of non-existent way
+ # try to get specific version of non-existent way
+ {nil => -1, nil => 1, latest => latest.version + 10}.each do |way, v|
+ amf_content "getway_old", "/1", [way.nil? ? 0 : way.id, v]
+ post :amf_read
+ assert_response :success
+ amf_parse_response
+ returned_way = amf_result("/1")
+ assert returned_way[2].empty?
+ assert returned_way[3].empty?
+ assert returned_way[4] < 0
+ end
+ end
+
+
+ # ************************************************************
+ # AMF Helper functions
+
# Get the result record for the specified ID
# It's an assertion FAIL if the record does not exist
def amf_result ref