Skip to content

Commit 379232f

Browse files
crawlerzzak
authored andcommitted
Fix ActiveStorage tests for load_defaults 7.0
1 parent 40ca0a0 commit 379232f

File tree

5 files changed

+15
-29
lines changed

5 files changed

+15
-29
lines changed

activestorage/app/models/active_storage/variant_with_record.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# ActiveStorage::VariantRecord. This is only used if `ActiveStorage.track_variants` is enabled.
55
class ActiveStorage::VariantWithRecord
66
attr_reader :blob, :variation
7+
delegate :service, to: :blob
78

89
def initialize(blob, variation)
910
@blob, @variation = blob, ActiveStorage::Variation.wrap(variation)

activestorage/test/database/setup.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
require_relative "create_users_migration"
44
require_relative "create_groups_migration"
55

6-
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
6+
# Writing and reading roles are required for the "previewing on the writer DB" test
7+
ActiveRecord::Base.connects_to(database: { writing: :primary, reading: :replica })
78
ActiveRecord::Base.connection.migration_context.migrate
89
ActiveStorageCreateUsers.migrate(:up)
910
ActiveStorageCreateGroups.migrate(:up)
Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,8 @@
1-
# SQLite version 3.x
2-
# gem install sqlite3
3-
#
4-
# Ensure the SQLite 3 gem is defined in your Gemfile
5-
# gem 'sqlite3'
6-
#
7-
default: &default
8-
adapter: sqlite3
9-
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
10-
timeout: 5000
11-
12-
development:
13-
<<: *default
14-
database: db/development.sqlite3
15-
16-
# Warning: The database defined as "test" will be erased and
17-
# re-generated from your development database when you run "rake".
18-
# Do not set this db to the same as development or production.
191
test:
20-
<<: *default
21-
database: db/test.sqlite3
22-
23-
production:
24-
<<: *default
25-
database: db/production.sqlite3
2+
primary: &primary
3+
adapter: sqlite3
4+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
5+
timeout: 5000
6+
database: ':memory:'
7+
replica:
8+
<<: *primary

activestorage/test/models/blob_test.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
class ActiveStorage::BlobTest < ActiveSupport::TestCase
88
include ActiveSupport::Testing::MethodCallAssertions
9+
include ActiveJob::TestHelper
910

1011
test "unattached scope" do
1112
[ create_blob(filename: "funky.jpg"), create_blob(filename: "town.jpg") ].tap do |blobs|
@@ -229,12 +230,12 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase
229230
assert_not ActiveStorage::Blob.service.exist?(blob.key)
230231
end
231232

232-
test "purge deletes variants from external service" do
233+
test "purge deletes variants from external service with the purge_later" do
233234
blob = create_file_blob
234235
variant = blob.variant(resize: "100>").processed
235236

236237
blob.purge
237-
assert_not ActiveStorage::Blob.service.exist?(variant.key)
238+
assert_enqueued_with(job: ActiveStorage::PurgeJob, args: [variant.image.blob])
238239
end
239240

240241
test "purge does nothing when attachments exist" do

activestorage/test/models/preview_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class ActiveStorage::PreviewTest < ActiveSupport::TestCase
5454
test "previewing on the writer DB" do
5555
blob = create_file_blob(filename: "report.pdf", content_type: "application/pdf")
5656

57-
# Simulate a selector middleware switching to a read-only replica.
58-
ActiveRecord::Base.connection_handler.while_preventing_writes do
57+
# prevent_writes option is required because there is no automatic write protection anymore
58+
ActiveRecord::Base.connected_to(role: ActiveRecord.reading_role, prevent_writes: true) do
5959
blob.preview(resize: "640x280").processed
6060
end
6161

0 commit comments

Comments
 (0)