1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

:undefined when key type is not specified, test

This commit is contained in:
fuJiin 2011-03-29 01:04:18 -07:00
parent cf2839c0d7
commit 75c6868e45
2 changed files with 15 additions and 1 deletions

View file

@ -44,7 +44,7 @@ module AwesomePrintMongoMapper
return object.inspect if !defined?(ActiveSupport::OrderedHash) || !object.respond_to?(:keys) return object.inspect if !defined?(ActiveSupport::OrderedHash) || !object.respond_to?(:keys)
data = object.keys.inject(ActiveSupport::OrderedHash.new) do |hash, c| 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 hash
end end
"class #{object} < #{object.superclass} " << awesome_hash(data) "class #{object} < #{object.superclass} " << awesome_hash(data)

View file

@ -38,6 +38,20 @@ class User < Object {
"last_name" => :string, "last_name" => :string,
"first_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 EOS
end end
end end