diff options
author | Andrew White <andrew.white@unboxed.co> | 2018-03-26 14:36:39 +0100 |
---|---|---|
committer | Andrew White <andrew.white@unboxed.co> | 2018-04-06 20:07:52 +0100 |
commit | 9436c22e2aa9419f275186967a1b863bc3d01ecb (patch) | |
tree | 3a833e8e5f773d0f6668b44d15bceb644db932a3 /activestorage/test | |
parent | 03bd370c02a8fa83ab6dd01bdd99fe342c523b81 (diff) | |
download | rails-9436c22e2aa9419f275186967a1b863bc3d01ecb.tar.gz rails-9436c22e2aa9419f275186967a1b863bc3d01ecb.tar.bz2 rails-9436c22e2aa9419f275186967a1b863bc3d01ecb.zip |
Use a current model to provide the host for service urls
Trying to pass the current request down to the service so that it can
create full urls instead of paths makes the API messy so use a model
based on ActiveSupport::CurrentAttributes to provide the current host
to services that need it (primarily the disk service).
Diffstat (limited to 'activestorage/test')
-rw-r--r-- | activestorage/test/models/blob_test.rb | 2 | ||||
-rw-r--r-- | activestorage/test/service/disk_service_test.rb | 2 | ||||
-rw-r--r-- | activestorage/test/test_helper.rb | 8 |
3 files changed, 10 insertions, 2 deletions
diff --git a/activestorage/test/models/blob_test.rb b/activestorage/test/models/blob_test.rb index 202d0fb093..fead17d33a 100644 --- a/activestorage/test/models/blob_test.rb +++ b/activestorage/test/models/blob_test.rb @@ -140,6 +140,6 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase def expected_url_for(blob, disposition: :inline, filename: nil) filename ||= blob.filename query_string = { content_type: blob.content_type, disposition: "#{disposition}; #{filename.parameters}" }.to_param - "/rails/active_storage/disk/#{ActiveStorage.verifier.generate(blob.key, expires_in: 5.minutes, purpose: :blob_key)}/#{filename}?#{query_string}" + "https://example.com/rails/active_storage/disk/#{ActiveStorage.verifier.generate(blob.key, expires_in: 5.minutes, purpose: :blob_key)}/#{filename}?#{query_string}" end end diff --git a/activestorage/test/service/disk_service_test.rb b/activestorage/test/service/disk_service_test.rb index 4a6361b920..d7142de458 100644 --- a/activestorage/test/service/disk_service_test.rb +++ b/activestorage/test/service/disk_service_test.rb @@ -8,7 +8,7 @@ class ActiveStorage::Service::DiskServiceTest < ActiveSupport::TestCase include ActiveStorage::Service::SharedServiceTests test "url generation" do - assert_match(/rails\/active_storage\/disk\/.*\/avatar\.png\?content_type=image%2Fpng&disposition=inline/, + assert_match(/^https:\/\/example.com\/rails\/active_storage\/disk\/.*\/avatar\.png\?content_type=image%2Fpng&disposition=inline/, @service.url(FIXTURE_KEY, expires_in: 5.minutes, disposition: :inline, filename: ActiveStorage::Filename.new("avatar.png"), content_type: "image/png")) end end diff --git a/activestorage/test/test_helper.rb b/activestorage/test/test_helper.rb index 043890832d..028874f374 100644 --- a/activestorage/test/test_helper.rb +++ b/activestorage/test/test_helper.rb @@ -41,6 +41,14 @@ ActiveStorage.verifier = ActiveSupport::MessageVerifier.new("Testing") class ActiveSupport::TestCase self.file_fixture_path = File.expand_path("fixtures/files", __dir__) + setup do + ActiveStorage::Current.host = "https://example.com" + end + + teardown do + ActiveStorage::Current.reset + end + private def create_blob(data: "Hello world!", filename: "hello.txt", content_type: "text/plain") ActiveStorage::Blob.create_after_upload! io: StringIO.new(data), filename: filename, content_type: content_type |