diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2014-08-19 20:07:39 -0300 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2014-08-19 21:59:01 -0300 |
commit | 2f7ac9cdcc06f3c84eb3d905d16da9ca22ef2c66 (patch) | |
tree | 140a2e59ff3309bbe8f9093b6d014a06d5b0c4a2 /railties | |
parent | e2066818e82799ab7eee15d4d5248c4d16edf6ba (diff) | |
download | rails-2f7ac9cdcc06f3c84eb3d905d16da9ca22ef2c66.tar.gz rails-2f7ac9cdcc06f3c84eb3d905d16da9ca22ef2c66.tar.bz2 rails-2f7ac9cdcc06f3c84eb3d905d16da9ca22ef2c66.zip |
Fix setting simple values to the new config.x
Previously setting simple values to the config.x object resulted in the
following:
config.x.super_debugger = true
config.x.super_debugger #=> {}
Which was against the examples showed in the changelog/release notes.
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG.md | 3 | ||||
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 14 | ||||
-rw-r--r-- | railties/test/application/configuration/custom_test.rb | 17 |
3 files changed, 23 insertions, 11 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 9f3c3ccdf5..2a09ccf61a 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -22,14 +22,13 @@ # config/environments/production.rb config.x.payment_processing.schedule = :daily config.x.payment_processing.retries = 3 - config.x.super_debugger = true + config.x.super_debugger = true These configuration points are then available through the configuration object: Rails.configuration.x.payment_processing.schedule # => :daily Rails.configuration.x.payment_processing.retries # => 3 Rails.configuration.x.super_debugger # => true - Rails.configuration.x.super_debugger.not_set # => nil *DHH* diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 782bc4b0f1..9a6a4a52c7 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -155,15 +155,21 @@ module Rails def annotations SourceAnnotationExtractor::Annotation end - + private - class Custom + class Custom #:nodoc: def initialize @configurations = Hash.new end - + def method_missing(method, *args) - @configurations[method] ||= ActiveSupport::OrderedOptions.new + if method =~ /=$/ + @configurations[$`.to_sym] = args.first + else + @configurations.fetch(method) { + @configurations[method] = ActiveSupport::OrderedOptions.new + } + end end end end diff --git a/railties/test/application/configuration/custom_test.rb b/railties/test/application/configuration/custom_test.rb index 045537fc28..f8d22f6d97 100644 --- a/railties/test/application/configuration/custom_test.rb +++ b/railties/test/application/configuration/custom_test.rb @@ -3,13 +3,20 @@ require 'application/configuration/base_test' class ApplicationTests::ConfigurationTests::CustomTest < ApplicationTests::ConfigurationTests::BaseTest test 'access custom configuration point' do add_to_config <<-RUBY - config.x.resque.inline_jobs = :always - config.x.resque.timeout = 60 + config.x.payment_processing.schedule = :daily + config.x.payment_processing.retries = 3 + config.x.super_debugger = true + config.x.hyper_debugger = false + config.x.nil_debugger = nil RUBY require_environment - assert_equal :always, Rails.configuration.x.resque.inline_jobs - assert_equal 60, Rails.configuration.x.resque.timeout - assert_nil Rails.configuration.x.resque.nothing + x = Rails.configuration.x + assert_equal :daily, x.payment_processing.schedule + assert_equal 3, x.payment_processing.retries + assert_equal true, x.super_debugger + assert_equal false, x.hyper_debugger + assert_equal nil, x.nil_debugger + assert_nil x.i_do_not_exist.zomg end end |