Permalink
Browse files

Pay tribute to timezones. Tune #inspect style.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6766 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 83318c7 commit 4d753adeaf623a341daca7f008c66034c69ba7a0 @jeremy jeremy committed May 18, 2007
Showing with 16 additions and 14 deletions.
  1. +9 −7 activerecord/lib/active_record/base.rb
  2. +7 −7 activerecord/test/base_test.rb
View
16 activerecord/lib/active_record/base.rb
@@ -897,7 +897,7 @@ def descends_from_active_record?
# 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 @@ def attribute_for_inspect(attr_name)
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 @@ def readonly! #: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
View
14 activerecord/test/base_test.rb
@@ -1645,20 +1645,20 @@ def test_to_param_should_return_string
# 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'])

0 comments on commit 4d753ad

Please sign in to comment.