Given a model that has an ActiveStorage attachment
class MyObject
has_one_attached :avatar
end
In a dev environment I am able to retrive the avatar as a StringIO object.
obj = MyObject.new( { valid params } )
file = File.open( Rails.root.join( "spec/support/images/test_image.jpg" ))
obj.avatar.attach( io: file, filename: "test_image.jpg" )
obj.save
version = obj.avatar.variant( resize: '200x200>').processed
version_url = Rails.application.routes.url_helpers.url_for( version )
download = open(version_url)
download.class
=> StringIO
When I attempt to do the same think in a test environment, open(version_url)
returns
Errno::ECONNREFUSED Exception: Failed to open TCP connection to localhost:3000 (Connection refused - connect(2) for "localhost" port 3000)
Has anyone managed to successfully download activestorage attachments within a test? How should I configure the test environment to achieve this?
My test environment already has
config.active_storage.service = :test
Rails.application.routes.default_url_options = {host: "localhost:3000"}
What have I overlooked?
EDIT
#storage.yml
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>