aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_helper.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2017-07-21 16:51:04 -0500
committerGitHub <noreply@github.com>2017-07-21 16:51:04 -0500
commitf0d7ce9e767ffbf7307ed6efaa4a189ae3ea3c0a (patch)
tree545ce85fc61a1e6bcc75110428648dbf9d59a0ac /test/test_helper.rb
parent986a71d26868d296f4c619df85909d1073b6c91f (diff)
parent6ac4fec964e67cf3d7dfbf7726bff9b05aca522c (diff)
downloadrails-f0d7ce9e767ffbf7307ed6efaa4a189ae3ea3c0a.tar.gz
rails-f0d7ce9e767ffbf7307ed6efaa4a189ae3ea3c0a.tar.bz2
rails-f0d7ce9e767ffbf7307ed6efaa4a189ae3ea3c0a.zip
Merge pull request #63 from rails/variants
On-demand variants
Diffstat (limited to 'test/test_helper.rb')
-rw-r--r--test/test_helper.rb22
1 files changed, 19 insertions, 3 deletions
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 03593b12c7..20b22049b3 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -1,3 +1,5 @@
+$LOAD_PATH << File.expand_path("../../app/controllers", __FILE__)
+
require "bundler/setup"
require "active_support"
require "active_support/test_case"
@@ -15,7 +17,6 @@ rescue Errno::ENOENT
{}
end
-
require "active_storage/service/disk_service"
require "tmpdir"
ActiveStorage::Blob.service = ActiveStorage::Service::DiskService.new(root: Dir.mktmpdir("active_storage_tests"))
@@ -24,20 +25,35 @@ ActiveStorage::Service.logger = ActiveSupport::Logger.new(STDOUT)
require "active_storage/verified_key_with_expiration"
ActiveStorage::VerifiedKeyWithExpiration.verifier = ActiveSupport::MessageVerifier.new("Testing")
+require "active_storage/variation"
+ActiveStorage::Variation.verifier = ActiveSupport::MessageVerifier.new("Testing")
+
class ActiveSupport::TestCase
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.open(File.expand_path("../fixtures/files/#{filename}", __FILE__)),
+ filename: filename, content_type: content_type
+ end
+
+ def assert_same_image(fixture_filename, variant)
+ assert_equal \
+ File.binread(File.expand_path("../fixtures/files/#{fixture_filename}", __FILE__)),
+ File.binread(variant.service.send(:path_for, variant.key))
+ end
end
require "action_controller"
require "action_controller/test_case"
-
class ActionController::TestCase
Routes = ActionDispatch::Routing::RouteSet.new.tap do |routes|
routes.draw do
- eval(File.read(File.expand_path("../../lib/active_storage/routes.rb", __FILE__)))
+ # 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