aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2007-12-06 00:01:11 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2007-12-06 00:01:11 +0000
commite16ecaf84c05b054a8ec3b776b3223880edda3d4 (patch)
tree025cc8e8b4097d15d30a700b92d45e913ac6af14
parent8f24701ae17a6bba0a9e648e38df2d17fb884792 (diff)
downloadrails-e16ecaf84c05b054a8ec3b776b3223880edda3d4.tar.gz
rails-e16ecaf84c05b054a8ec3b776b3223880edda3d4.tar.bz2
rails-e16ecaf84c05b054a8ec3b776b3223880edda3d4.zip
Fixed that the truncation of strings longer than 50 chars should use inspect so newlines etc are escaped (closes #10385) [norbert]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8319 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/base.rb2
-rwxr-xr-xactiverecord/test/base_test.rb6
3 files changed, 6 insertions, 4 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index b93f6e63d4..c3b5a60a03 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that the truncation of strings longer than 50 chars should use inspect so newlines etc are escaped #10385 [norbert]
+
* Fixed that habtm associations should be able to set :select as part of their definition and have that honored [DHH]
* Document how the :include option can be used in Calculations::calculate. Closes #7446 [adamwiggins, ultimoamore]
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 506ea5621e..b80ade254b 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -2079,7 +2079,7 @@ module ActiveRecord #:nodoc:
value = read_attribute(attr_name)
if value.is_a?(String) && value.length > 50
- %("#{value[0..50]}...")
+ "#{value[0..50]}...".inspect
elsif value.is_a?(Date) || value.is_a?(Time)
%("#{value.to_s(:db)}")
else
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index e8954b69d0..3a5fdac1ae 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -1732,14 +1732,14 @@ class BasicsTest < Test::Unit::TestCase
def test_attribute_for_inspect
t = topics(:first)
- t.content = %(This is some really long content, longer than 50 characters, so I can test that text is truncated correctly by the new ActiveRecord::Base#inspect method! Yay! BOOM!)
+ 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 '"This is some really long content, longer than 50 ch..."', t.attribute_for_inspect(:content)
+ assert_equal '"The First Topic Now Has A Title With\nNewlines And M..."', t.attribute_for_inspect(:title)
end
def test_becomes
assert_kind_of Reply, topics(:first).becomes(Reply)
assert_equal "The First Topic", topics(:first).becomes(Reply).title
end
-end \ No newline at end of file
+end