diff options
author | fatkodima <fatkodima123@gmail.com> | 2018-02-12 22:09:52 +0200 |
---|---|---|
committer | fatkodima <fatkodima123@gmail.com> | 2018-02-12 22:13:00 +0200 |
commit | 0c463f50eaf939042ea9561eed85146612daab5e (patch) | |
tree | 2cb9aff65b571af6c35e2fbbef014bb8f8acfa7d /activestorage/test | |
parent | 18b13d768fc1ecb8a209c9b1d3c1ddcfe27e3737 (diff) | |
download | rails-0c463f50eaf939042ea9561eed85146612daab5e.tar.gz rails-0c463f50eaf939042ea9561eed85146612daab5e.tar.bz2 rails-0c463f50eaf939042ea9561eed85146612daab5e.zip |
Add ActiveStorage::Blob.unattached scope
Diffstat (limited to 'activestorage/test')
-rw-r--r-- | activestorage/test/models/blob_test.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/activestorage/test/models/blob_test.rb b/activestorage/test/models/blob_test.rb index 9b555f9a1d..779e47ffb6 100644 --- a/activestorage/test/models/blob_test.rb +++ b/activestorage/test/models/blob_test.rb @@ -7,6 +7,23 @@ require "active_support/testing/method_call_assertions" class ActiveStorage::BlobTest < ActiveSupport::TestCase include ActiveSupport::Testing::MethodCallAssertions + test ".unattached scope returns not attached blobs" do + class UserWithHasOneAttachedDependentFalse < User + has_one_attached :avatar, dependent: false + end + + ActiveStorage::Blob.delete_all + blob_1 = create_blob filename: "funky.jpg" + blob_2 = create_blob filename: "town.jpg" + + user = UserWithHasOneAttachedDependentFalse.create! + user.avatar.attach blob_1 + + assert_equal [blob_2], ActiveStorage::Blob.unattached + user.destroy + assert_equal [blob_1, blob_2].map(&:id).sort, ActiveStorage::Blob.unattached.pluck(:id).sort + end + test "create after upload sets byte size and checksum" do data = "Hello world!" blob = create_blob data: data |