From 4d753adeaf623a341daca7f008c66034c69ba7a0 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 18 May 2007 07:24:03 +0000 Subject: [PATCH] Pay tribute to timezones. Tune #inspect style. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6766 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/base.rb | 16 +++++++++------- 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: # 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, '#' + assert_equal topic.inspect, %(#) 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'])