diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-07-31 15:21:22 -0400 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-07-31 15:21:22 -0400 |
commit | 9330d01ada9ce6768d14c59b99cd3860e209737a (patch) | |
tree | e4328b4e59b52dae35241f835f786641d1ff8595 /activestorage/test/test_helper.rb | |
parent | 0d58e7e478e79c2d6b2a39a4444d2a17a903b2a6 (diff) | |
parent | 3f4a7218a4a4923a0e7ce1b2eb0d2888ce30da58 (diff) | |
download | rails-9330d01ada9ce6768d14c59b99cd3860e209737a.tar.gz rails-9330d01ada9ce6768d14c59b99cd3860e209737a.tar.bz2 rails-9330d01ada9ce6768d14c59b99cd3860e209737a.zip |
Add 'activestorage/' from commit '3f4a7218a4a4923a0e7ce1b2eb0d2888ce30da58'
git-subtree-dir: activestorage
git-subtree-mainline: 0d58e7e478e79c2d6b2a39a4444d2a17a903b2a6
git-subtree-split: 3f4a7218a4a4923a0e7ce1b2eb0d2888ce30da58
Diffstat (limited to 'activestorage/test/test_helper.rb')
-rw-r--r-- | activestorage/test/test_helper.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/activestorage/test/test_helper.rb b/activestorage/test/test_helper.rb new file mode 100644 index 0000000000..9922c8685c --- /dev/null +++ b/activestorage/test/test_helper.rb @@ -0,0 +1,54 @@ +require File.expand_path("../../test/dummy/config/environment.rb", __FILE__) + +require "bundler/setup" +require "active_support" +require "active_support/test_case" +require "active_support/testing/autorun" +require "byebug" + +require "active_job" +ActiveJob::Base.queue_adapter = :test +ActiveJob::Base.logger = nil + +require "active_storage" + +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 + +require "tmpdir" +ActiveStorage::Blob.service = ActiveStorage::Service::DiskService.new(root: Dir.mktmpdir("active_storage_tests")) +ActiveStorage::Service.logger = ActiveSupport::Logger.new(STDOUT) + +ActiveStorage.verifier = ActiveSupport::MessageVerifier.new("Testing") + +class ActiveSupport::TestCase + self.file_fixture_path = File.expand_path("../fixtures/files", __FILE__) + + 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 + 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 +end + +require "global_id" +GlobalID.app = "ActiveStorageExampleApp" +ActiveRecord::Base.send :include, GlobalID::Identification |