From 2ae3a29508e2a5daab6dd3eea3e10e40df6fd945 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Thu, 19 Jul 2018 20:43:33 -0400 Subject: Add a foreign-key constraint to the attachments table for blobs --- activestorage/db/migrate/20170806125915_create_active_storage_tables.rb | 1 + activestorage/test/models/attached/many_test.rb | 2 +- activestorage/test/models/attached/one_test.rb | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'activestorage') diff --git a/activestorage/db/migrate/20170806125915_create_active_storage_tables.rb b/activestorage/db/migrate/20170806125915_create_active_storage_tables.rb index 9e31e3966a..cfaf01cd5e 100644 --- a/activestorage/db/migrate/20170806125915_create_active_storage_tables.rb +++ b/activestorage/db/migrate/20170806125915_create_active_storage_tables.rb @@ -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 diff --git a/activestorage/test/models/attached/many_test.rb b/activestorage/test/models/attached/many_test.rb index 82be88af08..334254d099 100644 --- a/activestorage/test/models/attached/many_test.rb +++ b/activestorage/test/models/attached/many_test.rb @@ -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") diff --git a/activestorage/test/models/attached/one_test.rb b/activestorage/test/models/attached/one_test.rb index 01caaf0b55..3333fd9323 100644 --- a/activestorage/test/models/attached/one_test.rb +++ b/activestorage/test/models/attached/one_test.rb @@ -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") -- cgit v1.2.3