2011-03-29 03:48:52 -04:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
|
|
|
2011-05-04 20:55:31 -04:00
|
|
|
begin
|
|
|
|
require "mongo_mapper"
|
|
|
|
require "ap/mixin/mongo_mapper"
|
2011-03-29 03:48:52 -04:00
|
|
|
|
2011-05-04 20:55:31 -04:00
|
|
|
if defined?(MongoMapper)
|
|
|
|
class User
|
|
|
|
include MongoMapper::Document
|
2011-03-29 03:48:52 -04:00
|
|
|
|
2011-05-04 20:55:31 -04:00
|
|
|
key :first_name, String
|
|
|
|
key :last_name, String
|
2011-03-29 03:48:52 -04:00
|
|
|
end
|
|
|
|
|
2011-05-04 20:55:31 -04:00
|
|
|
describe "AwesomePrint/MongoMapper" do
|
|
|
|
before :each do
|
|
|
|
@ap = AwesomePrint.new(:plain => true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should print for a class instance" do
|
|
|
|
user = User.new(:first_name => "Al", :last_name => "Capone")
|
|
|
|
out = @ap.send(:awesome, user)
|
|
|
|
str = <<-EOS.strip
|
2011-03-29 03:48:52 -04:00
|
|
|
#<User:0x01234567> {
|
|
|
|
"_id" => BSON::ObjectId('4d9183739a546f6806000001'),
|
|
|
|
"last_name" => "Capone",
|
|
|
|
"first_name" => "Al"
|
|
|
|
}
|
|
|
|
EOS
|
2011-05-04 20:55:31 -04:00
|
|
|
out.gsub!(/'([\w]+){23}'/, "'4d9183739a546f6806000001'")
|
|
|
|
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
|
|
|
out.should == str
|
|
|
|
end
|
2011-03-29 03:48:52 -04:00
|
|
|
|
2011-05-04 20:55:31 -04:00
|
|
|
it "should print for a class" do
|
|
|
|
@ap.send(:awesome, User).should == <<-EOS.strip
|
2011-03-29 03:48:52 -04:00
|
|
|
class User < Object {
|
|
|
|
"_id" => :object_id,
|
|
|
|
"last_name" => :string,
|
|
|
|
"first_name" => :string
|
|
|
|
}
|
2011-03-29 04:04:18 -04:00
|
|
|
EOS
|
|
|
|
end
|
|
|
|
|
2011-05-04 20:55:31 -04:00
|
|
|
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
|
2011-03-29 04:04:18 -04:00
|
|
|
class Chamelion < Object {
|
|
|
|
"_id" => :object_id,
|
|
|
|
"last_attribute" => :undefined
|
|
|
|
}
|
2011-03-29 03:48:52 -04:00
|
|
|
EOS
|
2011-05-04 20:55:31 -04:00
|
|
|
end
|
2011-03-29 03:48:52 -04:00
|
|
|
end
|
|
|
|
end
|
2011-05-04 20:55:31 -04:00
|
|
|
|
|
|
|
rescue LoadError
|
|
|
|
puts "Skipping MongoMapper specs..."
|
|
|
|
end
|