aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2018-11-30 11:42:44 -0500
committerGitHub <noreply@github.com>2018-11-30 11:42:44 -0500
commit25c076117ce9bb3efcf686c110187206e428b96a (patch)
tree1d4b3330e5c89dff6461542037f211dd56ff544c /railties/test
parentb37f06c814c75fa29f67e237301256d2ec4ec015 (diff)
parent264152af2b0c210b4c2e4865e337eaa07836c948 (diff)
downloadrails-25c076117ce9bb3efcf686c110187206e428b96a.tar.gz
rails-25c076117ce9bb3efcf686c110187206e428b96a.tar.bz2
rails-25c076117ce9bb3efcf686c110187206e428b96a.zip
Merge pull request #33882 from mberlanda/mberlanda/as-inheritable-options-intialization
[Realties] config_for as ActiveSupport::OrderedOptions
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/application/configuration_test.rb80
1 files changed, 54 insertions, 26 deletions
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index b8a0434432..3635de7162 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -1736,21 +1736,6 @@ module ApplicationTests
assert_equal true, Rails.application.config.action_mailer.show_previews
end
- test "config_for loads custom configuration from yaml files" do
- app_file "config/custom.yml", <<-RUBY
- development:
- foo: 'bar'
- RUBY
-
- add_to_config <<-RUBY
- config.my_custom_config = config_for('custom')
- RUBY
-
- app "development"
-
- assert_equal "bar", Rails.application.config.my_custom_config["foo"]
- end
-
test "config_for loads custom configuration from yaml accessible as symbol" do
app_file "config/custom.yml", <<-RUBY
development:
@@ -1766,10 +1751,12 @@ module ApplicationTests
assert_equal "bar", Rails.application.config.my_custom_config[:foo]
end
- test "config_for loads custom configuration from yaml accessible as method" do
+ test "config_for loads nested custom configuration from yaml as symbol keys" do
app_file "config/custom.yml", <<-RUBY
development:
- foo: 'bar'
+ foo:
+ bar:
+ baz: 1
RUBY
add_to_config <<-RUBY
@@ -1778,15 +1765,15 @@ module ApplicationTests
app "development"
- assert_equal "bar", Rails.application.config.my_custom_config.foo
+ assert_equal 1, Rails.application.config.my_custom_config[:foo][:bar][:baz]
end
- test "config_for loads nested custom configuration from yaml as symbol keys" do
+ test "config_for makes all hash methods available" do
app_file "config/custom.yml", <<-RUBY
development:
- foo:
- bar:
- baz: 1
+ foo: 0
+ bar:
+ baz: 1
RUBY
add_to_config <<-RUBY
@@ -1795,7 +1782,14 @@ module ApplicationTests
app "development"
- assert_equal 1, Rails.application.config.my_custom_config.foo[:bar][:baz]
+ actual = Rails.application.config.my_custom_config
+
+ assert_equal actual, foo: 0, bar: { baz: 1 }
+ assert_equal actual.keys, [ :foo, :bar ]
+ assert_equal actual.values, [ 0, baz: 1]
+ assert_equal actual.to_h, foo: 0, bar: { baz: 1 }
+ assert_equal actual[:foo], 0
+ assert_equal actual[:bar], baz: 1
end
test "config_for uses the Pathname object if it is provided" do
@@ -1810,7 +1804,7 @@ module ApplicationTests
app "development"
- assert_equal "custom key", Rails.application.config.my_custom_config["key"]
+ 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
@@ -1840,6 +1834,40 @@ module ApplicationTests
assert_equal({}, Rails.application.config.my_custom_config)
end
+ test "config_for implements shared configuration as secrets case found" do
+ app_file "config/custom.yml", <<-RUBY
+ shared:
+ foo: :bar
+ test:
+ foo: :baz
+ RUBY
+
+ add_to_config <<-RUBY
+ config.my_custom_config = config_for('custom')
+ RUBY
+
+ app "test"
+
+ assert_equal(:baz, Rails.application.config.my_custom_config[:foo])
+ end
+
+ test "config_for implements shared configuration as secrets case not found" do
+ app_file "config/custom.yml", <<-RUBY
+ shared:
+ foo: :bar
+ test:
+ foo: :baz
+ RUBY
+
+ add_to_config <<-RUBY
+ config.my_custom_config = config_for('custom')
+ RUBY
+
+ app "development"
+
+ assert_equal(:bar, Rails.application.config.my_custom_config[:foo])
+ end
+
test "config_for with empty file returns an empty hash" do
app_file "config/custom.yml", <<-RUBY
RUBY
@@ -1909,7 +1937,7 @@ module ApplicationTests
app "development"
- assert_equal "custom key", Rails.application.config.my_custom_config["key"]
+ assert_equal "custom key", Rails.application.config.my_custom_config[:key]
end
test "config_for with syntax error show a more descriptive exception" do
@@ -1942,7 +1970,7 @@ module ApplicationTests
RUBY
require "#{app_path}/config/environment"
- assert_equal "unicorn", Rails.application.config.my_custom_config["key"]
+ assert_equal "unicorn", Rails.application.config.my_custom_config[:key]
end
test "api_only is false by default" do