diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-12-15 15:50:56 -0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-12-15 15:53:53 -0200 |
commit | fc635b565393bd6b70be4af524934b3ea359e83c (patch) | |
tree | 97fd387e7ba127f42705e1b1d0d5ab45bbb70653 /railties | |
parent | 98087a604c988e2fd906cc7c63b30ea495679a5f (diff) | |
download | rails-fc635b565393bd6b70be4af524934b3ea359e83c.tar.gz rails-fc635b565393bd6b70be4af524934b3ea359e83c.tar.bz2 rails-fc635b565393bd6b70be4af524934b3ea359e83c.zip |
Accept a Pathname in Application#config_for
That would make possible to use it with action cable configuration.
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/application.rb | 6 | ||||
-rw-r--r-- | railties/test/application/configuration_test.rb | 15 |
2 files changed, 20 insertions, 1 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 77efe3248d..cac31e1eed 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -219,7 +219,11 @@ module Rails # config.middleware.use ExceptionNotifier, config_for(:exception_notification) # end def config_for(name, env: Rails.env) - yaml = Pathname.new("#{paths["config"].existent.first}/#{name}.yml") + if name.is_a?(Pathname) + yaml = name + else + yaml = Pathname.new("#{paths["config"].existent.first}/#{name}.yml") + end if yaml.exist? require "erb" diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 25e749ac14..264f254bfe 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1306,6 +1306,21 @@ module ApplicationTests assert_equal 'custom key', Rails.application.config.my_custom_config['key'] end + test "config_for use the Pathname object if it is provided" do + app_file 'config/custom.yml', <<-RUBY + development: + key: 'custom key' + RUBY + + add_to_config <<-RUBY + config.my_custom_config = config_for(Pathname.new(Rails.root.join("config/custom.yml"))) + RUBY + + app 'development' + + assert_equal 'custom key', Rails.application.config.my_custom_config['key'] + end + test "config_for raises an exception if the file does not exist" do add_to_config <<-RUBY config.my_custom_config = config_for('custom') |