Added tests for changeset upload code. Refactored diff reading code and put it into /lib. Changed the route of a changeset upload to explicitly refer to the changeset it applies to (i.e: resource).
This commit is contained in:
parent
136c5a7bf1
commit
dc2a959037
8 changed files with 596 additions and 96 deletions
|
@ -75,20 +75,25 @@ class Node < ActiveRecord::Base
|
|||
def self.from_xml_node(pt, create=false)
|
||||
node = Node.new
|
||||
|
||||
node.version = pt['version'].to_i
|
||||
node.lat = pt['lat'].to_f
|
||||
node.lon = pt['lon'].to_f
|
||||
node.changeset_id = pt['changeset'].to_i
|
||||
|
||||
return nil unless node.in_world?
|
||||
|
||||
# version must be present unless creating
|
||||
return nil unless create or not pt['version'].nil?
|
||||
node.version = pt['version'].to_i
|
||||
|
||||
unless create
|
||||
if pt['id'] != '0'
|
||||
node.id = pt['id'].to_i
|
||||
end
|
||||
end
|
||||
|
||||
node.visible = pt['visible'] and pt['visible'] == 'true'
|
||||
# visible if it says it is, or as the default if the attribute
|
||||
# is missing.
|
||||
node.visible = pt['visible'].nil? or pt['visible'] == 'true'
|
||||
|
||||
if create
|
||||
node.timestamp = Time.now
|
||||
|
@ -235,4 +240,11 @@ class Node < ActiveRecord::Base
|
|||
@tags[k] = v
|
||||
end
|
||||
|
||||
##
|
||||
# dummy method to make the interfaces of node, way and relation
|
||||
# more consistent.
|
||||
def fix_placeholders!(id_map)
|
||||
# nodes don't refer to anything, so there is nothing to do here
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -320,4 +320,22 @@ class Relation < ActiveRecord::Base
|
|||
def tags_as_hash
|
||||
return self.tags
|
||||
end
|
||||
|
||||
##
|
||||
# if any members are referenced by placeholder IDs (i.e: negative) then
|
||||
# this calling this method will fix them using the map from placeholders
|
||||
# to IDs +id_map+.
|
||||
def fix_placeholders!(id_map)
|
||||
self.members.map! do |type, id, role|
|
||||
old_id = id.to_i
|
||||
if old_id < 0
|
||||
new_id = id_map[type.to_sym][old_id]
|
||||
raise "invalid placeholder" if new_id.nil?
|
||||
[type, new_id, role]
|
||||
else
|
||||
[type, id, role]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -299,4 +299,21 @@ class Way < ActiveRecord::Base
|
|||
def tags_as_hash
|
||||
return self.tags
|
||||
end
|
||||
|
||||
##
|
||||
# if any referenced nodes are placeholder IDs (i.e: are negative) then
|
||||
# this calling this method will fix them using the map from placeholders
|
||||
# to IDs +id_map+.
|
||||
def fix_placeholders!(id_map)
|
||||
self.nds.map! do |node_id|
|
||||
if node_id < 0
|
||||
new_id = id_map[:node][node_id]
|
||||
raise "invalid placeholder for #{node_id.inspect}: #{new_id.inspect}" if new_id.nil?
|
||||
new_id
|
||||
else
|
||||
node_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue