]> git.openstreetmap.org Git - rails.git/blobdiff - test/factories/relation.rb
Simplify margins when showing diary entries
[rails.git] / test / factories / relation.rb
index f53245c1b6bd11b9c51de7b8c35a48daeb2970ea..8bb00e287e4045e3ada93f7a154b9f26412660e1 100644 (file)
@@ -1,9 +1,28 @@
-FactoryGirl.define do
+FactoryBot.define do
   factory :relation do
-    timestamp Time.now
-    visible true
-    version 1
+    timestamp { Time.now }
+    visible { true }
+    version { 1 }
 
     changeset
+
+    trait :deleted do
+      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