Skip to content

Commit b6c90d4

Browse files
committed
fix specs due to rails 6.1 active storage breaking changes
1 parent d173c79 commit b6c90d4

File tree

4 files changed

+51
-7
lines changed

4 files changed

+51
-7
lines changed

.github/workflows/dockerpush.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@ jobs:
99
- uses: actions/checkout@v2
1010
- name: Run tests
1111
run: |
12-
docker-compose run --rm test_6_1_ruby_3_0 bundle exec rake db:schema:load
12+
docker-compose run --rm test_6_1_ruby_3_0 bundle exec rake db:migrate
1313
docker-compose run --rm test_6_1_ruby_3_0 bundle exec rspec spec/test
1414
test_6_1_ruby_2_7:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v2
1818
- name: Run tests
1919
run: |
20-
docker-compose run --rm test_6_1_ruby_2_7 bundle exec rake db:schema:load
20+
docker-compose run --rm test_6_1_ruby_2_7 bundle exec rake db:migrate
2121
docker-compose run --rm test_6_1_ruby_2_7 bundle exec rspec spec/test
2222
test_6_0_ruby_2_6:
2323
runs-on: ubuntu-latest
2424
steps:
2525
- uses: actions/checkout@v2
2626
- name: Run tests
2727
run: |
28-
docker-compose run --rm test_6_0_ruby_2_6 bundle exec rake db:schema:load
28+
docker-compose run --rm test_6_0_ruby_2_6 bundle exec rake db:migrate
2929
docker-compose run --rm test_6_0_ruby_2_6 bundle exec rspec spec/test
3030
test_5_2_ruby_2_6:
3131
runs-on: ubuntu-latest
3232
steps:
3333
- uses: actions/checkout@v2
3434
- name: Run tests
3535
run: |
36-
docker-compose run --rm test_5_2_ruby_2_6 bundle exec rake db:schema:load
36+
docker-compose run --rm test_5_2_ruby_2_6 bundle exec rake db:migrate
3737
docker-compose run --rm test_5_2_ruby_2_6 bundle exec rspec spec/test
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This migration comes from active_storage (originally 20190112182829)
2+
class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0]
3+
def up
4+
if Rails::VERSION::MAJOR >= 6 && Rails::VERSION::MINOR >= 1
5+
unless column_exists?(:active_storage_blobs, :service_name)
6+
add_column :active_storage_blobs, :service_name, :string
7+
8+
if configured_service = ActiveStorage::Blob.service.name
9+
ActiveStorage::Blob.unscoped.update_all(service_name: configured_service)
10+
end
11+
12+
change_column :active_storage_blobs, :service_name, :string, null: false
13+
end
14+
end
15+
end
16+
17+
def down
18+
if Rails::VERSION::MAJOR >= 6 && Rails::VERSION::MINOR >= 1
19+
remove_column :active_storage_blobs, :service_name
20+
end
21+
end
22+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This migration comes from active_storage (originally 20191206030411)
2+
class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0]
3+
def change
4+
if Rails::VERSION::MAJOR >= 6 && Rails::VERSION::MINOR >= 1
5+
create_table :active_storage_variant_records do |t|
6+
t.belongs_to :blob, null: false, index: false
7+
t.string :variation_digest, null: false
8+
9+
t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true
10+
t.foreign_key :active_storage_blobs, column: :blob_id
11+
end
12+
end
13+
end
14+
end

spec/dummy/db/schema.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
# of editing this file, please use the migrations feature of Active Record to
33
# incrementally modify your database, and then regenerate this schema definition.
44
#
5-
# This file is the source Rails uses to define your schema when running `rails
6-
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
5+
# This file is the source Rails uses to define your schema when running `bin/rails
6+
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
77
# be faster and is potentially less error prone than running all of your
88
# migrations from scratch. Old migrations may fail to apply correctly if those
99
# migrations use external dependencies or application code.
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2020_12_22_161321) do
13+
ActiveRecord::Schema.define(version: 2021_02_04_135044) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -33,9 +33,16 @@
3333
t.bigint "byte_size", null: false
3434
t.string "checksum", null: false
3535
t.datetime "created_at", null: false
36+
t.string "service_name", null: false
3637
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
3738
end
3839

40+
create_table "active_storage_variant_records", force: :cascade do |t|
41+
t.bigint "blob_id", null: false
42+
t.string "variation_digest", null: false
43+
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
44+
end
45+
3946
create_table "dummy_child_models", force: :cascade do |t|
4047
t.string "title"
4148
t.text "description"
@@ -70,5 +77,6 @@
7077
end
7178

7279
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
80+
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
7381
add_foreign_key "dummy_child_models", "dummy_models"
7482
end

0 commit comments

Comments
 (0)