diff options
author | George Claghorn <george.claghorn@gmail.com> | 2018-08-06 22:01:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-06 22:01:21 -0400 |
commit | 1ed33a2a64f09182287c4bb283e574aad959126f (patch) | |
tree | 955033c82128a98024294e002dc90f4d11491728 /activestorage | |
parent | 53ec6cdf7ade942b2589bf8295246f7bc98c850a (diff) | |
parent | 3082786be616173f28488e89b7d8b9bfc5cd0f97 (diff) | |
download | rails-1ed33a2a64f09182287c4bb283e574aad959126f.tar.gz rails-1ed33a2a64f09182287c4bb283e574aad959126f.tar.bz2 rails-1ed33a2a64f09182287c4bb283e574aad959126f.zip |
Merge pull request #33540 from joeltaylor/improve_service_adapter_error_handling
Improve ActiveStorage service adapter error handling
Diffstat (limited to 'activestorage')
-rw-r--r-- | activestorage/lib/active_storage/service/configurator.rb | 4 | ||||
-rw-r--r-- | activestorage/test/service/configurator_test.rb | 6 |
2 files changed, 9 insertions, 1 deletions
diff --git a/activestorage/lib/active_storage/service/configurator.rb b/activestorage/lib/active_storage/service/configurator.rb index 39951fd026..32fa9105c6 100644 --- a/activestorage/lib/active_storage/service/configurator.rb +++ b/activestorage/lib/active_storage/service/configurator.rb @@ -26,7 +26,9 @@ module ActiveStorage def resolve(class_name) require "active_storage/service/#{class_name.to_s.underscore}_service" - ActiveStorage::Service.const_get(:"#{class_name}Service") + ActiveStorage::Service.const_get(:"#{class_name.classify}Service") + rescue LoadError + raise "Missing service adapter for #{class_name.inspect}" end end end diff --git a/activestorage/test/service/configurator_test.rb b/activestorage/test/service/configurator_test.rb index 1c9c5c3aa0..3ef9cf9fb6 100644 --- a/activestorage/test/service/configurator_test.rb +++ b/activestorage/test/service/configurator_test.rb @@ -9,6 +9,12 @@ class ActiveStorage::Service::ConfiguratorTest < ActiveSupport::TestCase assert_equal "path", service.root end + test "builds correct service instance based on lowercase service name" do + service = ActiveStorage::Service::Configurator.build(:foo, foo: { service: "disk", root: "path" }) + assert_instance_of ActiveStorage::Service::DiskService, service + assert_equal "path", service.root + end + test "raises error when passing non-existent service name" do assert_raise RuntimeError do ActiveStorage::Service::Configurator.build(:bigfoot, {}) |