]> git.openstreetmap.org Git - rails.git/commitdiff
better handling of duplicate tags. Extra validation in the tests.
authorShaun McDonald <shaun@shaunmcdonald.me.uk>
Fri, 28 Nov 2008 17:38:23 +0000 (17:38 +0000)
committerShaun McDonald <shaun@shaunmcdonald.me.uk>
Fri, 28 Nov 2008 17:38:23 +0000 (17:38 +0000)
app/models/node.rb
app/models/relation.rb
app/models/way.rb
test/functional/node_controller_test.rb
test/functional/way_controller_test.rb

index e1ad818ddec0c53991690a3c52727d7a09af930f..b2650b61da5db244c7b3c999c60593f4b5049f23 100644 (file)
@@ -71,8 +71,8 @@ class Node < ActiveRecord::Base
       doc.find('//osm/node').each do |pt|
         return Node.from_xml_node(pt, create)
       end
       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
 
     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.
 
     # 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
 
     @tags[k] = v
   end
index 0bdacb5ec70f1bb488dcb841f20bdaaa49819b37..ba27e9d7d6efb179e60446343ada1bb130898185 100644 (file)
@@ -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.
 
     # 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
 
     @tags[k] = v
   end
index 2071fd559c33ddd136da6608a71606f4698362b7..d4bca19aacfb3af26b912be6979f2fe265eecaf4 100644 (file)
@@ -34,8 +34,8 @@ class Way < ActiveRecord::Base
       doc.find('//osm/way').each do |pt|
         return Way.from_xml_node(pt, create)
       end
       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
 
     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.
 
     # 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
 
     @tags[k] = v
   end
index 9e5621f8b324adad189a9731c89af9b9a3141a04..9d7f48ca42e52a032413f5d8b27071d6e1d553b1 100644 (file)
@@ -194,7 +194,8 @@ class NodeControllerTest < ActionController::TestCase
     content node_xml
     put :update, :id => current_nodes(:visible_node).id
     assert_response :bad_request, 
     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
   end
 
   # test whether string injection is possible
index fcd1557d1370bbf7c750261492e957f537d77798..40ac0bd71c2388447c7fae9d4b44d58d92f18d85 100644 (file)
@@ -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'"
     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
 
   ##
   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'"
     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
 
   ##
   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'"
     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
 
   ##
   end
 
   ##