]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/way.rb
Added a bunch more tests on the API 0.6. Fixed node/way/relation from_xml code to...
[rails.git] / app / models / way.rb
index 05b412b299f888bfab09026bed4b89d0414c3cb4..90458006e8cf15a64a85bd797a5bf6a4116d2130 100644 (file)
@@ -1,5 +1,7 @@
 class Way < ActiveRecord::Base
   require 'xml/libxml'
+  
+  include ConsistencyValidations
 
   set_table_name 'current_ways'
 
@@ -167,6 +169,11 @@ class Way < ActiveRecord::Base
 
   def add_tag_keyval(k, v)
     @tags = Hash.new unless @tags
+
+    # 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
+
     @tags[k] = v
   end
 
@@ -210,13 +217,23 @@ class Way < ActiveRecord::Base
     if !new_way.preconditions_ok?
       raise OSM::APIPreconditionFailedError.new
     end
-    self.changeset_id = changeset_id
+    self.changeset_id = new_way.changeset_id
     self.tags = new_way.tags
     self.nds = new_way.nds
     self.visible = true
     save_with_history!
   end
 
+  def create_with_history(user)
+    check_create_consistency(self, user)
+    if !self.preconditions_ok?
+      raise OSM::APIPreconditionFailedError.new
+    end
+    self.version = 0
+    self.visible = true
+    save_with_history!
+  end
+
   def preconditions_ok?
     return false if self.nds.empty?
     self.nds.each do |n|