1
0
Fork 0

Factory generates Passport#image

This commit is contained in:
Alex Kotov 2018-11-30 08:41:57 +05:00
parent 8f9ff5bb21
commit 8f7e316ee0
No known key found for this signature in database
GPG Key ID: 4E831250F47DE154
2 changed files with 17 additions and 0 deletions

View File

@ -23,6 +23,7 @@ Metrics/AbcSize:
Metrics/BlockLength:
Exclude:
- 'config/initializers/*.rb'
- 'factories/**/*.rb'
- 'spec/**/*.rb'
Metrics/LineLength:

View File

@ -2,6 +2,15 @@
FactoryBot.define do
factory :passport do
transient do
image_filename { image_fixture }
image_fixture { "passport_image_#{rand(1..4)}.jpg" }
image_path do
File.join File.expand_path('..', __dir__), 'fixtures', image_fixture
end
end
surname { Faker::Name.last_name }
given_name { Faker::Name.first_name }
patronymic { Faker::Name.first_name }
@ -15,5 +24,12 @@ FactoryBot.define do
"#{rand(0..999).to_s.rjust(3, '0')}-#{rand(0..999).to_s.rjust(3, '0')}"
end
date_of_issue { Faker::Date.backward }
after :create do |passport, evaluator|
passport.image.attach(
filename: evaluator.image_filename,
io: File.open(evaluator.image_path),
)
end
end
end