diff options
Diffstat (limited to 'activestorage/test')
-rw-r--r-- | activestorage/test/database/setup.rb | 2 | ||||
-rwxr-xr-x | activestorage/test/dummy/bin/bundle | 2 | ||||
-rw-r--r-- | activestorage/test/models/preview_test.rb | 2 | ||||
-rw-r--r-- | activestorage/test/models/representation_test.rb | 41 | ||||
-rw-r--r-- | activestorage/test/models/variant_test.rb | 5 | ||||
-rw-r--r-- | activestorage/test/test_helper.rb | 6 |
6 files changed, 53 insertions, 5 deletions
diff --git a/activestorage/test/database/setup.rb b/activestorage/test/database/setup.rb index 87564499e6..705650a25d 100644 --- a/activestorage/test/database/setup.rb +++ b/activestorage/test/database/setup.rb @@ -3,5 +3,5 @@ require_relative "create_users_migration" ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") -ActiveRecord::Migrator.migrate File.expand_path("../../../db/migrate", __FILE__) +ActiveRecord::Migrator.migrate File.expand_path("../../db/migrate", __dir__) ActiveStorageCreateUsers.migrate(:up) diff --git a/activestorage/test/dummy/bin/bundle b/activestorage/test/dummy/bin/bundle index 277e128251..5015ba6f8b 100755 --- a/activestorage/test/dummy/bin/bundle +++ b/activestorage/test/dummy/bin/bundle @@ -1,5 +1,5 @@ #!/usr/bin/env ruby # frozen_string_literal: true -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__) +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) load Gem.bin_path("bundler", "bundle") diff --git a/activestorage/test/models/preview_test.rb b/activestorage/test/models/preview_test.rb index 317a2d5c58..bcd8442f4b 100644 --- a/activestorage/test/models/preview_test.rb +++ b/activestorage/test/models/preview_test.rb @@ -7,6 +7,7 @@ class ActiveStorage::PreviewTest < ActiveSupport::TestCase test "previewing a PDF" do blob = create_file_blob(filename: "report.pdf", content_type: "application/pdf") preview = blob.preview(resize: "640x280").processed + assert preview.image.attached? assert_equal "report.png", preview.image.filename.to_s assert_equal "image/png", preview.image.content_type @@ -19,6 +20,7 @@ class ActiveStorage::PreviewTest < ActiveSupport::TestCase test "previewing an MP4 video" do blob = create_file_blob(filename: "video.mp4", content_type: "video/mp4") preview = blob.preview(resize: "640x280").processed + assert preview.image.attached? assert_equal "video.png", preview.image.filename.to_s assert_equal "image/png", preview.image.content_type diff --git a/activestorage/test/models/representation_test.rb b/activestorage/test/models/representation_test.rb new file mode 100644 index 0000000000..29fe61aee4 --- /dev/null +++ b/activestorage/test/models/representation_test.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require "test_helper" +require "database/setup" + +class ActiveStorage::RepresentationTest < ActiveSupport::TestCase + test "representing an image" do + blob = create_file_blob + representation = blob.representation(resize: "100x100").processed + + image = read_image(representation.image) + assert_equal 100, image.width + assert_equal 67, image.height + end + + test "representing a PDF" do + blob = create_file_blob(filename: "report.pdf", content_type: "application/pdf") + representation = blob.representation(resize: "640x280").processed + + image = read_image(representation.image) + assert_equal 612, image.width + assert_equal 792, image.height + end + + test "representing an MP4 video" do + blob = create_file_blob(filename: "video.mp4", content_type: "video/mp4") + representation = blob.representation(resize: "640x280").processed + + image = read_image(representation.image) + assert_equal 640, image.width + assert_equal 480, image.height + end + + test "representing an unrepresentable blob" do + blob = create_blob + + assert_raises ActiveStorage::Blob::UnrepresentableError do + blob.representation resize: "100x100" + end + end +end diff --git a/activestorage/test/models/variant_test.rb b/activestorage/test/models/variant_test.rb index d7cbef4e55..b7d20ab55a 100644 --- a/activestorage/test/models/variant_test.rb +++ b/activestorage/test/models/variant_test.rb @@ -26,4 +26,9 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase assert_equal 67, image.height assert_match(/Gray/, image.colorspace) end + + test "service_url doesn't grow in length despite long variant options" do + variant = @blob.variant(font: "a" * 10_000).processed + assert_operator variant.service_url.length, :<, 500 + end end diff --git a/activestorage/test/test_helper.rb b/activestorage/test/test_helper.rb index dd37239060..60656feb80 100644 --- a/activestorage/test/test_helper.rb +++ b/activestorage/test/test_helper.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../../test/dummy/config/environment.rb", __FILE__) +require_relative "dummy/config/environment.rb" require "bundler/setup" require "active_support" @@ -23,7 +23,7 @@ Minitest.backtrace_filter = Minitest::BacktraceFilter.new require "yaml" SERVICE_CONFIGURATIONS = begin - erb = ERB.new(Pathname.new(File.expand_path("../service/configurations.yml", __FILE__)).read) + erb = ERB.new(Pathname.new(File.expand_path("service/configurations.yml", __dir__)).read) configuration = YAML.load(erb.result) || {} configuration.deep_symbolize_keys rescue Errno::ENOENT @@ -38,7 +38,7 @@ ActiveStorage::Service.logger = ActiveSupport::Logger.new(nil) ActiveStorage.verifier = ActiveSupport::MessageVerifier.new("Testing") class ActiveSupport::TestCase - self.file_fixture_path = File.expand_path("../fixtures/files", __FILE__) + self.file_fixture_path = File.expand_path("fixtures/files", __dir__) private def create_blob(data: "Hello world!", filename: "hello.txt", content_type: "text/plain") |