ActiveStorage::FixtureSet.blob - no implicit conversion of nil into String

Viewed 19

I'm attempting to get fixtures working for ActiveStorage while using Rspec, on Rails 7.

Here's the relationship:

# models/recording.rb
class Recordings
   has_one_attached :file

I've got the set-up recommended in the docs:

# config/storage.yml
test_fixtures:
  service: Disk
  root: <%= Rails.root.join("tmp/storage_fixtures") %>
# spec/fixtures/active_storage/attachments.yml
recording_file:
  name: recording_file
  record: review (Recording) # This exists in fixtures
  blob: recording_file_blob
# spec/fixtures/active_storage/blobs.yml
recording_file_blob: <%= ActiveStorage::FixtureSet.blob(
  filename: "test.jpg", # exists at spec/fixtures/files/test.jpg
  service_name: "test_fixtures") %>

However when running rspec, I get no implicit conversion of nil into String

It points to the error being here: activestorage-7.0.3.1/lib/active_storage/fixture_set.rb:68:in prepare'`

And that line seems to suggest that I'm missing a filename? But I'm clearly not?

1 Answers

The docs say the default path is test/fixtures/files, Maybe you need to make some config to use spec/fixtures/files.


Or you can just use rspec file-fixture

Related