2017-08-12 08:32:15 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-27 16:15:38 -04:00
|
|
|
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
|
2017-07-21 17:12:29 -04:00
|
|
|
|
2017-07-01 06:06:08 -04:00
|
|
|
require "bundler/setup"
|
|
|
|
require "active_support"
|
2017-07-04 12:10:53 -04:00
|
|
|
require "active_support/test_case"
|
2017-07-01 06:06:08 -04:00
|
|
|
require "active_support/testing/autorun"
|
2017-08-10 15:58:30 -04:00
|
|
|
|
|
|
|
begin
|
|
|
|
require "byebug"
|
|
|
|
rescue LoadError
|
|
|
|
end
|
2017-07-01 06:06:08 -04:00
|
|
|
|
2017-07-22 11:00:16 -04:00
|
|
|
require "active_job"
|
|
|
|
ActiveJob::Base.queue_adapter = :test
|
2017-08-10 15:58:30 -04:00
|
|
|
ActiveJob::Base.logger = ActiveSupport::Logger.new(nil)
|
2017-07-22 11:00:16 -04:00
|
|
|
|
2017-08-07 05:40:20 -04:00
|
|
|
# Filter out Minitest backtrace while allowing backtrace from other libraries
|
|
|
|
# to be shown.
|
|
|
|
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
|
|
|
|
2017-07-09 12:03:13 -04:00
|
|
|
require "yaml"
|
|
|
|
SERVICE_CONFIGURATIONS = begin
|
2017-08-01 12:06:39 -04:00
|
|
|
erb = ERB.new(Pathname.new(File.expand_path("../service/configurations.yml", __FILE__)).read)
|
|
|
|
configuration = YAML.load(erb.result) || {}
|
|
|
|
configuration.deep_symbolize_keys
|
2017-07-09 12:03:13 -04:00
|
|
|
rescue Errno::ENOENT
|
|
|
|
puts "Missing service configuration file in test/service/configurations.yml"
|
|
|
|
{}
|
|
|
|
end
|
|
|
|
|
2017-07-09 16:22:20 -04:00
|
|
|
require "tmpdir"
|
|
|
|
ActiveStorage::Blob.service = ActiveStorage::Service::DiskService.new(root: Dir.mktmpdir("active_storage_tests"))
|
2017-08-17 09:47:23 -04:00
|
|
|
ActiveStorage::Service.logger = ActiveSupport::Logger.new(nil)
|
2017-07-03 15:06:09 -04:00
|
|
|
|
2017-07-23 12:03:25 -04:00
|
|
|
ActiveStorage.verifier = ActiveSupport::MessageVerifier.new("Testing")
|
2017-07-11 12:53:17 -04:00
|
|
|
|
2017-07-04 12:10:53 -04:00
|
|
|
class ActiveSupport::TestCase
|
2017-07-26 12:51:02 -04:00
|
|
|
self.file_fixture_path = File.expand_path("../fixtures/files", __FILE__)
|
|
|
|
|
2017-07-04 12:10:53 -04:00
|
|
|
private
|
|
|
|
def create_blob(data: "Hello world!", filename: "hello.txt", content_type: "text/plain")
|
2017-07-06 05:33:29 -04:00
|
|
|
ActiveStorage::Blob.create_after_upload! io: StringIO.new(data), filename: filename, content_type: content_type
|
2017-07-04 12:10:53 -04:00
|
|
|
end
|
2017-07-21 17:34:18 -04:00
|
|
|
|
|
|
|
def create_image_blob(filename: "racecar.jpg", content_type: "image/jpeg")
|
|
|
|
ActiveStorage::Blob.create_after_upload! \
|
2017-07-26 12:51:02 -04:00
|
|
|
io: file_fixture(filename).open,
|
2017-07-21 17:34:18 -04:00
|
|
|
filename: filename, content_type: content_type
|
|
|
|
end
|
2017-07-26 14:58:59 -04:00
|
|
|
|
2017-07-25 21:03:48 -04:00
|
|
|
def create_blob_before_direct_upload(filename: "hello.txt", byte_size:, checksum:, content_type: "text/plain")
|
|
|
|
ActiveStorage::Blob.create_before_direct_upload! filename: filename, byte_size: byte_size, checksum: checksum, content_type: content_type
|
|
|
|
end
|
|
|
|
|
2017-07-26 12:51:02 -04:00
|
|
|
def read_image_variant(variant)
|
|
|
|
MiniMagick::Image.open variant.service.send(:path_for, variant.key)
|
2017-07-21 17:45:55 -04:00
|
|
|
end
|
2017-07-05 09:18:50 -04:00
|
|
|
end
|
|
|
|
|
2017-07-23 18:35:25 -04:00
|
|
|
require "global_id"
|
|
|
|
GlobalID.app = "ActiveStorageExampleApp"
|
|
|
|
ActiveRecord::Base.send :include, GlobalID::Identification
|
2017-08-10 15:58:30 -04:00
|
|
|
|
|
|
|
class User < ActiveRecord::Base
|
|
|
|
has_one_attached :avatar
|
|
|
|
has_many_attached :highlights
|
|
|
|
end
|