Skip to content
Permalink
Browse files

changed inspect so that only non-nil keys are shown by default - rela…

…ted to issue 194
  • Loading branch information
Jonathan Chambers authored and bkeepers committed Sep 2, 2011
1 parent 6c274a5 commit d5c52d848fa9d3767991c49250e6f3c7da38aa32
Showing with 26 additions and 3 deletions.
  1. +17 −0 .project
  2. +3 −2 lib/mongo_mapper/plugins/inspect.rb
  3. +6 −1 test/unit/test_inspect.rb
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>mongomapper</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.aptana.ide.core.unifiedBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.aptana.ruby.core.rubynature</nature>
</natures>
</projectDescription>
@@ -5,8 +5,9 @@ module Inspect
extend ActiveSupport::Concern

module InstanceMethods
def inspect
attributes_as_nice_string = key_names.sort.collect do |name|
def inspect(include_super=false)
key_array = include_super ? key_names : attributes.keys
attributes_as_nice_string = key_array.sort.collect do |name|
"#{name}: #{self[name].inspect}"
end.join(", ")
"#<#{self.class} #{attributes_as_nice_string}>"
@@ -6,14 +6,19 @@ class InspectTest < Test::Unit::TestCase
@document = Doc('User') do
key :name, String
key :age, Integer
key :email, String
end

@doc = @document.new(:name => 'John', :age => 29)
end

should "print out attributes in alpha sorted order" do
should "print out non-nil attributes in alpha sorted order" do
@doc.inspect.should =~ /_id:.*, age: 29, name: "John"/
end

should "print out all attributes when (optional) include_super argument is true" do
@doc.inspect(true).should =~ /_id:.*, age: 29, email: nil, name: "John"/
end

should "include class name" do
@doc.inspect.should =~ /^#<User/

0 comments on commit d5c52d8

Please sign in to comment.
You can’t perform that action at this time.