diff options
author | George Claghorn <george@basecamp.com> | 2018-07-19 20:43:33 -0400 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2018-07-19 20:43:33 -0400 |
commit | 2ae3a29508e2a5daab6dd3eea3e10e40df6fd945 (patch) | |
tree | fc08f206365a802df29e7d4f8115d84766ce96c1 | |
parent | 3f53296f1823417d9793c4616e9134414b7be0e8 (diff) | |
download | rails-2ae3a29508e2a5daab6dd3eea3e10e40df6fd945.tar.gz rails-2ae3a29508e2a5daab6dd3eea3e10e40df6fd945.tar.bz2 rails-2ae3a29508e2a5daab6dd3eea3e10e40df6fd945.zip |
Add a foreign-key constraint to the attachments table for blobs
-rw-r--r-- | activestorage/db/migrate/20170806125915_create_active_storage_tables.rb | 1 | ||||
-rw-r--r-- | activestorage/test/models/attached/many_test.rb | 2 | ||||
-rw-r--r-- | activestorage/test/models/attached/one_test.rb | 2 |
3 files changed, 3 insertions, 2 deletions
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") |