2011-05-13 19:37:24 -04:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2011-03-29 03:48:52 -04:00
|
|
|
|
2011-05-04 20:55:31 -04:00
|
|
|
begin
|
|
|
|
require "mongo_mapper"
|
2011-05-13 19:37:24 -04:00
|
|
|
require "awesome_print/ext/mongo_mapper"
|
2011-03-29 03:48:52 -04:00
|
|
|
|
2011-05-06 17:29:53 -04:00
|
|
|
describe "AwesomePrint/MongoMapper" do
|
|
|
|
before :all do
|
|
|
|
class MongoUser
|
|
|
|
include MongoMapper::Document
|
2011-03-29 03:48:52 -04:00
|
|
|
|
2011-05-06 17:29:53 -04:00
|
|
|
key :first_name, String
|
|
|
|
key :last_name, String
|
|
|
|
end
|
2011-03-29 03:48:52 -04:00
|
|
|
end
|
|
|
|
|
2012-09-06 19:34:11 -04:00
|
|
|
after :all do
|
|
|
|
Object.instance_eval{ remove_const :MongoUser }
|
|
|
|
Object.instance_eval{ remove_const :Chamelion }
|
|
|
|
end
|
|
|
|
|
2011-05-14 00:07:34 -04:00
|
|
|
before do
|
2012-09-06 19:34:11 -04:00
|
|
|
stub_dotfile!
|
2011-05-14 00:07:34 -04:00
|
|
|
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
|
2011-05-06 17:29:53 -04:00
|
|
|
end
|
2011-05-04 20:55:31 -04:00
|
|
|
|
2011-05-14 00:07:34 -04:00
|
|
|
it "should print class instance" do
|
2011-05-06 17:29:53 -04:00
|
|
|
user = MongoUser.new(:first_name => "Al", :last_name => "Capone")
|
|
|
|
out = @ap.send(:awesome, user)
|
|
|
|
str = <<-EOS.strip
|
2011-05-14 00:07:34 -04:00
|
|
|
#<MongoUser:0x01234567
|
2011-11-09 00:27:02 -05:00
|
|
|
@_new = true,
|
|
|
|
attr_accessor :first_name = "Al",
|
|
|
|
attr_accessor :last_name = "Capone",
|
|
|
|
attr_reader :changed_attributes = {
|
2011-05-14 00:07:34 -04:00
|
|
|
"first_name" => nil,
|
|
|
|
"last_name" => nil
|
|
|
|
},
|
|
|
|
attr_reader :first_name_before_type_cast = "Al",
|
2011-11-09 00:27:02 -05:00
|
|
|
attr_reader :last_name_before_type_cast = "Capone"
|
2011-05-14 00:07:34 -04:00
|
|
|
>
|
2011-03-29 03:48:52 -04:00
|
|
|
EOS
|
2011-05-06 17:29:53 -04:00
|
|
|
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
|
|
|
out.should == str
|
|
|
|
end
|
2011-03-29 03:48:52 -04:00
|
|
|
|
2011-05-14 00:07:34 -04:00
|
|
|
it "should print the class" do
|
2011-05-06 17:29:53 -04:00
|
|
|
@ap.send(:awesome, MongoUser).should == <<-EOS.strip
|
|
|
|
class MongoUser < Object {
|
2011-03-29 03:48:52 -04:00
|
|
|
"_id" => :object_id,
|
2011-05-06 15:29:06 -04:00
|
|
|
"first_name" => :string,
|
|
|
|
"last_name" => :string
|
2011-03-29 03:48:52 -04:00
|
|
|
}
|
2011-03-29 04:04:18 -04:00
|
|
|
EOS
|
2011-05-06 17:29:53 -04:00
|
|
|
end
|
2011-03-29 04:04:18 -04:00
|
|
|
|
2011-05-14 00:07:34 -04:00
|
|
|
it "should print the class when type is undefined" do
|
2011-05-06 17:29:53 -04:00
|
|
|
class Chamelion
|
|
|
|
include MongoMapper::Document
|
|
|
|
key :last_attribute
|
|
|
|
end
|
2011-05-04 20:55:31 -04:00
|
|
|
|
2011-05-06 17:29:53 -04:00
|
|
|
@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
|
|
|
|
end
|
|
|
|
end
|
2011-05-04 20:55:31 -04:00
|
|
|
|
2011-11-24 00:33:03 -05:00
|
|
|
rescue LoadError => error
|
|
|
|
puts "Skipping MongoMapper specs: #{error}"
|
2011-05-04 20:55:31 -04:00
|
|
|
end
|