Skip to content

Commit e45cb30

Browse files
authored
Merge pull request rails#42163 from ghiculescu/as-diskservice-root-accessor
Add a public writer for `ActiveStorage::Service::DiskService#root`
2 parents 3cf6378 + ea43daa commit e45cb30

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

activestorage/lib/active_storage/service/disk_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module ActiveStorage
99
# Wraps a local disk path as an Active Storage service. See ActiveStorage::Service for the generic API
1010
# documentation that applies to all services.
1111
class Service::DiskService < Service
12-
attr_reader :root
12+
attr_accessor :root
1313

1414
def initialize(root:, public: false, **options)
1515
@root = root

activestorage/test/service/disk_service_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,17 @@ class ActiveStorage::Service::DiskServiceTest < ActiveSupport::TestCase
2626
test "headers_for_direct_upload generation" do
2727
assert_equal({ "Content-Type" => "application/json" }, @service.headers_for_direct_upload(@key, content_type: "application/json"))
2828
end
29+
30+
test "root" do
31+
assert_equal tmp_config.dig(:tmp, :root), @service.root
32+
end
33+
34+
test "can change root" do
35+
tmp_path_2 = File.join(Dir.tmpdir, "active_storage_2")
36+
@service.root = tmp_path_2
37+
38+
assert_equal tmp_path_2, @service.root
39+
ensure
40+
@service.root = tmp_config.dig(:tmp, :root)
41+
end
2942
end

0 commit comments

Comments
 (0)