Skip to content

Commit

Permalink
Install active_storage migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
vsppedro committed Nov 2, 2020
1 parent 4ecc9d2 commit a1154b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 29 deletions.
13 changes: 13 additions & 0 deletions spec/support/unit/rails_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
require_relative '../tests/command_runner'
require_relative '../tests/database'
require_relative '../tests/filesystem'
require_relative 'helpers/active_record_versions'
require_relative 'helpers/rails_versions'

require 'yaml'

module UnitTests
class RailsApplication
include UnitTests::ActiveRecordVersions

def initialize
@fs = Tests::Filesystem.new
@bundle = Tests::Bundle.new
Expand All @@ -26,6 +29,10 @@ def create
def load
load_environment

if active_record_supports_active_storage?
add_active_storage_migration
end

if rails_version > 5 && bundle.includes?('actiontext')
add_action_text_migration
end
Expand Down Expand Up @@ -170,6 +177,12 @@ class DevelopmentRecord < ActiveRecord::Base
TEXT
end

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

def add_action_text_migration
fs.within_project do
run_command! 'bundle exec rake action_text:install:migrations'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,6 @@

describe Shoulda::Matchers::ActiveRecord::HaveAttachedMatcher, type: :model do
if active_record_supports_active_storage?
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 a1154b2

Please sign in to comment.