Skip to content

Commit 2736ace

Browse files
Handle all false args in config.x error check
Follow-up to rails#50050. Using `args.none?` does not catch the case when all args are `false` or `nil`. Therefore, this commit changes the condition to `args.empty?`. This commit also changes the error message to more closely match Ruby's error messages when trying to pass an arg to a getter method: ```ruby Rails.configuration.x(false) # => wrong number of arguments (given 1, expected 0) (ArgumentError) Rails.configuration.x.i_do_not_exist(false) # => wrong number of arguments (given 1, expected 0) when reading configuration `i_do_not_exist` (ArgumentError) ```
1 parent 1c3ae87 commit 2736ace

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

railties/lib/rails/application/configuration.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,14 +569,12 @@ def initialize
569569
def method_missing(method, *args)
570570
if method.end_with?("=")
571571
@configurations[:"#{method[0..-2]}"] = args.first
572-
elsif args.none?
572+
elsif args.empty?
573573
@configurations.fetch(method) {
574574
@configurations[method] = ActiveSupport::OrderedOptions.new
575575
}
576576
else
577-
arguments = args.map(&:inspect)
578-
579-
raise ArgumentError.new("unexpected arguments (%s) while reading `%s` configuration" % [arguments.join(", "), method])
577+
raise ArgumentError, "wrong number of arguments (given #{args.length}, expected 0) when reading configuration `#{method}`"
580578
end
581579
end
582580

railties/test/application/configuration/custom_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def teardown
3737
assert_kind_of Method, x.method(:i_do_not_exist)
3838
assert_kind_of ActiveSupport::OrderedOptions, x.i_do_not_exist
3939

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)
40+
assert_raises ArgumentError, match: "wrong number of arguments (given 1, expected 0) when reading configuration `i_do_not_exist`" do
41+
x.i_do_not_exist(false)
4242
end
4343
end
4444

0 commit comments

Comments
 (0)