aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-01-01 19:04:29 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-01-01 19:04:29 -0200
commita28f1c279355ac129bb1976d97a7012dd219cb77 (patch)
treecee93151acb660e6935ec9afba6e3b4f38e5a190 /activerecord
parent6fc59d38d82a6c974d8b431dc58fb73d0dac3879 (diff)
parentaaf1af3cb83dad300c87e8abf2d1717cc528ff36 (diff)
downloadrails-a28f1c279355ac129bb1976d97a7012dd219cb77.tar.gz
rails-a28f1c279355ac129bb1976d97a7012dd219cb77.tar.bz2
rails-a28f1c279355ac129bb1976d97a7012dd219cb77.zip
Merge pull request #13557 from gmarik/patch-1
Use `Array#wrap` instead `Array()`
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/validations/presence.rb2
-rw-r--r--activerecord/test/cases/validations/presence_validation_test.rb17
2 files changed, 18 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/validations/presence.rb b/activerecord/lib/active_record/validations/presence.rb
index 6b14c39686..9a19483da3 100644
--- a/activerecord/lib/active_record/validations/presence.rb
+++ b/activerecord/lib/active_record/validations/presence.rb
@@ -5,7 +5,7 @@ module ActiveRecord
super
attributes.each do |attribute|
next unless record.class.reflect_on_association(attribute)
- associated_records = Array(record.send(attribute))
+ associated_records = Array.wrap(record.send(attribute))
# Superclass validates presence. Ensure present records aren't about to be destroyed.
if associated_records.present? && associated_records.all? { |r| r.marked_for_destruction? }
diff --git a/activerecord/test/cases/validations/presence_validation_test.rb b/activerecord/test/cases/validations/presence_validation_test.rb
index 1de8934406..fa04a7d02e 100644
--- a/activerecord/test/cases/validations/presence_validation_test.rb
+++ b/activerecord/test/cases/validations/presence_validation_test.rb
@@ -3,6 +3,8 @@ require "cases/helper"
require 'models/man'
require 'models/face'
require 'models/interest'
+require 'models/speedometer'
+require 'models/dashboard'
class PresenceValidationTest < ActiveRecord::TestCase
class Boy < Man; end
@@ -48,4 +50,19 @@ class PresenceValidationTest < ActiveRecord::TestCase
i2.mark_for_destruction
assert b.invalid?
end
+
+
+ def test_validates_presence_doesnt_convert_to_array
+ Speedometer.validates_presence_of :dashboard
+
+ dash = Dashboard.new
+
+ # dashboard has to_a method
+ def dash.to_a; ['(/)', '(\)']; end
+
+ s = Speedometer.new
+ s.dashboard = dash
+
+ assert_nothing_raised { s.valid? }
+ end
end