Use `Array#wrap` instead `Array()`
- since `Array()` calls `to_ary` or `to_a` on a subject
- the intent is to 'wrap' subject into an array
Thanks but I don't see what we are gaining with this change. Array#wrap exists mostly to handle the string with new line cases, which doesn't seem to matter here. If this change is important, shouldn't we have a test case?
@josevalim thanks for the quick response!
I think it worth changing as current code assumes that result of record.send(attribute):
The case 2) is flawed obviously.
IMO the intent here is to have associated_records in an array and not to convert association into an array as it may result in losing actual association object and getting an array representation whatever may be.
Let me know!
add test case
So without Array.wrap if an associated object defines to_a method it gets called and error is raised:
See example test
NoMethodError: undefined method `marked_for_destruction?' for "(/)":String
rails/activerecord/lib/active_record/validations/presence.rb:11:in `block (2 levels) in validate'
rails/activerecord/lib/active_record/validations/presence.rb:11:in `block in validate'
rails/activemodel/lib/active_model/validations/callbacks.rb:106:in `block in run_validations!'
test/cases/validations/presence_validation_test.rb:66:in `block in test_validates_presence_doesnt_convert_to_array'
Add CHANGELOG entry for #13557 [ci skip]