File tree Expand file tree Collapse file tree 5 files changed +15
-29
lines changed
app/models/active_storage Expand file tree Collapse file tree 5 files changed +15
-29
lines changed Original file line number Diff line number Diff line change 4
4
# ActiveStorage::VariantRecord. This is only used if `ActiveStorage.track_variants` is enabled.
5
5
class ActiveStorage ::VariantWithRecord
6
6
attr_reader :blob , :variation
7
+ delegate :service , to : :blob
7
8
8
9
def initialize ( blob , variation )
9
10
@blob , @variation = blob , ActiveStorage ::Variation . wrap ( variation )
Original file line number Diff line number Diff line change 3
3
require_relative "create_users_migration"
4
4
require_relative "create_groups_migration"
5
5
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 } )
7
8
ActiveRecord ::Base . connection . migration_context . migrate
8
9
ActiveStorageCreateUsers . migrate ( :up )
9
10
ActiveStorageCreateGroups . migrate ( :up )
Original file line number Diff line number Diff line change 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.
19
1
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
Original file line number Diff line number Diff line change 6
6
7
7
class ActiveStorage ::BlobTest < ActiveSupport ::TestCase
8
8
include ActiveSupport ::Testing ::MethodCallAssertions
9
+ include ActiveJob ::TestHelper
9
10
10
11
test "unattached scope" do
11
12
[ create_blob ( filename : "funky.jpg" ) , create_blob ( filename : "town.jpg" ) ] . tap do |blobs |
@@ -229,12 +230,12 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase
229
230
assert_not ActiveStorage ::Blob . service . exist? ( blob . key )
230
231
end
231
232
232
- test "purge deletes variants from external service" do
233
+ test "purge deletes variants from external service with the purge_later " do
233
234
blob = create_file_blob
234
235
variant = blob . variant ( resize : "100>" ) . processed
235
236
236
237
blob . purge
237
- assert_not ActiveStorage ::Blob . service . exist? ( variant . key )
238
+ assert_enqueued_with ( job : ActiveStorage ::PurgeJob , args : [ variant . image . blob ] )
238
239
end
239
240
240
241
test "purge does nothing when attachments exist" do
Original file line number Diff line number Diff line change @@ -54,8 +54,8 @@ class ActiveStorage::PreviewTest < ActiveSupport::TestCase
54
54
test "previewing on the writer DB" do
55
55
blob = create_file_blob ( filename : "report.pdf" , content_type : "application/pdf" )
56
56
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
59
59
blob . preview ( resize : "640x280" ) . processed
60
60
end
61
61
You can’t perform that action at this time.
0 commit comments