2018-11-29 20:19:38 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
FactoryBot.define do
|
2018-12-02 11:44:02 -05:00
|
|
|
factory :empty_passport, class: Passport do
|
2019-01-30 22:04:42 -05:00
|
|
|
association :person, factory: :initial_person
|
|
|
|
|
2018-12-02 09:24:28 -05:00
|
|
|
confirmed { false }
|
2018-12-02 11:44:02 -05:00
|
|
|
|
2019-07-08 09:59:34 -04:00
|
|
|
trait :with_map do
|
2018-12-02 15:29:39 -05:00
|
|
|
after :create do |passport, _evaluator|
|
|
|
|
create :passport_map, passport: passport
|
|
|
|
end
|
2018-12-02 11:44:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :with_image do
|
|
|
|
transient do
|
|
|
|
image_filename { image_fixture }
|
|
|
|
image_fixture { "passport_image_#{rand(1..4)}.jpg" }
|
|
|
|
|
|
|
|
image_path { Rails.root.join 'fixtures', image_fixture }
|
|
|
|
end
|
|
|
|
|
|
|
|
after :build do |passport, evaluator|
|
|
|
|
passport.images.attach(
|
|
|
|
filename: evaluator.image_filename,
|
2019-04-28 09:34:46 -04:00
|
|
|
io: File.open(evaluator.image_path),
|
2018-12-02 11:44:02 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2018-12-02 09:24:28 -05:00
|
|
|
end
|
|
|
|
|
2019-07-08 09:59:34 -04:00
|
|
|
factory :passport_with_map,
|
2018-12-02 11:44:02 -05:00
|
|
|
parent: :empty_passport,
|
2019-07-08 09:59:34 -04:00
|
|
|
traits: %i[with_map]
|
2018-12-01 04:59:41 -05:00
|
|
|
|
2018-12-02 11:44:02 -05:00
|
|
|
factory :passport_with_image,
|
|
|
|
parent: :empty_passport,
|
|
|
|
traits: %i[with_image]
|
|
|
|
|
2019-07-08 09:59:34 -04:00
|
|
|
factory :passport_with_map_and_image,
|
2018-12-02 11:44:02 -05:00
|
|
|
parent: :empty_passport,
|
2019-07-08 09:59:34 -04:00
|
|
|
traits: %i[with_map with_image] do
|
2018-12-02 11:44:02 -05:00
|
|
|
trait :with_almost_enough_confirmations do
|
|
|
|
after :create do |passport, _evaluator|
|
|
|
|
create_list :passport_confirmation,
|
|
|
|
Passport::REQUIRED_CONFIRMATIONS - 1,
|
|
|
|
passport: passport
|
|
|
|
end
|
2018-12-01 04:59:41 -05:00
|
|
|
end
|
2018-11-29 22:41:57 -05:00
|
|
|
|
2018-12-02 11:44:02 -05:00
|
|
|
trait :with_enough_confirmations do
|
|
|
|
after :create do |passport, _evaluator|
|
|
|
|
create_list :passport_confirmation,
|
|
|
|
Passport::REQUIRED_CONFIRMATIONS,
|
|
|
|
passport: passport
|
|
|
|
end
|
2018-11-29 22:41:57 -05:00
|
|
|
end
|
2018-11-29 20:19:38 -05:00
|
|
|
end
|
2018-11-30 04:27:33 -05:00
|
|
|
|
2018-12-01 12:18:37 -05:00
|
|
|
factory :passport_with_almost_enough_confirmations,
|
2019-07-08 09:59:34 -04:00
|
|
|
parent: :passport_with_map_and_image,
|
2018-12-02 11:44:02 -05:00
|
|
|
traits: %i[with_almost_enough_confirmations]
|
2018-12-01 12:18:37 -05:00
|
|
|
|
|
|
|
factory :passport_with_enough_confirmations,
|
2019-07-08 09:59:34 -04:00
|
|
|
parent: :passport_with_map_and_image,
|
2018-12-02 11:44:02 -05:00
|
|
|
traits: %i[with_enough_confirmations]
|
2018-12-01 12:18:37 -05:00
|
|
|
|
|
|
|
factory :confirmed_passport, parent: :passport_with_enough_confirmations do
|
|
|
|
after :create do |passport, _evaluator|
|
|
|
|
passport.update! confirmed: true
|
|
|
|
end
|
2018-11-30 04:27:33 -05:00
|
|
|
end
|
2018-11-29 20:19:38 -05:00
|
|
|
end
|