Fixed 'raw' raises by converting them to the appropriate OSM::APIError type. Made the error messages for placeholder fixing more informative. Added tests for these.
This commit is contained in:
parent
9acc6d3288
commit
3e9b6845d3
5 changed files with 116 additions and 8 deletions
|
@ -267,7 +267,7 @@ class Node < ActiveRecord::Base
|
|||
##
|
||||
# dummy method to make the interfaces of node, way and relation
|
||||
# more consistent.
|
||||
def fix_placeholders!(id_map)
|
||||
def fix_placeholders!(id_map, placeholder_id = nil)
|
||||
# nodes don't refer to anything, so there is nothing to do here
|
||||
end
|
||||
|
||||
|
|
|
@ -318,12 +318,12 @@ class Relation < ActiveRecord::Base
|
|||
# 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)
|
||||
def fix_placeholders!(id_map, placeholder_id = nil)
|
||||
self.members.map! do |type, id, role|
|
||||
old_id = id.to_i
|
||||
if old_id < 0
|
||||
new_id = id_map[type.downcase.to_sym][old_id]
|
||||
raise "invalid placeholder" if new_id.nil?
|
||||
raise OSM::APIBadUserInput.new("Placeholder #{type} not found for reference #{old_id} in relation #{self.id.nil? ? placeholder_id : self.id}.") if new_id.nil?
|
||||
[type, new_id, role]
|
||||
else
|
||||
[type, id, role]
|
||||
|
|
|
@ -287,11 +287,11 @@ class Way < ActiveRecord::Base
|
|||
# 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)
|
||||
def fix_placeholders!(id_map, placeholder_id = nil)
|
||||
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?
|
||||
raise OSM::APIBadUserInput.new("Placeholder node not found for reference #{node_id} in way #{self.id.nil? ? placeholder_id : self.id}") if new_id.nil?
|
||||
new_id
|
||||
else
|
||||
node_id
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue