aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/test/models/blob_test.rb
diff options
context:
space:
mode:
authorGeorge Claghorn <george.claghorn@gmail.com>2018-07-07 23:25:33 -0400
committerGitHub <noreply@github.com>2018-07-07 23:25:33 -0400
commite8682c5bf051517b0b265e446aa1a7eccfd47bf7 (patch)
treecc04c8a28113bc0fa3748fdc6035d487e3e16af7 /activestorage/test/models/blob_test.rb
parent0b534cd1c814a4db2d0aa283981f1d55e5e62d25 (diff)
downloadrails-e8682c5bf051517b0b265e446aa1a7eccfd47bf7.tar.gz
rails-e8682c5bf051517b0b265e446aa1a7eccfd47bf7.tar.bz2
rails-e8682c5bf051517b0b265e446aa1a7eccfd47bf7.zip
Store newly-uploaded files on save rather than assignment
Diffstat (limited to 'activestorage/test/models/blob_test.rb')
-rw-r--r--activestorage/test/models/blob_test.rb22
1 files changed, 8 insertions, 14 deletions
diff --git a/activestorage/test/models/blob_test.rb b/activestorage/test/models/blob_test.rb
index 40b30acd3e..a0e207642a 100644
--- a/activestorage/test/models/blob_test.rb
+++ b/activestorage/test/models/blob_test.rb
@@ -7,21 +7,15 @@ 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
+ test "unattached scope" do
+ [ create_blob(filename: "funky.jpg"), create_blob(filename: "town.jpg") ].tap do |blobs|
+ User.create! name: "DHH", avatar: blobs.first
+ assert_includes ActiveStorage::Blob.unattached, blobs.second
+ assert_not_includes ActiveStorage::Blob.unattached, blobs.first
+
+ User.create! name: "Jason", avatar: blobs.second
+ assert_not_includes ActiveStorage::Blob.unattached, blobs.second
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