]> git.openstreetmap.org Git - rails.git/blobdiff - test/factories/relation.rb
Underline time elements that have a title
[rails.git] / test / factories / relation.rb
index 1631b92de2d92efe1a2dee11776952b3707cab89..6d43df0a37290dbfb3750b6d3c36f52e2b0d769a 100644 (file)
@@ -1,13 +1,28 @@
-FactoryGirl.define do
+FactoryBot.define do
   factory :relation 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 |relation, _evaluator|
+        (1..relation.version).each do |n|
+          create(:old_relation, :relation_id => relation.id, :version => n, :changeset => relation.changeset)
+        end
+
+        # For deleted relations, make sure the most recent old_relation is also deleted.
+        if relation.visible == false
+          latest = relation.old_relations.find_by(:version => relation.version)
+          latest.visible = false
+          latest.save
+        end
+      end
     end
   end
 end