aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/attribute_methods_test.rb
diff options
context:
space:
mode:
authorKevin McPhillips <github@kevinmcphillips.ca>2016-06-28 14:54:17 -0400
committerKevin McPhillips <github@kevinmcphillips.ca>2016-06-29 10:31:09 -0400
commita023fd665701cd455d9458e1b1a0cd0e550202aa (patch)
treeb3d5ecd69d01c45351d6f6046e047c2484013256 /activerecord/test/cases/attribute_methods_test.rb
parent160cc331796ebfbcd6da83e96f391ab5732832b6 (diff)
downloadrails-a023fd665701cd455d9458e1b1a0cd0e550202aa.tar.gz
rails-a023fd665701cd455d9458e1b1a0cd0e550202aa.tar.bz2
rails-a023fd665701cd455d9458e1b1a0cd0e550202aa.zip
Do not specal case inspecting associated arrays of over 10 elements, preventing infinite looping in some cases.
Diffstat (limited to 'activerecord/test/cases/attribute_methods_test.rb')
-rw-r--r--activerecord/test/cases/attribute_methods_test.rb23
1 files changed, 21 insertions, 2 deletions
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb
index 1db52af59b..04126e87e4 100644
--- a/activerecord/test/cases/attribute_methods_test.rb
+++ b/activerecord/test/cases/attribute_methods_test.rb
@@ -27,14 +27,33 @@ class AttributeMethodsTest < ActiveRecord::TestCase
ActiveRecord::Base.send(:attribute_method_matchers).concat(@old_matchers)
end
- def test_attribute_for_inspect
+ def test_attribute_for_inspect_string
t = topics(:first)
t.title = "The First Topic Now Has A Title With\nNewlines And More Than 50 Characters"
- assert_equal %("#{t.written_on.to_s(:db)}"), t.attribute_for_inspect(:written_on)
assert_equal '"The First Topic Now Has A Title With\nNewlines And ..."', t.attribute_for_inspect(:title)
end
+ def test_attribute_for_inspect_date
+ t = topics(:first)
+
+ assert_equal %("#{t.written_on.to_s(:db)}"), t.attribute_for_inspect(:written_on)
+ end
+
+ def test_attribute_for_inspect_array
+ t = topics(:first)
+ t.content = [Object.new]
+
+ assert_match %r(\[#<Object:0x[0-9a-f]+>\]), t.attribute_for_inspect(:content)
+ end
+
+ def test_attribute_for_inspect_long_array
+ t = topics(:first)
+ t.content = (1..11).to_a
+
+ assert_equal "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]", t.attribute_for_inspect(:content)
+ end
+
def test_attribute_present
t = Topic.new
t.title = "hello there!"