aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/test
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2017-08-29 15:34:50 -0400
committerGeorge Claghorn <george@basecamp.com>2017-08-29 15:34:50 -0400
commit656ee8b2dd1b06541f03ea19302d3529085f5139 (patch)
tree969368cc54572a6dc30579a300beaa53f8d938c7 /activestorage/test
parent96742b5e0f04a2ed795032df04736cb1f16cc3a4 (diff)
downloadrails-656ee8b2dd1b06541f03ea19302d3529085f5139.tar.gz
rails-656ee8b2dd1b06541f03ea19302d3529085f5139.tar.bz2
rails-656ee8b2dd1b06541f03ea19302d3529085f5139.zip
Fix replacing a singular attachment
Diffstat (limited to 'activestorage/test')
-rw-r--r--activestorage/test/models/attachments_test.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/activestorage/test/models/attachments_test.rb b/activestorage/test/models/attachments_test.rb
index 7cfd8683db..ac346c0087 100644
--- a/activestorage/test/models/attachments_test.rb
+++ b/activestorage/test/models/attachments_test.rb
@@ -31,6 +31,31 @@ class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase
assert_equal "racecar.jpg", @user.avatar.filename.to_s
end
+ test "replace attached blob" do
+ @user.avatar.attach create_blob(filename: "funky.jpg")
+
+ perform_enqueued_jobs do
+ assert_no_difference -> { ActiveStorage::Blob.count } do
+ @user.avatar.attach create_blob(filename: "town.jpg")
+ end
+ end
+
+ assert_equal "town.jpg", @user.avatar.filename.to_s
+ end
+
+ test "replace attached blob unsuccessfully" do
+ @user.avatar.attach create_blob(filename: "funky.jpg")
+
+ perform_enqueued_jobs do
+ assert_raises do
+ @user.avatar.attach nil
+ end
+ end
+
+ assert_equal "funky.jpg", @user.reload.avatar.filename.to_s
+ assert ActiveStorage::Blob.service.exist?(@user.avatar.key)
+ end
+
test "access underlying associations of new blob" do
@user.avatar.attach create_blob(filename: "funky.jpg")
assert_equal @user, @user.avatar_attachment.record