better handling of duplicate tags. Extra validation in the tests.
This commit is contained in:
parent
c3785ff278
commit
6e98e324e5
5 changed files with 12 additions and 8 deletions
|
@ -71,8 +71,8 @@ class Node < ActiveRecord::Base
|
|||
doc.find('//osm/node').each do |pt|
|
||||
return Node.from_xml_node(pt, create)
|
||||
end
|
||||
rescue
|
||||
return nil
|
||||
rescue LibXML::XML::Error => ex
|
||||
raise OSM::APIBadXMLError.new("node", xml, ex.message)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -274,7 +274,7 @@ class Node < ActiveRecord::Base
|
|||
|
||||
# duplicate tags are now forbidden, so we can't allow values
|
||||
# in the hash to be overwritten.
|
||||
raise OSM::APIDuplicateTagsError.new if @tags.include? k
|
||||
raise OSM::APIDuplicateTagsError.new("node", self.id, k) if @tags.include? k
|
||||
|
||||
@tags[k] = v
|
||||
end
|
||||
|
|
|
@ -209,7 +209,7 @@ class Relation < ActiveRecord::Base
|
|||
|
||||
# duplicate tags are now forbidden, so we can't allow values
|
||||
# in the hash to be overwritten.
|
||||
raise OSM::APIDuplicateTagsError.new if @tags.include? k
|
||||
raise OSM::APIDuplicateTagsError.new("relation", self.id, k) if @tags.include? k
|
||||
|
||||
@tags[k] = v
|
||||
end
|
||||
|
|
|
@ -34,8 +34,8 @@ class Way < ActiveRecord::Base
|
|||
doc.find('//osm/way').each do |pt|
|
||||
return Way.from_xml_node(pt, create)
|
||||
end
|
||||
rescue
|
||||
return nil
|
||||
rescue LibXML::XML::Error => ex
|
||||
raise OSM::APIBadXMLError.new("relation", xml, ex.message)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -182,7 +182,7 @@ class Way < ActiveRecord::Base
|
|||
|
||||
# duplicate tags are now forbidden, so we can't allow values
|
||||
# in the hash to be overwritten.
|
||||
raise OSM::APIDuplicateTagsError.new if @tags.include? k
|
||||
raise OSM::APIDuplicateTagsError.new("way", self.id, k) if @tags.include? k
|
||||
|
||||
@tags[k] = v
|
||||
end
|
||||
|
|
|
@ -194,7 +194,8 @@ class NodeControllerTest < ActionController::TestCase
|
|||
content node_xml
|
||||
put :update, :id => current_nodes(:visible_node).id
|
||||
assert_response :bad_request,
|
||||
"adding duplicate tags to a node should fail with 'bad request'"
|
||||
"adding duplicate tags to a node should fail with 'bad request'"
|
||||
assert_equal "Element node/#{current_nodes(:visible_node).id} has duplicate tags with key #{current_node_tags(:t1).k}.", @response.body
|
||||
end
|
||||
|
||||
# test whether string injection is possible
|
||||
|
|
|
@ -219,6 +219,7 @@ class WayControllerTest < ActionController::TestCase
|
|||
put :update, :id => current_ways(:visible_way).id
|
||||
assert_response :bad_request,
|
||||
"adding a duplicate tag to a way should fail with 'bad request'"
|
||||
assert_equal "Element way/#{current_ways(:visible_way).id} has duplicate tags with key #{current_way_tags(:t1).k}.", @response.body
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -243,6 +244,7 @@ class WayControllerTest < ActionController::TestCase
|
|||
put :update, :id => current_ways(:visible_way).id
|
||||
assert_response :bad_request,
|
||||
"adding new duplicate tags to a way should fail with 'bad request'"
|
||||
assert_equal "Element way/#{current_ways(:visible_way).id} has duplicate tags with key i_am_a_duplicate.", @response.body
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -264,6 +266,7 @@ class WayControllerTest < ActionController::TestCase
|
|||
put :create
|
||||
assert_response :bad_request,
|
||||
"adding new duplicate tags to a way should fail with 'bad request'"
|
||||
assert_equal "Element way/ has duplicate tags with key addr:housenumber.", @response.body
|
||||
end
|
||||
|
||||
##
|
||||
|
|
Loading…
Add table
Reference in a new issue