For deleted nodes created via factories, make sure the most recent old_node is also...
[rails.git] / test / factories / node.rb
index 85eded4054ba42bebe350bae2186b413ed7224d0..cbebbb00986096245b972bafa98223472199198c 100644 (file)
@@ -8,5 +8,24 @@ FactoryGirl.define do
     visible true
     timestamp Time.now
     version 1
+
+    trait :deleted do
+      visible false
+    end
+
+    trait :with_history do
+      after(:create) do |node, _evaluator|
+        (1..node.version).each do |n|
+          create(:old_node, :node_id => node.id, :version => n)
+        end
+
+        # For deleted nodes, make sure the most recent old_node is also deleted.
+        if node.visible == false
+          latest = node.old_nodes.find_by(:version => node.version)
+          latest.visible = false
+          latest.save
+        end
+      end
+    end
   end
 end