diff options
Diffstat (limited to 'activerecord')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 16 | ||||
-rwxr-xr-x | activerecord/test/base_test.rb | 14 |
2 files changed, 16 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 65f808815e..365af0a93e 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -897,7 +897,7 @@ module ActiveRecord #:nodoc: # Returns a string looking like: #<Post id:integer, title:string, body:text> def inspect - "#<#{name} #{columns.collect { |c| "#{c.name}:#{c.type}" }.join(", ")}>" + "#<#{name} #{columns.collect { |c| "#{c.name}: #{c.type}" }.join(", ")}>" end @@ -1817,10 +1817,10 @@ module ActiveRecord #:nodoc: raise "Attribute not present #{attr_name}" unless has_attribute?(attr_name) value = read_attribute(attr_name) - if (value.is_a?(String) && value.length > 50) - '"' + value[0..50] + '..."' - elsif (value.is_a?(Date) || value.is_a?(Time)) - '"' + value.to_s(:db) + '"' + if value.is_a?(String) && value.length > 50 + %("#{value[0..50]}...") + elsif value.is_a?(Date) || value.is_a?(Time) + %("#{value.to_s(:db)}") else value.inspect end @@ -1908,8 +1908,10 @@ module ActiveRecord #:nodoc: # Nice pretty inspect. def inspect - attributes_as_nice_string = self.class.column_names.collect {|attr_name| "#{attr_name}: #{attribute_for_inspect(attr_name)}"}.join(", ") - "#<#{self.class.name} #{attributes_as_nice_string}>" + attributes_as_nice_string = self.class.column_names.collect { |name| + "#{name}: #{attribute_for_inspect(name)}" + }.join(", ") + "#<#{self.class} #{attributes_as_nice_string}>" end private diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index 152355c9dd..60e48c763b 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -1645,20 +1645,20 @@ class BasicsTest < Test::Unit::TestCase # assert counts.last <= counts.first, # "expected last count (#{counts.last}) to be <= first count (#{counts.first})" #end - + def test_inspect topic = topics(:first) - assert_equal topic.inspect, '#<Topic id: 1, title: "The First Topic", author_name: "David", author_email_address: "david@loudthinking.com", written_on: "2003-07-16 07:28:11", bonus_time: "2000-01-01 06:28:00", last_read: "2004-04-15", content: "Have a nice day", approved: false, replies_count: 1, parent_id: nil, type: nil>' + assert_equal topic.inspect, %(#<Topic id: 1, title: "The First Topic", author_name: "David", author_email_address: "david@loudthinking.com", written_on: "#{topic.written_on.to_s(:db)}", bonus_time: "#{topic.bonus_time.to_s(:db)}", last_read: "#{topic.last_read.to_s(:db)}", content: "Have a nice day", approved: false, replies_count: 1, parent_id: nil, type: nil>) end - + 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!) - - assert_equal t.attribute_for_inspect(:written_on), '"' + t.written_on.to_s(:db) + '"' - assert_equal t.attribute_for_inspect(:content), '"This is some really long content, longer than 50 ch..."' + + 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) end - + private def assert_readers(model, exceptions) expected_readers = Set.new(model.column_names - ['id']) |