1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activestorage/test/test_helper.rb

70 lines
2.3 KiB
Ruby
Raw Normal View History

# 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"
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
ActiveJob::Base.logger = ActiveSupport::Logger.new(nil)
2017-07-22 11:00:16 -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
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
require "tmpdir"
ActiveStorage::Blob.service = ActiveStorage::Service::DiskService.new(root: Dir.mktmpdir("active_storage_tests"))
ActiveStorage::Service.logger = ActiveSupport::Logger.new(nil)
2017-07-03 15:06:09 -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
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")
ActiveStorage::Blob.create_after_upload! io: StringIO.new(data), filename: filename, content_type: content_type
2017-07-04 12:10:53 -04:00
end
def create_image_blob(filename: "racecar.jpg", content_type: "image/jpeg")
ActiveStorage::Blob.create_after_upload! \
io: file_fixture(filename).open,
filename: filename, content_type: content_type
end
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
def read_image_variant(variant)
MiniMagick::Image.open variant.service.send(:path_for, variant.key)
end
2017-07-05 09:18:50 -04:00
end
require "global_id"
GlobalID.app = "ActiveStorageExampleApp"
ActiveRecord::Base.send :include, GlobalID::Identification
class User < ActiveRecord::Base
has_one_attached :avatar
has_many_attached :highlights
end