Skip to content

Commit

Permalink
Install ActiveStorage migrations (#1458)
Browse files Browse the repository at this point in the history
  • Loading branch information
vsppedro committed Sep 26, 2022
1 parent 958a9fe commit 035822f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
7 changes: 7 additions & 0 deletions spec/support/unit/rails_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def create
def load
load_environment

add_active_storage_migration
add_action_text_migration if rails_version >= 6.0

run_migrations
Expand Down Expand Up @@ -150,6 +151,12 @@ def add_action_text_migration
end
end

def add_active_storage_migration
fs.within_project do
run_command! 'bundle exec rake active_storage:install:migrations'
end
end

def add_initializer_for_time_zone_aware_types
path = 'config/initializers/configure_time_zone_aware_types.rb'
fs.write(path, <<-TEXT)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
require 'unit_spec_helper'

describe Shoulda::Matchers::ActiveRecord::HaveAttachedMatcher, type: :model do
before do
create_table :active_storage_blobs do |t|
t.string :key, null: false
t.string :filename, null: false
t.string :content_type
t.text :metadata
t.bigint :byte_size, null: false
t.string :checksum, null: false
t.datetime :created_at, null: false

t.index [:key], unique: true
end

create_table :active_storage_attachments do |t|
t.string :name, null: false
t.references :record, null: false, polymorphic: true, index: false
t.references :blob, null: false

t.datetime :created_at, null: false

t.index [:record_type, :record_id, :name, :blob_id],
name: 'index_active_storage_attachments_uniqueness', unique: true

# The original rails migration has a foreign key.
# Since this messes up the clearing of the database, it's removed here.
# t.foreign_key :active_storage_blobs, column: :blob_id
end
end

describe 'have_one_attached' do
describe '#description' do
it 'returns the message with the name of the association' do
Expand Down

0 comments on commit 035822f

Please sign in to comment.