mirror of
https://github.com/github/rails.git
synced 2026-01-30 00:38:00 -05:00
Pay tribute to timezones. Tune #inspect style.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6766 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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'])
|
||||
|
||||
Reference in New Issue
Block a user