Files
grecia/spec/factories/files.rb
Javi Martín 8eea6f585a Remove hack to allow IO files in Active Storage
We were using this hack in order to allow `File.new` attachments in
tests files. However, we can use the `fixture_file_upload` helper
instead.

Just like it happened with `file_fixture`, this helper method doesn't
work in fixtures, so in this case we're using `Rack::Test::UploadedFile`
instead.
2022-02-23 19:00:33 +01:00

65 lines
1.6 KiB
Ruby

FactoryBot.define do
factory :image do
attachment { Rack::Test::UploadedFile.new("spec/fixtures/files/clippy.jpg") }
title { "Lorem ipsum dolor sit amet" }
association :user, factory: :user
trait :proposal_image do
association :imageable, factory: :proposal
end
trait :budget_investment_image do
association :imageable, factory: :budget_investment
end
end
factory :document do
sequence(:title) { |n| "Document title #{n}" }
association :user, factory: :user
attachment { Rack::Test::UploadedFile.new("spec/fixtures/files/empty.pdf") }
trait :proposal_document do
association :documentable, factory: :proposal
end
trait :budget_investment_document do
association :documentable, factory: :budget_investment
end
trait :poll_question_document do
association :documentable, factory: :poll_question
end
trait :admin do
admin { true }
end
end
factory :direct_upload do
user
trait :proposal do
resource_type { "Proposal" }
end
trait :budget_investment do
resource_type { "Budget::Investment" }
end
trait :documents do
resource_relation { "documents" }
attachment { Rack::Test::UploadedFile.new("spec/fixtures/files/empty.pdf") }
end
trait :image do
resource_relation { "image" }
attachment { Rack::Test::UploadedFile.new("spec/fixtures/files/clippy.jpg") }
end
initialize_with { new(attributes) }
end
factory :active_storage_blob, class: "ActiveStorage::Blob" do
filename { "sample.pdf" }
byte_size { 3000 }
checksum { SecureRandom.hex(32) }
end
end