openstreetmap-website/test/factories/traces.rb
Andy Allan 1cb0767e3d Copy trace fixture files, rather than symlinking
Since we are using tmpdirs in order to enable parallel testing, we
can go the full hog and drop the fakefs too and just copy all the
files directly into the tmpdir. If a test makes changes (e.g.
changing the icon file during an import) the copy in the tmpdir is
thrown away at the end of the test anyway.
2020-03-18 15:35:55 +01:00

31 lines
944 B
Ruby

FactoryBot.define do
factory :trace do
sequence(:name) { |n| "Trace #{n}.gpx" }
sequence(:description) { |n| "This is trace #{n}" }
user
timestamp { Time.now }
inserted { true }
size { 10 }
trait :deleted do
visible { false }
end
transient do
fixture { nil }
end
after(:create) do |trace, evaluator|
if evaluator.fixture
FileUtils.copy(Rails.root.join("test", "gpx", "fixtures", "#{evaluator.fixture}.gpx"),
File.join(Settings.gpx_trace_dir, "#{trace.id}.gpx"))
FileUtils.copy(Rails.root.join("test", "gpx", "fixtures", "#{evaluator.fixture}.gif"),
File.join(Settings.gpx_image_dir, "#{trace.id}.gif"))
FileUtils.copy(Rails.root.join("test", "gpx", "fixtures", "#{evaluator.fixture}_icon.gif"),
File.join(Settings.gpx_image_dir, "#{trace.id}_icon.gif"))
end
end
end
end