shrinerb / shrine-memory Goto Github PK
View Code? Open in Web Editor NEW[MERGED] In-memory storage for Shrine
License: MIT License
[MERGED] In-memory storage for Shrine
License: MIT License
I'm not sure if I should be able to do this with the gem anyway. I am using Shrine memory for my test environment. I am trying to write a feature spec to check a process in which a user uploads a CSV, matches up the files headers and it processes it. I've setup shrine memory in the initialiser as below:
if Rails.env.test?
require 'shrine/storage/memory'
Shrine.storages = {
cache: Shrine::Storage::Memory.new,
store: Shrine::Storage::Memory.new,
}
else
I am then adding a csv file in my factory which I want to use later in my controller. I run the FactoryGirl factory in my spec and it all seems to work fine. When inspecting it I get back a url of it in memory. However when I visit the page where I am matching up the headers of the csv file it fails. It says it is unable to find the file in memory. As I need to open the file to find out what the headers are.
Should/would the file created in the factory actually be accessible, if it is meant to be what am I doing wrong? If not is their a way I can force the model to point to a file I store somewhere else?
I'm using the shrine-imgix
plugin in combination with S3 like so:
imgix = Shrine::Storage::Imgix.new(
storage: Shrine::Storage::S3.new(**s3_options),
include_prefix: true, # set to false if you have prefix configured in Imgix source
api_key: "xzy123", #
host: "my-subdomain.imgix.net", # Imgix::Client options
secure_url_token: "abc123", # optional #
)
Shrine.storages[:store] = imgix
I'm also using direct uploads with the presign_endpoint
plugin.
As part of the upload process I show the user a preview of the image they are uploading, before they submit the form. I generate the URL of this image using the following code:
path = []
path << Shrine.storages[:cache].storage.prefix
path << File.basename(params[:key])
path = path.join("/")
imgix = Shrine.storages[:cache].client
url = imgix.path(path).to_url(w: 125, h: 125, dpr: 2, fit: "crop")
For my tests I want to use shrine-memory
, but the above URL generation code relies on the Shrine.storages[:cache].storage
method which isn't available in shrine-memory
.
Is there a workaround for this using this gem? I don't need an actual working URL obviously, but ideally shrine-memory
would be able to mimic's shrine-imgix
interface.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.