2014-12-31 15:59:32 -05:00
|
|
|
require 'spec_helper'
|
2011-10-26 17:47:15 -04:00
|
|
|
|
2014-12-31 15:59:32 -05:00
|
|
|
RSpec.describe "AwesomePrint/Mongoid", skip: ->{ !ExtVerifier.has_mongoid? }.call do
|
2011-10-26 17:47:15 -04:00
|
|
|
|
2014-12-31 15:59:32 -05:00
|
|
|
if ExtVerifier.has_mongoid?
|
2011-10-26 17:47:15 -04:00
|
|
|
before :all do
|
|
|
|
class MongoUser
|
|
|
|
include Mongoid::Document
|
|
|
|
|
|
|
|
field :first_name, :type => String
|
|
|
|
field :last_name, :type => String
|
|
|
|
end
|
|
|
|
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
|
2014-12-31 15:59:32 -05:00
|
|
|
end
|
2012-09-06 19:34:11 -04:00
|
|
|
|
2014-12-31 15:59:32 -05:00
|
|
|
before do
|
|
|
|
@ap = AwesomePrint::Inspector.new :plain => true, :sort_keys => true
|
|
|
|
end
|
2011-10-26 17:47:15 -04:00
|
|
|
|
2014-12-31 15:59:32 -05:00
|
|
|
it "should print class instance" do
|
|
|
|
user = MongoUser.new :first_name => "Al", :last_name => "Capone"
|
|
|
|
out = @ap.send :awesome, user
|
2011-10-26 17:47:15 -04:00
|
|
|
|
2014-12-31 15:59:32 -05:00
|
|
|
object_id = user.id.inspect
|
|
|
|
str = <<-EOS.strip
|
2016-05-09 10:04:42 -04:00
|
|
|
#<MongoUser:placeholder_id> {
|
2012-08-08 07:59:19 -04:00
|
|
|
:_id => #{object_id},
|
2011-12-13 00:41:31 -05:00
|
|
|
:first_name => "Al",
|
|
|
|
:last_name => "Capone"
|
|
|
|
}
|
2014-12-31 15:59:32 -05:00
|
|
|
EOS
|
2016-05-09 16:12:59 -04:00
|
|
|
expect(out).to be_similar_to(str, {:skip_bson => true})
|
2014-12-31 15:59:32 -05:00
|
|
|
end
|
2011-10-26 17:47:15 -04:00
|
|
|
|
2014-12-31 15:59:32 -05:00
|
|
|
it "should print the class" do
|
|
|
|
class_spec = if mongoid_3_0?
|
|
|
|
<<-EOS.strip
|
2014-12-31 13:41:17 -05:00
|
|
|
class MongoUser < Object {
|
|
|
|
:_id => :"moped/bson/object_id",
|
|
|
|
:_type => :string,
|
|
|
|
:first_name => :string,
|
|
|
|
:last_name => :string
|
|
|
|
}
|
2014-12-31 15:59:32 -05:00
|
|
|
EOS
|
|
|
|
elsif mongoid_3_1?
|
|
|
|
<<-EOS.strip
|
2014-12-31 13:41:17 -05:00
|
|
|
class MongoUser < Object {
|
|
|
|
:_id => :"moped/bson/object_id",
|
|
|
|
:first_name => :string,
|
|
|
|
:last_name => :string
|
|
|
|
}
|
2014-12-31 15:59:32 -05:00
|
|
|
EOS
|
|
|
|
elsif mongoid_4_0?
|
|
|
|
<<-EOS.strip
|
2011-10-26 17:47:15 -04:00
|
|
|
class MongoUser < Object {
|
2014-08-07 21:56:23 -04:00
|
|
|
:_id => :"bson/object_id",
|
2011-12-13 00:41:31 -05:00
|
|
|
:first_name => :string,
|
|
|
|
:last_name => :string
|
2011-10-26 17:47:15 -04:00
|
|
|
}
|
2014-12-31 15:59:32 -05:00
|
|
|
EOS
|
|
|
|
end
|
2014-12-31 13:41:17 -05:00
|
|
|
|
2014-12-31 15:59:32 -05:00
|
|
|
expect(@ap.send(:awesome, MongoUser)).to eq class_spec
|
|
|
|
end
|
2011-10-26 17:47:15 -04:00
|
|
|
|
2014-12-31 15:59:32 -05:00
|
|
|
it "should print the class when type is undefined" do
|
|
|
|
class Chamelion
|
|
|
|
include Mongoid::Document
|
|
|
|
field :last_attribute
|
|
|
|
end
|
2011-10-26 17:47:15 -04:00
|
|
|
|
2014-12-31 15:59:32 -05:00
|
|
|
class_spec = if mongoid_3_0?
|
|
|
|
<<-EOS.strip
|
2014-12-31 13:41:17 -05:00
|
|
|
class Chamelion < Object {
|
|
|
|
:_id => :"moped/bson/object_id",
|
|
|
|
:_type => :string,
|
|
|
|
:last_attribute => :object
|
|
|
|
}
|
2014-12-31 15:59:32 -05:00
|
|
|
EOS
|
|
|
|
elsif mongoid_3_1?
|
|
|
|
<<-EOS.strip
|
2014-12-31 13:41:17 -05:00
|
|
|
class Chamelion < Object {
|
|
|
|
:_id => :"moped/bson/object_id",
|
|
|
|
:last_attribute => :object
|
|
|
|
}
|
2014-12-31 15:59:32 -05:00
|
|
|
EOS
|
|
|
|
elsif mongoid_4_0?
|
|
|
|
<<-EOS.strip
|
2011-10-26 17:47:15 -04:00
|
|
|
class Chamelion < Object {
|
2014-08-07 21:56:23 -04:00
|
|
|
:_id => :"bson/object_id",
|
2014-12-31 13:41:17 -05:00
|
|
|
:last_attribute => :object
|
2011-10-26 17:47:15 -04:00
|
|
|
}
|
2014-12-31 15:59:32 -05:00
|
|
|
EOS
|
|
|
|
end
|
2014-12-31 13:41:17 -05:00
|
|
|
|
|
|
|
|
2014-12-31 15:59:32 -05:00
|
|
|
expect(@ap.send(:awesome, Chamelion)).to eq class_spec
|
2011-10-26 17:47:15 -04:00
|
|
|
end
|
|
|
|
end
|