From 1966c188cfb06b39a47082e2f6c6e33a43668ae5 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 11 Jul 2017 18:53:17 +0200 Subject: Very incomplete first stab --- test/test_helper.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/test_helper.rb') diff --git a/test/test_helper.rb b/test/test_helper.rb index 03593b12c7..878ce8391c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -24,6 +24,9 @@ ActiveStorage::Service.logger = ActiveSupport::Logger.new(STDOUT) require "active_storage/verified_key_with_expiration" ActiveStorage::VerifiedKeyWithExpiration.verifier = ActiveSupport::MessageVerifier.new("Testing") +require "active_storage/variant" +ActiveStorage::Variant.verifier = ActiveSupport::MessageVerifier.new("Testing") + class ActiveSupport::TestCase private def create_blob(data: "Hello world!", filename: "hello.txt", content_type: "text/plain") -- cgit v1.2.3 From 1a9026b485b9b1da0f34c526d4c901406074c508 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 20 Jul 2017 17:33:31 -0500 Subject: Extract routes.rb to engine location for auto configuration --- test/test_helper.rb | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'test/test_helper.rb') diff --git a/test/test_helper.rb b/test/test_helper.rb index 878ce8391c..6081fc1bcf 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -34,17 +34,6 @@ class ActiveSupport::TestCase 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__))) - end - end -end - require "active_storage/attached" ActiveRecord::Base.send :extend, ActiveStorage::Attached::Macros -- cgit v1.2.3 From 0c47740d858cb04c7165bce411584c3b05d155b6 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 21 Jul 2017 15:50:36 -0500 Subject: Hacky way to mount routes for engine controller tests --- test/test_helper.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test/test_helper.rb') diff --git a/test/test_helper.rb b/test/test_helper.rb index 6081fc1bcf..af379ad35a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -34,6 +34,17 @@ class ActiveSupport::TestCase end end +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 + require "active_storage/attached" ActiveRecord::Base.send :extend, ActiveStorage::Attached::Macros -- cgit v1.2.3 From 7f4111185ca6286adbe0ffc1346d416c5fa7dfd3 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 21 Jul 2017 15:51:31 -0500 Subject: Extract variation value object --- test/test_helper.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'test/test_helper.rb') diff --git a/test/test_helper.rb b/test/test_helper.rb index af379ad35a..e98b6e0afc 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -15,7 +15,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,8 +23,8 @@ ActiveStorage::Service.logger = ActiveSupport::Logger.new(STDOUT) require "active_storage/verified_key_with_expiration" ActiveStorage::VerifiedKeyWithExpiration.verifier = ActiveSupport::MessageVerifier.new("Testing") -require "active_storage/variant" -ActiveStorage::Variant.verifier = ActiveSupport::MessageVerifier.new("Testing") +require "active_storage/variation" +ActiveStorage::Variation.verifier = ActiveSupport::MessageVerifier.new("Testing") class ActiveSupport::TestCase private -- cgit v1.2.3 From 796f8330ad441e93590a57521ef8fb80a030fb66 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 21 Jul 2017 16:12:29 -0500 Subject: Fix and test VariantsController --- test/test_helper.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/test_helper.rb') diff --git a/test/test_helper.rb b/test/test_helper.rb index e98b6e0afc..7aa7b50bf3 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" -- cgit v1.2.3 From 08d84e225cca6772aa54dfb7123120fe1070ea30 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 21 Jul 2017 16:34:18 -0500 Subject: Extract test helper for image blob fixtures --- test/test_helper.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/test_helper.rb') diff --git a/test/test_helper.rb b/test/test_helper.rb index 7aa7b50bf3..69ba76b9c4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -33,6 +33,12 @@ class ActiveSupport::TestCase 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 end require "action_controller" -- cgit v1.2.3 From f3b092a6e6f6d873e14ebe1e612028ef7ac15e4a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 21 Jul 2017 16:45:55 -0500 Subject: Test actual transformation via controller too --- test/test_helper.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/test_helper.rb') diff --git a/test/test_helper.rb b/test/test_helper.rb index 69ba76b9c4..20b22049b3 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -39,6 +39,12 @@ class ActiveSupport::TestCase 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" -- cgit v1.2.3