From 8b2a21ee9be91f4defe599a8f53dff23318b7b14 Mon Sep 17 00:00:00 2001 From: Matthew Schulkind Date: Mon, 24 Jun 2013 22:04:54 -0400 Subject: [PATCH] Fix mongoid documents with no attributes. --- lib/awesome_print/ext/mongoid.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/awesome_print/ext/mongoid.rb b/lib/awesome_print/ext/mongoid.rb index e5d3fa6..8b31cce 100644 --- a/lib/awesome_print/ext/mongoid.rb +++ b/lib/awesome_print/ext/mongoid.rb @@ -44,7 +44,7 @@ module AwesomePrint def awesome_mongoid_document(object) return object.inspect if !defined?(::ActiveSupport::OrderedHash) - data = object.attributes.sort_by { |key| key }.inject(::ActiveSupport::OrderedHash.new) do |hash, c| + data = (object.attributes || {}).sort_by { |key| key }.inject(::ActiveSupport::OrderedHash.new) do |hash, c| hash[c[0].to_sym] = c[1] hash end