Skip to content

Instantly share code, notes, and snippets.

@ichi
Last active February 24, 2017 05:05
Show Gist options
  • Save ichi/fc4e47dde9ad57dbe7c4d2d3149f52f4 to your computer and use it in GitHub Desktop.
Save ichi/fc4e47dde9ad57dbe7c4d2d3149f52f4 to your computer and use it in GitHub Desktop.
refile in rails5
# config/application.rb
module MyApp
class Application < Rails::Application
config.refile = config_for(:refile)
end
end
# NOTE: https://github.com/refile/refile/pull/486
# NOTE: https://github.com/refile/refile/issues/447
gem 'refile', github: 'jastkand/refile', branch: 'mime-types-v3', require: 'refile/rails'
gem 'sinatra', '~> 2.0.0.beta2', require: false
# gem 'refile-s3'
# config/initializers/refile.rb
Refile.types[:video] = Refile::Type.new(:video,
content_type: %w[video/mp4]
)
if Rails.configuration.refile['backend'] == 's3'
require 'refile/s3'
Refile.cache = Refile::S3.new(prefix: "#{Rails.env}/cache", **Rails.configuration.refile['options'].to_hash.symbolize_keys)
Refile.store = Refile::S3.new(prefix: "#{Rails.env}/store", **Rails.configuration.refile['options'].to_hash.symbolize_keys)
end
Refile.app_host = Rails.configuration.refile['app_host']
Refile.cdn_host = Rails.configuration.refile['cdn_host']
default: &default
backend: file_system
options: {}
app_host: 'http://localhost:3000'
cdn_host:
s3: &s3
backend: s3
options:
access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
region: ap-northeast-1
bucket: bucket_name
development:
<<: *default
test:
<<: *default
staging:
<<: *s3
cdn_host: 'https://hogehoge.cloudfront.net'
production:
<<: *s3
cdn_host: 'https://fugafuga.cloudfront.net'
# spec/support/refile.rb
require "refile/file_double"
module RefileHelper
def refile_double(type: nil)
content_type = Refile.types[type].content_type.sample if type
extension = MIME::Types[content_type].first.extensions.first if content_type
Refile::FileDouble.new("dummy", Faker::File.file_name(nil, nil, extension), content_type: content_type)
end
end
FactoryGirl::SyntaxRunner.send(:include, RefileHelper)
RSpec.configure do |config|
config.include RefileHelper
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment