mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Adding support for Mongoid 3 and Moped
This commit is contained in:
parent
fea9567eb4
commit
2779249a4b
2 changed files with 23 additions and 6 deletions
|
@ -20,7 +20,7 @@ module AwesomePrint
|
|||
cast = :mongoid_class
|
||||
elsif object.class.ancestors.include?(::Mongoid::Document)
|
||||
cast = :mongoid_document
|
||||
elsif object.is_a?(::BSON::ObjectId)
|
||||
elsif defined?(::BSON) && object.is_a?(::BSON::ObjectId) || defined?(::Moped) && object.is_a?(::Moped::BSON::ObjectId)
|
||||
cast = :mongoid_bson_id
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,22 +22,37 @@ begin
|
|||
user = MongoUser.new :first_name => "Al", :last_name => "Capone"
|
||||
out = @ap.send :awesome, user
|
||||
|
||||
str = <<-EOS.strip
|
||||
if defined?(::Moped)
|
||||
str = <<-EOS.strip
|
||||
#<MongoUser:0x01234567> {
|
||||
:_id => "424242424242424242424242",
|
||||
:first_name => "Al",
|
||||
:last_name => "Capone"
|
||||
}
|
||||
EOS
|
||||
else
|
||||
str = <<-EOS.strip
|
||||
#<MongoUser:0x01234567> {
|
||||
:_id => BSON::ObjectId('424242424242424242424242'),
|
||||
:first_name => "Al",
|
||||
:last_name => "Capone"
|
||||
}
|
||||
EOS
|
||||
end
|
||||
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
||||
out.gsub!(/Id\('[^']+/, "Id('424242424242424242424242")
|
||||
if defined?(::Moped)
|
||||
out.gsub!(/:_id => \"[^"]+/, ":_id => \"424242424242424242424242")
|
||||
else
|
||||
out.gsub!(/Id\('[^']+/, "Id('424242424242424242424242")
|
||||
end
|
||||
out.should == str
|
||||
end
|
||||
|
||||
it "should print the class" do
|
||||
moped_or_not = defined?(::Moped) ? 'moped/' : ''
|
||||
@ap.send(:awesome, MongoUser).should == <<-EOS.strip
|
||||
class MongoUser < Object {
|
||||
:_id => :"bson/object_id",
|
||||
:_id => :"#{moped_or_not}bson/object_id",
|
||||
:_type => :string,
|
||||
:first_name => :string,
|
||||
:last_name => :string
|
||||
|
@ -51,11 +66,13 @@ EOS
|
|||
field :last_attribute
|
||||
end
|
||||
|
||||
moped_or_not = defined?(::Moped) ? 'moped/' : ''
|
||||
last_attribute = defined?(::BSON) ? '"mongoid/fields/serializable/object"' : 'object'
|
||||
@ap.send(:awesome, Chamelion).should == <<-EOS.strip
|
||||
class Chamelion < Object {
|
||||
:_id => :"bson/object_id",
|
||||
:_id => :"#{moped_or_not}bson/object_id",
|
||||
:_type => :string,
|
||||
:last_attribute => :"mongoid/fields/serializable/object"
|
||||
:last_attribute => :#{last_attribute}
|
||||
}
|
||||
EOS
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue