]> git.openstreetmap.org Git - rails.git/blobdiff - test/factories/way.rb
Fix another hostip stub
[rails.git] / test / factories / way.rb
index 7c35316478b17a0e941e5162292b781859f1343a..68826e91942e98c8180949e2ba31bde7cc4c9913 100644 (file)
@@ -1,4 +1,4 @@
-FactoryGirl.define do
+FactoryBot.define do
   factory :way do
     timestamp Time.now
     visible true
@@ -9,5 +9,32 @@ FactoryGirl.define do
     trait :deleted do
       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
+      end
+
+      after(:create) do |way, evaluator|
+        (1..evaluator.nodes_count).each do |n|
+          create(:way_node, :way => way, :sequence_id => n)
+        end
+      end
+    end
   end
 end