Merge rails_port as of r4613 & fix tests.
[rails.git] / app / models / way.rb
index b564a33..e0a4450 100644 (file)
@@ -142,49 +142,47 @@ class Way < ActiveRecord::Base
     @tags[k] = v
   end
 
-  def save_with_history
-    begin
-      Way.transaction do
-        t = Time.now
-        self.timestamp = t
-        self.save!
+  def save_with_history!
+    t = Time.now
 
-        tags = self.tags
+    Way.transaction do
+      self.timestamp = t
+      self.save!
+    end
 
-        WayTag.delete_all(['id = ?', self.id])
+    WayTag.transaction do
+      tags = self.tags
 
-        tags.each do |k,v|
-          tag = WayTag.new
-          tag.k = k
-          tag.v = v
-          tag.id = self.id
-          tag.save!
-        end
+      WayTag.delete_all(['id = ?', self.id])
 
-        nds = self.nds
+      tags.each do |k,v|
+        tag = WayTag.new
+        tag.k = k
+        tag.v = v
+        tag.id = self.id
+        tag.save!
+      end
+    end
 
-        WayNode.delete_all(['id = ?', self.id])
+    WayNode.transaction do
+      nds = self.nds
 
-        i = 1
-        nds.each do |n|
-          nd = WayNode.new
-          nd.id = self.id
-          nd.node_id = n
-          nd.sequence_id = i
-          nd.save!
-          i += 1
-        end
+      WayNode.delete_all(['id = ?', self.id])
 
-        old_way = OldWay.from_way(self)
-        old_way.timestamp = t
-        old_way.save_with_dependencies!
+      i = 1
+      nds.each do |n|
+        nd = WayNode.new
+        nd.id = self.id
+        nd.node_id = n
+        nd.sequence_id = i
+        nd.save!
+        i += 1
       end
-
-      return true
-    rescue => ex
-      puts ex
-      return nil
     end
+
+    old_way = OldWay.from_way(self)
+    old_way.timestamp = t
+    old_way.save_with_dependencies!
   end
 
   def preconditions_ok?