-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bfe4510
commit 3aefe23
Showing
3 changed files
with
83 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require "spec/helper/all" | ||
|
||
describe EM::Mongo do | ||
|
||
it "should yield until connection is ready" do | ||
EventMachine.synchrony do | ||
connection = EM::Mongo::Connection.new | ||
connection.connected?.should be_true | ||
|
||
db = connection.db('db') | ||
db.is_a?(EventMachine::Mongo::Database).should be_true | ||
|
||
EventMachine.stop | ||
end | ||
end | ||
|
||
it "should insert a record into db" do | ||
EventMachine.synchrony do | ||
collection = EM::Mongo::Connection.new.db('db').collection('test') | ||
collection.remove({}) # nuke all keys in collection | ||
|
||
obj = collection.insert('hello' => 'world') | ||
obj.keys.should include '_id' | ||
|
||
obj = collection.find | ||
obj.size.should == 1 | ||
obj.first['hello'].should == 'world' | ||
|
||
EventMachine.stop | ||
end | ||
end | ||
|
||
it "should insert a record into db" do | ||
EventMachine.synchrony do | ||
collection = EM::Mongo::Connection.new.db('db').collection('test') | ||
collection.remove({}) # nuke all keys in collection | ||
|
||
obj = collection.insert('hello' => 'world') | ||
obj = collection.insert('hello2' => 'world2') | ||
|
||
obj = collection.find({}) | ||
obj.size.should == 2 | ||
|
||
obj2 = collection.find({}, {:limit => 1}) | ||
obj2.size.should == 1 | ||
|
||
obj3 = collection.first | ||
obj3.is_a?(Hash).should be_true | ||
|
||
EventMachine.stop | ||
end | ||
end | ||
|
||
it "should update records in db" do | ||
EventMachine.synchrony do | ||
collection = EM::Mongo::Connection.new.db('db').collection('test') | ||
collection.remove({}) # nuke all keys in collection | ||
|
||
obj = collection.insert('hello' => 'world') | ||
collection.update({'hello' => 'world'}, {'hello' => 'newworld'}) | ||
|
||
new_obj = collection.first({'_id' => obj['_id']}) | ||
new_obj['hello'].should == 'newworld' | ||
|
||
EventMachine.stop | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,12 @@ | ||
require "spec/helper/all" | ||
require 'spec/helper/all' | ||
require 'lib/em-synchrony/mongo' | ||
require 'mongo' | ||
|
||
describe EM::Mongo do | ||
|
||
it "should yield until connection is ready" do | ||
EventMachine.synchrony do | ||
connection = EM::Mongo::Connection.new | ||
connection.connected?.should be_true | ||
|
||
db = connection.db('db') | ||
db.is_a?(EventMachine::Mongo::Database).should be_true | ||
|
||
EventMachine.stop | ||
end | ||
end | ||
|
||
it "should insert a record into db" do | ||
describe Mongo::Connection do | ||
it 'connects to DB' do | ||
EventMachine.synchrony do | ||
collection = EM::Mongo::Connection.new.db('db').collection('test') | ||
collection.remove({}) # nuke all keys in collection | ||
|
||
obj = collection.insert('hello' => 'world') | ||
obj.keys.should include '_id' | ||
|
||
obj = collection.find | ||
obj.size.should == 1 | ||
obj.first['hello'].should == 'world' | ||
|
||
EventMachine.stop | ||
conn = Mongo::Connection.new 'localhost', 27017, :connect => true | ||
EM.stop | ||
end | ||
end | ||
|
||
it "should insert a record into db" do | ||
EventMachine.synchrony do | ||
collection = EM::Mongo::Connection.new.db('db').collection('test') | ||
collection.remove({}) # nuke all keys in collection | ||
|
||
obj = collection.insert('hello' => 'world') | ||
obj = collection.insert('hello2' => 'world2') | ||
|
||
obj = collection.find({}) | ||
obj.size.should == 2 | ||
|
||
obj2 = collection.find({}, {:limit => 1}) | ||
obj2.size.should == 1 | ||
|
||
obj3 = collection.first | ||
obj3.is_a?(Hash).should be_true | ||
|
||
EventMachine.stop | ||
end | ||
end | ||
|
||
it "should update records in db" do | ||
EventMachine.synchrony do | ||
collection = EM::Mongo::Connection.new.db('db').collection('test') | ||
collection.remove({}) # nuke all keys in collection | ||
|
||
obj = collection.insert('hello' => 'world') | ||
collection.update({'hello' => 'world'}, {'hello' => 'newworld'}) | ||
|
||
new_obj = collection.first({'_id' => obj['_id']}) | ||
new_obj['hello'].should == 'newworld' | ||
|
||
EventMachine.stop | ||
end | ||
end | ||
|
||
end |