Add a foreign-key constraint to the attachments table for blobs

This commit is contained in:
George Claghorn 2018-07-19 20:43:33 -04:00
parent 3f53296f18
commit 2ae3a29508
3 changed files with 3 additions and 2 deletions

View File

@ -20,6 +20,7 @@ class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
t.datetime :created_at, null: false
t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end
end

View File

@ -10,7 +10,7 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase
@user = User.create!(name: "Josh")
end
teardown { ActiveStorage::Blob.all.each(&:purge) }
teardown { ActiveStorage::Blob.all.each(&:delete) }
test "attaching existing blobs to an existing record" do
@user.highlights.attach create_blob(filename: "funky.jpg"), create_blob(filename: "town.jpg")

View File

@ -10,7 +10,7 @@ class ActiveStorage::OneAttachedTest < ActiveSupport::TestCase
@user = User.create!(name: "Josh")
end
teardown { ActiveStorage::Blob.all.each(&:purge) }
teardown { ActiveStorage::Blob.all.each(&:delete) }
test "attaching an existing blob to an existing record" do
@user.avatar.attach create_blob(filename: "funky.jpg")