Skip to content

Commit

Permalink
Merge pull request rails#50569 from jonathanhefner/follow-up-50050
Browse files Browse the repository at this point in the history
Handle all false args in `config.x` error check
  • Loading branch information
jonathanhefner authored Jan 3, 2024
2 parents e39373c + 2736ace commit c2e2a1d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions railties/lib/rails/application/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,12 @@ def initialize
def method_missing(method, *args)
if method.end_with?("=")
@configurations[:"#{method[0..-2]}"] = args.first
elsif args.none?
elsif args.empty?
@configurations.fetch(method) {
@configurations[method] = ActiveSupport::OrderedOptions.new
}
else
arguments = args.map(&:inspect)

raise ArgumentError.new("unexpected arguments (%s) while reading `%s` configuration" % [arguments.join(", "), method])
raise ArgumentError, "wrong number of arguments (given #{args.length}, expected 0) when reading configuration `#{method}`"
end
end

Expand Down
4 changes: 2 additions & 2 deletions railties/test/application/configuration/custom_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def teardown
assert_kind_of Method, x.method(:i_do_not_exist)
assert_kind_of ActiveSupport::OrderedOptions, x.i_do_not_exist

assert_raises ArgumentError, match: "unexpected arguments (true, false) while reading `i_do_not_exist` configuration" do
x.i_do_not_exist(true, false)
assert_raises ArgumentError, match: "wrong number of arguments (given 1, expected 0) when reading configuration `i_do_not_exist`" do
x.i_do_not_exist(false)
end
end

Expand Down

0 comments on commit c2e2a1d

Please sign in to comment.