Skip to content

Commit 44bc952

Browse files
authored
Merge pull request rails#50050 from seanpdoyle/config-x-read-with-arguments-no-method
Raise `ArgumentError` when reading from `config.x` with arguments
2 parents bfac3fc + 9a58f7e commit 44bc952

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

railties/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
* Raise `ArgumentError` when reading `config.x.something` with arguments
2+
3+
```ruby
4+
config.x.this_works.this_raises true # raises ArgumentError
5+
```
6+
7+
*Sean Doyle*
8+
19
* Add default PWA files for manifest and service-worker that are served from `app/views/pwa` and can be dynamically rendered through erb. Mount these files explicitly at the root with default routes in the generated routes file.
210

311
*DHH*

railties/lib/rails/application/configuration.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,14 @@ def initialize
569569
def method_missing(method, *args)
570570
if method.end_with?("=")
571571
@configurations[:"#{method[0..-2]}"] = args.first
572-
else
572+
elsif args.none?
573573
@configurations.fetch(method) {
574574
@configurations[method] = ActiveSupport::OrderedOptions.new
575575
}
576+
else
577+
arguments = args.map(&:inspect)
578+
579+
raise ArgumentError.new("unexpected arguments (%s) while reading `%s` configuration" % [arguments.join(", "), method])
576580
end
577581
end
578582

railties/test/application/configuration/custom_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ def teardown
3636
assert_respond_to x, :i_do_not_exist
3737
assert_kind_of Method, x.method(:i_do_not_exist)
3838
assert_kind_of ActiveSupport::OrderedOptions, x.i_do_not_exist
39+
40+
assert_raises ArgumentError, match: "unexpected arguments (true, false) while reading `i_do_not_exist` configuration" do
41+
x.i_do_not_exist(true, false)
42+
end
3943
end
4044

4145
private

0 commit comments

Comments
 (0)