1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/factories/passports.rb

72 lines
2 KiB
Ruby
Raw Normal View History

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
2018-12-02 09:24:28 -05:00
confirmed { false }
2018-12-02 11:44:02 -05:00
trait :with_passport_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,
io: File.open(evaluator.image_path),
)
end
end
2018-12-02 09:24:28 -05:00
end
2018-12-02 11:44:02 -05:00
factory :passport_with_passport_map,
parent: :empty_passport,
traits: %i[with_passport_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]
factory :passport_with_passport_map_and_image,
parent: :empty_passport,
traits: %i[with_passport_map with_image] do
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,
2018-12-02 11:44:02 -05:00
parent: :passport_with_passport_map_and_image,
traits: %i[with_almost_enough_confirmations]
2018-12-01 12:18:37 -05:00
factory :passport_with_enough_confirmations,
2018-12-02 11:44:02 -05:00
parent: :passport_with_passport_map_and_image,
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