aboutsummaryrefslogtreecommitdiffstats
path: root/test/service
diff options
context:
space:
mode:
authorJeremy Daer <jeremydaer@gmail.com>2017-07-08 16:55:50 -0700
committerJeremy Daer <jeremydaer@gmail.com>2017-07-08 17:27:31 -0700
commite5503399c0bb992ec1fd47b4bc371b8aef679e37 (patch)
tree345c3428df076adee7b9478ad4ae105959b4e47e /test/service
parent6116313da4996ef99dcb45e2b9ac90ef073caabc (diff)
downloadrails-e5503399c0bb992ec1fd47b4bc371b8aef679e37.tar.gz
rails-e5503399c0bb992ec1fd47b4bc371b8aef679e37.tar.bz2
rails-e5503399c0bb992ec1fd47b4bc371b8aef679e37.zip
Configure services that reference other services
* Move service configuration from the Engine to Service * Delegate configuration mechanics to internal Service::Configurator * Delegate service building to the concrete Service classes, allowing them to configure composed services. * Implement for the Mirror service.
Diffstat (limited to 'test/service')
-rw-r--r--test/service/disk_service_test.rb2
-rw-r--r--test/service/gcs_service_test.rb2
-rw-r--r--test/service/mirror_service_test.rb27
-rw-r--r--test/service/s3_service_test.rb2
4 files changed, 19 insertions, 14 deletions
diff --git a/test/service/disk_service_test.rb b/test/service/disk_service_test.rb
index 5dd7cff303..bd2e68277e 100644
--- a/test/service/disk_service_test.rb
+++ b/test/service/disk_service_test.rb
@@ -2,7 +2,7 @@ require "tmpdir"
require "service/shared_service_tests"
class ActiveStorage::Service::DiskServiceTest < ActiveSupport::TestCase
- SERVICE = ActiveStorage::Service.configure(:Disk, root: File.join(Dir.tmpdir, "active_storage"))
+ SERVICE = ActiveStorage::Service.configure(:test, test: { service: "Disk", root: File.join(Dir.tmpdir, "active_storage") })
include ActiveStorage::Service::SharedServiceTests
end
diff --git a/test/service/gcs_service_test.rb b/test/service/gcs_service_test.rb
index 42f9cd3061..7d4700498b 100644
--- a/test/service/gcs_service_test.rb
+++ b/test/service/gcs_service_test.rb
@@ -2,7 +2,7 @@ require "service/shared_service_tests"
if SERVICE_CONFIGURATIONS[:gcs]
class ActiveStorage::Service::GCSServiceTest < ActiveSupport::TestCase
- SERVICE = ActiveStorage::Service.configure(:GCS, SERVICE_CONFIGURATIONS[:gcs])
+ SERVICE = ActiveStorage::Service.configure(:gcs, SERVICE_CONFIGURATIONS)
include ActiveStorage::Service::SharedServiceTests
diff --git a/test/service/mirror_service_test.rb b/test/service/mirror_service_test.rb
index 10af41c0a8..6fee3cadd2 100644
--- a/test/service/mirror_service_test.rb
+++ b/test/service/mirror_service_test.rb
@@ -2,12 +2,17 @@ require "tmpdir"
require "service/shared_service_tests"
class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase
- PRIMARY_DISK_SERVICE = ActiveStorage::Service.configure(:Disk, root: File.join(Dir.tmpdir, "active_storage"))
- MIRROR_SERVICES = (1..3).map do |i|
- ActiveStorage::Service.configure(:Disk, root: File.join(Dir.tmpdir, "active_storage_mirror_#{i}"))
- end
+ mirror_config = (1..3).map do |i|
+ [ "mirror_#{i}",
+ service: "Disk",
+ root: File.join(Dir.tmpdir, "active_storage_mirror_#{i}") ]
+ end.to_h
+
+ config = mirror_config.merge \
+ mirror: { service: "Mirror", primary: 'primary', mirrors: mirror_config.keys },
+ primary: { service: "Disk", root: File.join(Dir.tmpdir, "active_storage") }
- SERVICE = ActiveStorage::Service.configure :Mirror, primary: PRIMARY_DISK_SERVICE, mirrors: MIRROR_SERVICES
+ SERVICE = ActiveStorage::Service.configure :mirror, config
include ActiveStorage::Service::SharedServiceTests
@@ -16,8 +21,8 @@ class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase
data = "Something else entirely!"
key = upload(data, to: @service)
- assert_equal data, PRIMARY_DISK_SERVICE.download(key)
- MIRROR_SERVICES.each do |mirror|
+ assert_equal data, SERVICE.primary.download(key)
+ SERVICE.mirrors.each do |mirror|
assert_equal data, mirror.download(key)
end
ensure
@@ -27,22 +32,22 @@ class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase
test "downloading from primary service" do
data = "Something else entirely!"
- key = upload(data, to: PRIMARY_DISK_SERVICE)
+ key = upload(data, to: SERVICE.primary)
assert_equal data, @service.download(key)
end
test "deleting from all services" do
@service.delete FIXTURE_KEY
- assert_not PRIMARY_DISK_SERVICE.exist?(FIXTURE_KEY)
- MIRROR_SERVICES.each do |mirror|
+ assert_not SERVICE.primary.exist?(FIXTURE_KEY)
+ SERVICE.mirrors.each do |mirror|
assert_not mirror.exist?(FIXTURE_KEY)
end
end
test "URL generation in primary service" do
travel_to Time.now do
- assert_equal PRIMARY_DISK_SERVICE.url(FIXTURE_KEY, expires_in: 2.minutes, disposition: :inline, filename: "test.txt"),
+ assert_equal SERVICE.primary.url(FIXTURE_KEY, expires_in: 2.minutes, disposition: :inline, filename: "test.txt"),
@service.url(FIXTURE_KEY, expires_in: 2.minutes, disposition: :inline, filename: "test.txt")
end
end
diff --git a/test/service/s3_service_test.rb b/test/service/s3_service_test.rb
index 604dfd6c60..e8cc4cb5f4 100644
--- a/test/service/s3_service_test.rb
+++ b/test/service/s3_service_test.rb
@@ -2,7 +2,7 @@ require "service/shared_service_tests"
if SERVICE_CONFIGURATIONS[:s3]
class ActiveStorage::Service::S3ServiceTest < ActiveSupport::TestCase
- SERVICE = ActiveStorage::Service.configure(:S3, SERVICE_CONFIGURATIONS[:s3])
+ SERVICE = ActiveStorage::Service.configure(:s3, SERVICE_CONFIGURATIONS)
include ActiveStorage::Service::SharedServiceTests
end