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/models/attachment_test.rb
2020-01-16 14:14:28 -05:00

52 lines
1.3 KiB
Ruby

# frozen_string_literal: true
require "test_helper"
require "database/setup"
class ActiveStorage::AttachmentTest < ActiveSupport::TestCase
include ActiveJob::TestHelper
setup do
@user = User.create!(name: "Josh")
end
teardown { ActiveStorage::Blob.all.each(&:delete) }
test "analyzing a directly-uploaded blob after attaching it" do
blob = directly_upload_file_blob(filename: "racecar.jpg")
assert_not blob.analyzed?
perform_enqueued_jobs do
@user.highlights.attach(blob)
end
assert blob.reload.analyzed?
assert_equal 4104, blob.metadata[:width]
assert_equal 2736, blob.metadata[:height]
end
test "attaching a un-analyzable blob" do
blob = create_blob(filename: "blank.txt")
assert_not_predicate blob, :analyzed?
assert_no_enqueued_jobs do
@user.highlights.attach(blob)
end
assert_predicate blob.reload, :analyzed?
end
test "mirroring a directly-uploaded blob after attaching it" do
with_service("mirror") do
blob = directly_upload_file_blob
assert_not ActiveStorage::Blob.service.mirrors.second.exist?(blob.key)
perform_enqueued_jobs do
@user.highlights.attach(blob)
end
assert ActiveStorage::Blob.service.mirrors.second.exist?(blob.key)
end
end
end