mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Fixed MongoMapper specs
This commit is contained in:
parent
e048d0fab5
commit
8a0f6fa97e
1 changed files with 29 additions and 29 deletions
|
@ -4,57 +4,57 @@ begin
|
||||||
require "mongo_mapper"
|
require "mongo_mapper"
|
||||||
require "ap/mixin/mongo_mapper"
|
require "ap/mixin/mongo_mapper"
|
||||||
|
|
||||||
if defined?(::MongoMapper)
|
describe "AwesomePrint/MongoMapper" do
|
||||||
class User
|
before :all do
|
||||||
include MongoMapper::Document
|
class MongoUser
|
||||||
|
include MongoMapper::Document
|
||||||
|
|
||||||
key :first_name, String
|
key :first_name, String
|
||||||
key :last_name, String
|
key :last_name, String
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "AwesomePrint/MongoMapper" do
|
before :each do
|
||||||
before :each do
|
@ap = AwesomePrint.new(:plain => true)
|
||||||
@ap = AwesomePrint.new(:plain => true)
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "should print for a class instance" do
|
it "should print for a class instance" do
|
||||||
user = User.new(:first_name => "Al", :last_name => "Capone")
|
user = MongoUser.new(:first_name => "Al", :last_name => "Capone")
|
||||||
out = @ap.send(:awesome, user)
|
out = @ap.send(:awesome, user)
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
#<User:0x01234567> {
|
#<MongoUser:0x01234567> {
|
||||||
"_id" => BSON::ObjectId('4d9183739a546f6806000001'),
|
"_id" => BSON::ObjectId('4d9183739a546f6806000001'),
|
||||||
"first_name" => "Al",
|
"first_name" => "Al",
|
||||||
"last_name" => "Capone"
|
"last_name" => "Capone"
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
out.gsub!(/'([\w]+){23}'/, "'4d9183739a546f6806000001'")
|
out.gsub!(/'([\w]+){23}'/, "'4d9183739a546f6806000001'")
|
||||||
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
||||||
out.should == str
|
out.should == str
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should print for a class" do
|
it "should print for a class" do
|
||||||
@ap.send(:awesome, User).should == <<-EOS.strip
|
@ap.send(:awesome, MongoUser).should == <<-EOS.strip
|
||||||
class User < Object {
|
class MongoUser < Object {
|
||||||
"_id" => :object_id,
|
"_id" => :object_id,
|
||||||
"first_name" => :string,
|
"first_name" => :string,
|
||||||
"last_name" => :string
|
"last_name" => :string
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should print for a class when type is undefined" do
|
||||||
|
class Chamelion
|
||||||
|
include MongoMapper::Document
|
||||||
|
key :last_attribute
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should print for a class when type is undefined" do
|
@ap.send(:awesome, Chamelion).should == <<-EOS.strip
|
||||||
class Chamelion
|
|
||||||
include MongoMapper::Document
|
|
||||||
key :last_attribute
|
|
||||||
end
|
|
||||||
|
|
||||||
@ap.send(:awesome, Chamelion).should == <<-EOS.strip
|
|
||||||
class Chamelion < Object {
|
class Chamelion < Object {
|
||||||
"_id" => :object_id,
|
"_id" => :object_id,
|
||||||
"last_attribute" => :undefined
|
"last_attribute" => :undefined
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue