2017-08-12 08:32:15 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-06 06:22:44 -04:00
|
|
|
require "service/shared_service_tests"
|
|
|
|
|
|
|
|
class ActiveStorage::Service::DiskServiceTest < ActiveSupport::TestCase
|
2018-01-16 20:32:02 -05:00
|
|
|
SERVICE = ActiveStorage::Service::DiskService.new(root: File.join(Dir.tmpdir, "active_storage"))
|
2017-07-06 06:22:44 -04:00
|
|
|
|
|
|
|
include ActiveStorage::Service::SharedServiceTests
|
2017-07-09 11:04:37 -04:00
|
|
|
|
2019-04-01 08:29:37 -04:00
|
|
|
test "URL generation" do
|
2019-07-09 15:54:35 -04:00
|
|
|
original_url_options = Rails.application.routes.default_url_options.dup
|
|
|
|
Rails.application.routes.default_url_options.merge!(protocol: "http", host: "test.example.com", port: 3001)
|
|
|
|
begin
|
|
|
|
assert_match(/^https:\/\/example.com\/rails\/active_storage\/disk\/.*\/avatar\.png\?content_type=image%2Fpng&disposition=inline/,
|
|
|
|
@service.url(@key, expires_in: 5.minutes, disposition: :inline, filename: ActiveStorage::Filename.new("avatar.png"), content_type: "image/png"))
|
|
|
|
ensure
|
|
|
|
Rails.application.routes.default_url_options = original_url_options
|
|
|
|
end
|
2017-07-09 11:04:37 -04:00
|
|
|
end
|
2018-02-28 18:59:00 -05:00
|
|
|
|
|
|
|
test "headers_for_direct_upload generation" do
|
2018-06-25 18:49:26 -04:00
|
|
|
assert_equal({ "Content-Type" => "application/json" }, @service.headers_for_direct_upload(@key, content_type: "application/json"))
|
2018-02-28 18:59:00 -05:00
|
|
|
end
|
2017-07-06 06:22:44 -04:00
|
|
|
end
|