2017-07-21 21:12:29 +00:00
|
|
|
$LOAD_PATH << File.expand_path("../../app/controllers", __FILE__)
|
2017-07-22 14:47:24 +00:00
|
|
|
$LOAD_PATH << File.expand_path("../../app/models", __FILE__)
|
|
|
|
$LOAD_PATH << File.expand_path("../../app/jobs", __FILE__)
|
2017-07-21 21:12:29 +00:00
|
|
|
|
2017-07-01 10:06:08 +00:00
|
|
|
require "bundler/setup"
|
|
|
|
require "active_support"
|
2017-07-04 16:10:53 +00:00
|
|
|
require "active_support/test_case"
|
2017-07-01 10:06:08 +00:00
|
|
|
require "active_support/testing/autorun"
|
|
|
|
require "byebug"
|
|
|
|
|
2017-07-22 15:00:16 +00:00
|
|
|
require "active_job"
|
|
|
|
ActiveJob::Base.queue_adapter = :test
|
|
|
|
ActiveJob::Base.logger = nil
|
|
|
|
|
2017-07-06 09:33:29 +00:00
|
|
|
require "active_storage"
|
2017-07-09 16:03:13 +00:00
|
|
|
|
|
|
|
require "active_storage/service"
|
|
|
|
require "yaml"
|
|
|
|
SERVICE_CONFIGURATIONS = begin
|
|
|
|
YAML.load_file(File.expand_path("../service/configurations.yml", __FILE__)).deep_symbolize_keys
|
|
|
|
rescue Errno::ENOENT
|
|
|
|
puts "Missing service configuration file in test/service/configurations.yml"
|
|
|
|
{}
|
|
|
|
end
|
|
|
|
|
2017-07-24 19:35:36 +00:00
|
|
|
require "active_storage/blob"
|
2017-07-09 11:23:21 +00:00
|
|
|
require "active_storage/service/disk_service"
|
2017-07-09 20:22:20 +00:00
|
|
|
require "tmpdir"
|
|
|
|
ActiveStorage::Blob.service = ActiveStorage::Service::DiskService.new(root: Dir.mktmpdir("active_storage_tests"))
|
2017-07-09 15:04:28 +00:00
|
|
|
ActiveStorage::Service.logger = ActiveSupport::Logger.new(STDOUT)
|
2017-07-03 19:06:09 +00:00
|
|
|
|
2017-07-23 16:03:25 +00:00
|
|
|
ActiveStorage.verifier = ActiveSupport::MessageVerifier.new("Testing")
|
2017-07-11 16:53:17 +00:00
|
|
|
|
2017-07-04 16:10:53 +00:00
|
|
|
class ActiveSupport::TestCase
|
2017-07-26 16:51:02 +00:00
|
|
|
self.file_fixture_path = File.expand_path("../fixtures/files", __FILE__)
|
|
|
|
|
2017-07-04 16:10:53 +00:00
|
|
|
private
|
|
|
|
def create_blob(data: "Hello world!", filename: "hello.txt", content_type: "text/plain")
|
2017-07-06 09:33:29 +00:00
|
|
|
ActiveStorage::Blob.create_after_upload! io: StringIO.new(data), filename: filename, content_type: content_type
|
2017-07-04 16:10:53 +00:00
|
|
|
end
|
2017-07-21 21:34:18 +00:00
|
|
|
|
|
|
|
def create_image_blob(filename: "racecar.jpg", content_type: "image/jpeg")
|
|
|
|
ActiveStorage::Blob.create_after_upload! \
|
2017-07-26 16:51:02 +00:00
|
|
|
io: file_fixture(filename).open,
|
2017-07-21 21:34:18 +00:00
|
|
|
filename: filename, content_type: content_type
|
|
|
|
end
|
2017-07-26 16:51:02 +00:00
|
|
|
|
2017-07-26 01:03:48 +00: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 16:51:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
def assert_equal_image_dimensions(fixture_filename, variant)
|
|
|
|
expected_image, actual_image = read_image_fixture(fixture_filename), read_image_variant(variant)
|
|
|
|
|
|
|
|
assert_equal expected_image.width, actual_image.width
|
|
|
|
assert_equal expected_image.height, actual_image.height
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_equal_image_colorspace(fixture_filename, variant)
|
|
|
|
expected_image, actual_image = read_image_fixture(fixture_filename), read_image_variant(variant)
|
|
|
|
|
|
|
|
assert_equal expected_image.colorspace, actual_image.colorspace
|
|
|
|
end
|
|
|
|
|
|
|
|
def read_image_fixture(fixture_filename)
|
|
|
|
MiniMagick::Image.open file_fixture(fixture_filename)
|
|
|
|
end
|
2017-07-26 01:03:48 +00:00
|
|
|
|
2017-07-26 16:51:02 +00:00
|
|
|
def read_image_variant(variant)
|
|
|
|
MiniMagick::Image.open variant.service.send(:path_for, variant.key)
|
2017-07-21 21:45:55 +00:00
|
|
|
end
|
2017-07-05 13:18:50 +00:00
|
|
|
end
|
|
|
|
|
2017-07-21 20:50:36 +00:00
|
|
|
require "action_controller"
|
|
|
|
require "action_controller/test_case"
|
|
|
|
class ActionController::TestCase
|
|
|
|
Routes = ActionDispatch::Routing::RouteSet.new.tap do |routes|
|
|
|
|
routes.draw do
|
|
|
|
# FIXME: Hacky way to avoid having to instantiate the real engine
|
|
|
|
eval(File.readlines(File.expand_path("../../config/routes.rb", __FILE__)).slice(1..-2).join("\n"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-06 09:33:29 +00:00
|
|
|
require "active_storage/attached"
|
|
|
|
ActiveRecord::Base.send :extend, ActiveStorage::Attached::Macros
|
2017-07-23 22:35:25 +00:00
|
|
|
|
|
|
|
require "global_id"
|
|
|
|
GlobalID.app = "ActiveStorageExampleApp"
|
|
|
|
ActiveRecord::Base.send :include, GlobalID::Identification
|