diff --git a/lib/ap/mixin/mongo_mapper.rb b/lib/ap/mixin/mongo_mapper.rb index 9b105ee..cb856a7 100644 --- a/lib/ap/mixin/mongo_mapper.rb +++ b/lib/ap/mixin/mongo_mapper.rb @@ -44,7 +44,7 @@ module AwesomePrintMongoMapper return object.inspect if !defined?(ActiveSupport::OrderedHash) || !object.respond_to?(:keys) data = object.keys.inject(ActiveSupport::OrderedHash.new) do |hash, c| - hash[c.first] = c.last.type.to_s.underscore.intern + hash[c.first] = (c.last.type || "undefined").to_s.underscore.intern hash end "class #{object} < #{object.superclass} " << awesome_hash(data) diff --git a/spec/mongo_mapper_spec.rb b/spec/mongo_mapper_spec.rb index 7d429f7..ae2499b 100644 --- a/spec/mongo_mapper_spec.rb +++ b/spec/mongo_mapper_spec.rb @@ -38,6 +38,20 @@ class User < Object { "last_name" => :string, "first_name" => :string } +EOS + end + + it "should print for a class when type is undefined" do + class Chamelion + include MongoMapper::Document + key :last_attribute + end + + @ap.send(:awesome, Chamelion).should == <<-EOS.strip +class Chamelion < Object { + "_id" => :object_id, + "last_attribute" => :undefined +} EOS end end