Attaching ActiveStorage files in factorybot
This solution works with rails 6:
factory :post do
# ...
after(:build) do |post|
post.image.attach(
io: File.open(Rails.root.join('test', 'fixture_files', 'test.jpg')),
filename: 'test.jpg',
content_type: 'image/jpeg'
)
end
end
Change your code to the following it will work.
include ActionDispatch::TestProcess
factory :activity_fit_file, class: 'Activity' do
association :user, factory: :user
activity_type {:cycling}
original_activity_log_file { fixture_file_upload("#{Rails.root}/spec/files/example_fit_file.fit") }
end
Try with Rack::Test::UploadedFile
directly:
file { Rack::Test::UploadedFile.new('path', 'image/png') }