Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix and test for displaying embedded documents

  • Loading branch information...
commit 9aba10d620709a11922c1a2fd7f440f091ccdb4f 1 parent f30980f
@kkamil kkamil authored
Showing with 25 additions and 1 deletion.
  1. +5 −1 lib/mongo_mapper/plugins/inspect.rb
  2. +20 −0 test/unit/test_inspect.rb
View
6 lib/mongo_mapper/plugins/inspect.rb
@@ -7,7 +7,11 @@ module Inspect
def inspect(include_nil = false)
keys = include_nil ? key_names : attributes.keys
attributes_as_nice_string = keys.sort.collect do |name|
- "#{name}: #{self[name].inspect}"
+ if self[name].nil?
+ "#{name}: #{self.send(:"#{name}").inspect}"
+ else
+ "#{name}: #{self[name].inspect}"
+ end
end.join(", ")
"#<#{self.class} #{attributes_as_nice_string}>"
end
View
20 test/unit/test_inspect.rb
@@ -23,5 +23,25 @@ class InspectTest < Test::Unit::TestCase
should "include class name" do
@doc.inspect.should =~ /^#<User/
end
+
+ should "include embedded documents" do
+ klass = Doc()
+ pets = EDoc()
+
+ klass.many :pets, :class => pets
+
+ doc = klass.new(:pets => [{:name => "Kitten"}])
+ doc.inspect.should =~ /_id:.*, pets: \[.*_id.*, name: "Kitten".*\]/
+ end
+
+ should "include embedded document" do
+ klass = Doc()
+ pet = EDoc()
+
+ klass.one :pet, :class => pet
+
+ doc = klass.new(:pet => {:name => "Kitten"})
+ doc.inspect.should =~ /_id:.*, pet: .*_id.*, name: "Kitten".*/
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.