Improve ActiveStorage service adapter error handling

This commit is contained in:
Joel Taylor 2018-08-06 18:17:49 -07:00
parent 53ec6cdf7a
commit 3082786be6
2 changed files with 9 additions and 1 deletions

@ -26,7 +26,9 @@ def config_for(name)
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

@ -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, {})