]> git.openstreetmap.org Git - rails.git/blob - test/factories/relation.rb
Merge remote-tracking branch 'upstream/pull/4439'
[rails.git] / test / factories / relation.rb
1 FactoryBot.define do
2   factory :relation do
3     timestamp { Time.now.utc }
4     visible { true }
5     version { 1 }
6
7     changeset
8
9     trait :deleted do
10       visible { false }
11     end
12
13     trait :with_history do
14       after(:create) do |relation, _evaluator|
15         (1..relation.version).each do |n|
16           create(:old_relation, :relation_id => relation.id, :version => n, :changeset => relation.changeset)
17         end
18
19         # For deleted relations, make sure the most recent old_relation is also deleted.
20         if relation.visible == false
21           latest = relation.old_relations.find_by(:version => relation.version)
22           latest.visible = false
23           latest.save
24         end
25       end
26     end
27   end
28 end