Provide a sensible default host

This commit is contained in:
George Claghorn 2018-01-16 20:32:02 -05:00
parent 4c0cb1c2c9
commit 6fb3ac1536
8 changed files with 15 additions and 13 deletions

View File

@ -11,7 +11,7 @@ module ActiveStorage
class Service::DiskService < Service
attr_reader :root, :host
def initialize(root:, host:)
def initialize(root:, host: "http://localhost:3000")
@root, @host = root, host
end

View File

@ -1,4 +1,3 @@
local:
service: Disk
root: <%= Rails.root.join("storage") %>
host: http://localhost:3000

View File

@ -4,7 +4,7 @@ require "service/shared_service_tests"
class ActiveStorage::Service::ConfiguratorTest < ActiveSupport::TestCase
test "builds correct service instance based on service name" do
service = ActiveStorage::Service::Configurator.build(:foo, foo: { service: "Disk", root: "path", host: "http://localhost:3000" })
service = ActiveStorage::Service::Configurator.build(:foo, foo: { service: "Disk", root: "path" })
assert_instance_of ActiveStorage::Service::DiskService, service
assert_equal "path", service.root

View File

@ -3,7 +3,7 @@
require "service/shared_service_tests"
class ActiveStorage::Service::DiskServiceTest < ActiveSupport::TestCase
SERVICE = ActiveStorage::Service::DiskService.new(root: File.join(Dir.tmpdir, "active_storage"), host: "http://localhost:3000")
SERVICE = ActiveStorage::Service::DiskService.new(root: File.join(Dir.tmpdir, "active_storage"))
include ActiveStorage::Service::SharedServiceTests

View File

@ -6,13 +6,12 @@ class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase
mirror_config = (1..3).map do |i|
[ "mirror_#{i}",
service: "Disk",
root: Dir.mktmpdir("active_storage_tests_mirror_#{i}"),
host: "http://localhost:3000" ]
root: Dir.mktmpdir("active_storage_tests_mirror_#{i}") ]
end.to_h
config = mirror_config.merge \
mirror: { service: "Mirror", primary: "primary", mirrors: mirror_config.keys },
primary: { service: "Disk", root: Dir.mktmpdir("active_storage_tests_primary"), host: "http://localhost:3000" }
primary: { service: "Disk", root: Dir.mktmpdir("active_storage_tests_primary") }
SERVICE = ActiveStorage::Service.configure :mirror, config

View File

@ -34,7 +34,7 @@ rescue Errno::ENOENT
end
require "tmpdir"
ActiveStorage::Blob.service = ActiveStorage::Service::DiskService.new(root: Dir.mktmpdir("active_storage_tests"), host: "http://localhost:3000")
ActiveStorage::Blob.service = ActiveStorage::Service::DiskService.new(root: Dir.mktmpdir("active_storage_tests"))
ActiveStorage.logger = ActiveSupport::Logger.new(nil)
ActiveStorage.verifier = ActiveSupport::MessageVerifier.new("Testing")

View File

@ -49,12 +49,10 @@ below declares three services named `local`, `test`, and `amazon`:
local:
service: Disk
root: <%= Rails.root.join("storage") %>
host: http://localhost:3000
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
host: http://localhost:3000
amazon:
service: S3
@ -93,7 +91,15 @@ Declare a Disk service in `config/storage.yml`:
local:
service: Disk
root: <%= Rails.root.join("storage") %>
host: http://localhost:3000
```
Optionally specify a host for generating URLs (the default is `http://localhost:3000`):
```yaml
local:
service: Disk
root: <%= Rails.root.join("storage") %>
host: http://myapp.test
```
### Amazon S3 Service

View File

@ -1,12 +1,10 @@
test:
service: Disk
root: <%%= Rails.root.join("tmp/storage") %>
host: http://localhost:3000
local:
service: Disk
root: <%%= Rails.root.join("storage") %>
host: http://localhost:3000
# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
# amazon: