diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-02-12 20:55:23 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-12 20:55:23 -0500 |
commit | b9ed1fa4442633e1328dcde5a37a472b22003a6f (patch) | |
tree | 25c63154b5c693c516dba05e6369609a1072b09e /activestorage/test | |
parent | 2c4e9c678bcfae23fcee28c105577403ebb2aa00 (diff) | |
parent | 0c463f50eaf939042ea9561eed85146612daab5e (diff) | |
download | rails-b9ed1fa4442633e1328dcde5a37a472b22003a6f.tar.gz rails-b9ed1fa4442633e1328dcde5a37a472b22003a6f.tar.bz2 rails-b9ed1fa4442633e1328dcde5a37a472b22003a6f.zip |
Merge pull request #31970 from fatkodima/active_storage-unattached-scope
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 |