amf get*_history tests and related fixes
This commit is contained in:
parent
436470b057
commit
2aa3daf0e0
2 changed files with 78 additions and 12 deletions
|
@ -246,26 +246,36 @@ class AmfController < ApplicationController
|
||||||
# an array of previous versions.
|
# an array of previous versions.
|
||||||
|
|
||||||
def getway_history(wayid) #:doc:
|
def getway_history(wayid) #:doc:
|
||||||
history = Way.find(wayid).old_ways.reverse.collect do |old_way|
|
begin
|
||||||
user = old_way.user.data_public? ? old_way.user.display_name : 'anonymous'
|
history = Way.find(wayid).old_ways.reverse.collect do |old_way|
|
||||||
uid = old_way.user.data_public? ? old_way.user.id : 0
|
user_object = old_way.changeset.user
|
||||||
[old_way.version, old_way.timestamp.strftime("%d %b %Y, %H:%M"), old_way.visible ? 1 : 0, user, uid]
|
user = user_object.data_public? ? user_object.display_name : 'anonymous'
|
||||||
end
|
uid = user_object.data_public? ? user_object.id : 0
|
||||||
|
[old_way.version, old_way.timestamp.strftime("%d %b %Y, %H:%M"), old_way.visible ? 1 : 0, user, uid]
|
||||||
|
end
|
||||||
|
|
||||||
['way',wayid,history]
|
return ['way',wayid,history]
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
return ['way', wayid, []]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Find history of a node. Returns 'node', id, and
|
# Find history of a node. Returns 'node', id, and
|
||||||
# an array of previous versions.
|
# an array of previous versions.
|
||||||
|
|
||||||
def getnode_history(nodeid) #:doc:
|
def getnode_history(nodeid) #:doc:
|
||||||
history = Node.find(nodeid).old_nodes.reverse.collect do |old_node|
|
begin
|
||||||
user = old_node.user.data_public? ? old_node.user.display_name : 'anonymous'
|
history = Node.find(nodeid).old_nodes.reverse.collect do |old_node|
|
||||||
uid = old_node.user.data_public? ? old_node.user.id : 0
|
user_object = old_node.changeset.user
|
||||||
[old_node.timestamp.to_i, old_node.timestamp.strftime("%d %b %Y, %H:%M"), old_node.visible ? 1 : 0, user, uid]
|
user = user_object.data_public? ? user_object.display_name : 'anonymous'
|
||||||
end
|
uid = user_object.data_public? ? user_object.id : 0
|
||||||
|
[old_node.timestamp.to_i, old_node.timestamp.strftime("%d %b %Y, %H:%M"), old_node.visible ? 1 : 0, user, uid]
|
||||||
|
end
|
||||||
|
|
||||||
['node',nodeid,history]
|
return ['node',nodeid,history]
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
return ['node', nodeid, []]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get a relation with all tags and members.
|
# Get a relation with all tags and members.
|
||||||
|
|
|
@ -187,6 +187,62 @@ class AmfControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_getway_history
|
||||||
|
latest = current_ways(:way_with_versions)
|
||||||
|
amf_content "getway_history", "/1", [latest.id]
|
||||||
|
post :amf_read
|
||||||
|
assert_response :success
|
||||||
|
amf_parse_response
|
||||||
|
history = amf_result("/1")
|
||||||
|
|
||||||
|
# ['way',wayid,history]
|
||||||
|
assert_equal history[0], 'way'
|
||||||
|
assert_equal history[1], latest.id
|
||||||
|
assert_equal history[2].first[0], latest.version
|
||||||
|
assert_equal history[2].last[0], ways(:way_with_versions_v1).version
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_getway_history_nonexistent
|
||||||
|
amf_content "getway_history", "/1", [0]
|
||||||
|
post :amf_read
|
||||||
|
assert_response :success
|
||||||
|
amf_parse_response
|
||||||
|
history = amf_result("/1")
|
||||||
|
|
||||||
|
# ['way',wayid,history]
|
||||||
|
assert_equal history[0], 'way'
|
||||||
|
assert_equal history[1], 0
|
||||||
|
assert history[2].empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_getnode_history
|
||||||
|
latest = current_nodes(:node_with_versions)
|
||||||
|
amf_content "getnode_history", "/1", [latest.id]
|
||||||
|
post :amf_read
|
||||||
|
assert_response :success
|
||||||
|
amf_parse_response
|
||||||
|
history = amf_result("/1")
|
||||||
|
|
||||||
|
# ['node',nodeid,history]
|
||||||
|
assert_equal history[0], 'node'
|
||||||
|
assert_equal history[1], latest.id
|
||||||
|
assert_equal history[2].first[0], latest.timestamp.to_i
|
||||||
|
assert_equal history[2].last[0], nodes(:node_with_versions_v1).timestamp.to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_getnode_history_nonexistent
|
||||||
|
amf_content "getnode_history", "/1", [0]
|
||||||
|
post :amf_read
|
||||||
|
assert_response :success
|
||||||
|
amf_parse_response
|
||||||
|
history = amf_result("/1")
|
||||||
|
|
||||||
|
# ['node',nodeid,history]
|
||||||
|
assert_equal history[0], 'node'
|
||||||
|
assert_equal history[1], 0
|
||||||
|
assert history[2].empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# ************************************************************
|
# ************************************************************
|
||||||
# AMF Helper functions
|
# AMF Helper functions
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue