]> git.openstreetmap.org Git - rails.git/blobdiff - test/factories/way.rb
Merge remote-tracking branch 'upstream/pull/5059'
[rails.git] / test / factories / way.rb
index 89409e807aa0a1088edd3b39ca61c5c3dea903f9..f2093e305ca8c32807939c06a362c7bf4b534dc0 100644 (file)
@@ -1,18 +1,33 @@
-FactoryGirl.define do
+FactoryBot.define do
   factory :way do
-    timestamp Time.now
-    visible true
-    version 1
+    timestamp { Time.now.utc }
+    visible { true }
+    version { 1 }
 
     changeset
 
     trait :deleted do
-      visible false
+      visible { false }
+    end
+
+    trait :with_history do
+      after(:create) do |way, _evaluator|
+        (1..way.version).each do |n|
+          create(:old_way, :way_id => way.id, :version => n, :changeset => way.changeset)
+        end
+
+        # For deleted ways, make sure the most recent old_way is also deleted.
+        if way.visible == false
+          latest = way.old_ways.find_by(:version => way.version)
+          latest.visible = false
+          latest.save
+        end
+      end
     end
 
     factory :way_with_nodes do
       transient do
-        nodes_count 1
+        nodes_count { 1 }
       end
 
       after(:create) do |way, evaluator|