I'm looking for a way to create factories for models which have active storage attachments
I attempted the method in this post
with my factory
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
but I got this error
NoMethodError:
undefined method `fixture_file_upload' for #<FactoryBot::SyntaxRunner:0x000000000208c5f8>
What is the correct way to attach files in ActiveStorage?
Try with Rack::Test::UploadedFile
directly:
file { Rack::Test::UploadedFile.new('path', 'image/png') }