mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
order keys alphabetically, fixes specs for ruby 1.8 & 1.9
This commit is contained in:
parent
3efefd1f29
commit
9c9ae6e258
2 changed files with 7 additions and 7 deletions
|
@ -31,7 +31,7 @@ module AwesomePrintMongoMapper
|
|||
def awesome_mongo_mapper_instance(object)
|
||||
return object.inspect if !defined?(ActiveSupport::OrderedHash)
|
||||
|
||||
data = object.keys.keys.inject(ActiveSupport::OrderedHash.new) do |hash, name|
|
||||
data = object.keys.keys.sort_by{|k| k}.inject(ActiveSupport::OrderedHash.new) do |hash, name|
|
||||
hash[name] = object[name]
|
||||
hash
|
||||
end
|
||||
|
@ -43,7 +43,7 @@ module AwesomePrintMongoMapper
|
|||
def awesome_mongo_mapper_class(object)
|
||||
return object.inspect if !defined?(ActiveSupport::OrderedHash) || !object.respond_to?(:keys)
|
||||
|
||||
data = object.keys.inject(ActiveSupport::OrderedHash.new) do |hash, c|
|
||||
data = object.keys.sort_by{|k| k}.inject(ActiveSupport::OrderedHash.new) do |hash, c|
|
||||
hash[c.first] = (c.last.type || "undefined").to_s.underscore.intern
|
||||
hash
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ begin
|
|||
require "mongo_mapper"
|
||||
require "ap/mixin/mongo_mapper"
|
||||
|
||||
if defined?(MongoMapper)
|
||||
if defined?(::MongoMapper)
|
||||
class User
|
||||
include MongoMapper::Document
|
||||
|
||||
|
@ -23,8 +23,8 @@ begin
|
|||
str = <<-EOS.strip
|
||||
#<User:0x01234567> {
|
||||
"_id" => BSON::ObjectId('4d9183739a546f6806000001'),
|
||||
"last_name" => "Capone",
|
||||
"first_name" => "Al"
|
||||
"first_name" => "Al",
|
||||
"last_name" => "Capone"
|
||||
}
|
||||
EOS
|
||||
out.gsub!(/'([\w]+){23}'/, "'4d9183739a546f6806000001'")
|
||||
|
@ -36,8 +36,8 @@ EOS
|
|||
@ap.send(:awesome, User).should == <<-EOS.strip
|
||||
class User < Object {
|
||||
"_id" => :object_id,
|
||||
"last_name" => :string,
|
||||
"first_name" => :string
|
||||
"first_name" => :string,
|
||||
"last_name" => :string
|
||||
}
|
||||
EOS
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue