test/spec_mongo_mutation.rb in populate-me-0.0.27 vs test/spec_mongo_mutation.rb in populate-me-0.0.28
- old
+ new
@@ -6,16 +6,16 @@
require 'mongo'
require 'rack/utils'
$:.unshift './lib'
require 'populate_me/mongo'
-MONGO = ::Mongo::MongoClient.new
+MONGO = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'test-mongo-mutation')
class NoDB
include PopulateMe::Mongo::Plug
def self.human_name; 'No DB'; end
end
-DB = MONGO['test-mongo-mutation']
+DB = MONGO.database
class Naked; include PopulateMe::Mongo::Plug; end
class Person
include PopulateMe::Mongo::Plug
@@ -52,25 +52,25 @@
NoDB.db.should==nil
Naked.db.should==DB
end
end
- shared "Empty BSON" do
- it "Should be set to an empty BSON ordered hash by default" do
- @bson.class.should==::BSON::OrderedHash
+ shared "Empty Hash" do
+ it "Should be set to an empty hash by default" do
+ @bson.class.should==Hash
@bson.empty?.should==true
end
end
describe ".schema" do
before { @bson = Naked.schema }
- behaves_like "Empty BSON"
+ behaves_like "Empty Hash"
end
describe ".relationships" do
before { @bson = Naked.relationships }
- behaves_like "Empty BSON"
+ behaves_like "Empty Hash"
end
describe ".human_name" do
it "Returns a legible version of the class name - override when incorrect" do
Article.human_name.should=='Article'
@@ -100,13 +100,18 @@
it 'Makes the argument a BSON::ObjectId if it is a valid string' do
string_id = '000000000000000000000000'
BSON::ObjectId.legal?(string_id).should==true
Address.ref(string_id).should=={'_id'=>BSON::ObjectId.from_string(string_id)}
end
+ it 'Makes a selector for multiple docs if argument is an Array' do
+ Address.ref([]).should=={'_id'=>{'$in'=>[]}}
+ id = BSON::ObjectId.new
+ string_id = '000000000000000000000000'
+ Address.ref([id,string_id]).should=={'_id'=>{'$in'=>[id,BSON::ObjectId.from_string(string_id)]}}
+ end
it 'Just put an empty string in selector for any invalid argument' do
Address.ref('abc').should=={'_id'=>''}
- Address.ref([]).should=={'_id'=>''}
end
end
shared "Basic slot" do
it "Adds the declared slot to the schema" do
@@ -260,13 +265,15 @@
# #save
describe 'CursorMutation' do
it 'Should give the correct class of object on iterations' do
Address.new('body'=>'42').save
- Address.find.to_a[0].model.name.should=='Address'
+ Address.find.each do |a|
+ a.model.name.should=='Address'
+ end
end
end
end
-MONGO.drop_database('test-mongo-mutation')
+DB.drop