em-mongo 0.2.12 → 0.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,7 +26,7 @@ module EM::Mongo
26
26
  end
27
27
 
28
28
  def insert(obj)
29
- obj['_id'] ||= BSON::ObjectID.new
29
+ obj['_id'] ||= BSON::ObjectId.new
30
30
  @connection.insert(@name, obj)
31
31
  obj
32
32
  end
@@ -199,7 +199,7 @@ module EM::Mongo
199
199
  # Documents
200
200
  docs = (1..number_returned).map do
201
201
  size= peek_size(@buffer)
202
- buf = BSON::ByteBuffer.new(@buffer.get(size))
202
+ buf = @buffer.get(size)
203
203
  BSON::BSON_CODER.deserialize(buf)
204
204
  end
205
205
  [response_to,docs]
@@ -24,7 +24,7 @@ describe EMMongo::Collection do
24
24
  EM::Spec::Mongo.collection do |collection|
25
25
  obj = collection.insert('hello' => 'world')
26
26
  obj.keys.should include '_id'
27
- obj['_id'].should be_a_kind_of(BSON::ObjectID)
27
+ obj['_id'].should be_a_kind_of(BSON::ObjectId)
28
28
  EM::Spec::Mongo.close
29
29
  end
30
30
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 12
9
- version: 0.2.12
8
+ - 13
9
+ version: 0.2.13
10
10
  platform: ruby
11
11
  authors:
12
12
  - bcg
@@ -61,8 +61,6 @@ files:
61
61
  - lib/em-mongo.rb
62
62
  - spec/collection_spec.rb
63
63
  - spec/connection_spec.rb
64
- - spec/integration/collection_spec.rb
65
- - spec/integration/connection_spec.rb
66
64
  - spec/spec_helper.rb
67
65
  has_rdoc: true
68
66
  homepage:
@@ -99,6 +97,4 @@ summary: EventMachine driver for MongoDB.
99
97
  test_files:
100
98
  - spec/collection_spec.rb
101
99
  - spec/connection_spec.rb
102
- - spec/integration/collection_spec.rb
103
- - spec/integration/connection_spec.rb
104
100
  - spec/spec_helper.rb
@@ -1,219 +0,0 @@
1
- require File.expand_path('spec_helper', File.dirname(__FILE__))
2
-
3
- describe EMMongo::Collection do
4
- include EM::SpecHelper
5
-
6
- before(:all) do
7
- @numbers = {
8
- 1 => 'one',
9
- 2 => 'two',
10
- 3 => 'three',
11
- 4 => 'four',
12
- 5 => 'five',
13
- 6 => 'six',
14
- 7 => 'seven',
15
- 8 => 'eight',
16
- 9 => 'nine'
17
- }
18
- end
19
-
20
- after(:all) do
21
- end
22
-
23
- it 'should insert an object' do
24
- EM::Spec::Mongo.collection do |collection|
25
- obj = collection.insert('hello' => 'world')
26
- obj.keys.should include '_id'
27
- obj['_id'].should be_a_kind_of String
28
- obj['_id'].length.should == 24
29
- EM::Spec::Mongo.close
30
- end
31
- end
32
-
33
- it 'should find an object by attribute' do
34
- EM::Spec::Mongo.collection do |collection|
35
- collection.insert("hello" => 'world')
36
- r = collection.find({"hello" => "world"},{}) do |res|
37
- res.size.should >= 1
38
- res[0]["hello"].should == "world"
39
- EM::Spec::Mongo.close
40
- end
41
- end
42
- end
43
-
44
- it 'should find an object by id' do
45
- EM::Spec::Mongo.collection do |collection|
46
- obj = collection.insert('hello' => 'world')
47
- collection.find({'_id' => obj['_id']},{}) do |res|
48
- res.size.should >= 1
49
- res[0]['hello'].should == "world"
50
- EM::Spec::Mongo.close
51
- end
52
- end
53
- end
54
-
55
- it 'should find all objects' do
56
- EM::Spec::Mongo.collection do |collection|
57
- collection.insert('one' => 'one')
58
- collection.insert('two' => 'two')
59
- collection.find do |res|
60
- res.size.should >= 2
61
- EM::Spec::Mongo.close
62
- end
63
- end
64
- end
65
-
66
- it 'should find large sets of objects' do
67
- EM::Spec::Mongo.collection do |collection|
68
- (0..1500).each { |n| collection.insert({n.to_s => n.to_s}) }
69
- collection.find do |res|
70
- res.size.should == EM::Mongo::DEFAULT_QUERY_DOCS
71
- collection.find({}, {:limit => 1500}) do |res|
72
- res.size.should == 1500
73
- EM::Spec::Mongo.close
74
- end
75
- end
76
- end
77
- end
78
-
79
- it 'should update an object' do
80
- EM::Spec::Mongo.collection do |collection|
81
- obj = collection.insert('hello' => 'world')
82
- collection.update({'hello' => 'world'}, {'hello' => 'newworld'})
83
- collection.find({'_id' => obj['_id']},{}) do |res|
84
- res[0]['hello'].should == 'newworld'
85
- EM::Spec::Mongo.close
86
- end
87
- end
88
- end
89
-
90
- it 'should update an object with $inc' do
91
- EM::Spec::Mongo.collection do |collection|
92
- obj = collection.insert('hello' => 'world')
93
- collection.update({'hello' => 'world'}, {'$inc' => {'count' => 1}})
94
- collection.find({'_id' => obj['_id']},{}) do |res|
95
- res.first['hello'].should == 'world'
96
- res.first['count'].should == 1
97
- EM::Spec::Mongo.close
98
- end
99
- end
100
- end
101
-
102
- it 'should remove an object' do
103
- EM::Spec::Mongo.collection do |collection|
104
- obj = collection.insert('hello' => 'world')
105
- collection.remove('_id' => obj['_id'])
106
- collection.find({'hello' => "world"}) do |res|
107
- res.size.should == 0
108
- EM::Spec::Mongo.close
109
- end
110
- end
111
- end
112
-
113
- it 'should remove all objects' do
114
- EM::Spec::Mongo.collection do |collection|
115
- collection.insert('one' => 'one')
116
- collection.insert('two' => 'two')
117
- collection.remove
118
- collection.find do |res|
119
- res.size.should == 0
120
- EM::Spec::Mongo.close
121
- end
122
- end
123
- end
124
-
125
- it 'should insert a Time' do
126
- EM::Spec::Mongo.collection do |collection|
127
- t = Time.now.utc.freeze
128
- collection.insert('date' => t)
129
- collection.find do |res|
130
- res[0]['date'].to_s.should == t.to_s
131
- EM::Spec::Mongo.close
132
- end
133
- end
134
- end
135
-
136
- it 'should insert a complex object' do
137
- EM::Spec::Mongo.collection do |collection|
138
- obj = {
139
- 'array' => [1,2,3],
140
- 'float' => 123.456,
141
- 'hash' => {'boolean' => true},
142
- 'nil' => nil,
143
- 'symbol' => :name,
144
- 'string' => 'hello world',
145
- 'time' => Time.now.to_f,
146
- 'regex' => /abc$/ix
147
- }
148
- retobj = collection.insert(obj)
149
- collection.find({'_id' => obj['_id']}) do |ret|
150
- ret.size.should == 1
151
- ret[0].each_key do |key|
152
- ret[0][key].should == obj[key]
153
- end
154
- EM::Spec::Mongo.close
155
- end
156
-
157
- end
158
- end
159
-
160
- it 'should find an object using nested properties' do
161
- EM::Spec::Mongo.collection do |collection|
162
- collection.insert({
163
- 'name' => 'Google',
164
- 'address' => {
165
- 'city' => 'Mountain View',
166
- 'state' => 'California'}
167
- })
168
-
169
- collection.first('address.city' => 'Mountain View') do |res|
170
- res['name'].should == 'Google'
171
- EM::Spec::Mongo.close
172
- end
173
- end
174
- end
175
-
176
- it 'should find objects with specific values' do
177
- EM::Spec::Mongo.collection do |collection|
178
- @numbers.each do |num, word|
179
- collection.insert({'num' => num, 'word' => word})
180
- end
181
-
182
- collection.find({'num' => {'$in' => [1,3,5]}}) do |res|
183
- res.size.should == 3
184
- res.map{|r| r['num'] }.sort.should == [1,3,5]
185
- EM::Spec::Mongo.close
186
- end
187
- end
188
- end
189
-
190
- it 'should find objects greater than something' do
191
- EM::Spec::Mongo.collection do |collection|
192
- @numbers.each do |num, word|
193
- collection.insert('num' => num, 'word' => word)
194
- end
195
-
196
- collection.find({'num' => {'$gt' => 3}}) do |res|
197
- res.size.should == 6
198
- res.map{|r| r['num'] }.sort.should == [4,5,6,7,8,9]
199
- EM::Spec::Mongo.close
200
- end
201
- end
202
- end
203
-
204
- it 'should handle multiple pending queries' do
205
- EM::Spec::Mongo.collection do |collection|
206
- id = collection.insert("foo" => "bar")['_id']
207
- received = 0
208
-
209
- 10.times do |n|
210
- collection.first("_id" => id) do |res|
211
- received += 1
212
- EM::Spec::Mongo.close if received == 10
213
- end
214
- end
215
-
216
- end
217
- end
218
-
219
- end
@@ -1,48 +0,0 @@
1
- require File.expand_path('spec_helper', File.dirname(__FILE__))
2
-
3
- describe EMMongo::Connection do
4
- include EM::SpecHelper
5
-
6
- it 'should connect' do
7
- em do
8
- connection = EMMongo::Connection.new
9
- EM.next_tick do
10
- connection.should be_connected
11
- done
12
- end
13
- end
14
- end
15
-
16
- it 'should close' do
17
- em do
18
- connection = EMMongo::Connection.new
19
-
20
- EM.add_timer(1) do
21
- connection.should be_connected
22
- connection.close
23
- end
24
-
25
- EM.add_timer(2) do
26
- EM.next_tick do
27
- connection.should_not be_connected
28
- done
29
- end
30
- end
31
- end
32
- end
33
-
34
- it 'should instantiate a Database' do
35
- EM::Spec::Mongo.connection do |connection|
36
- db1 = connection.db
37
- db1.should be_kind_of(EM::Mongo::Database)
38
-
39
- db2 = connection.db('db2')
40
- db2.should be_kind_of(EM::Mongo::Database)
41
- db2.should_not == db1
42
-
43
- EM::Spec::Mongo.close
44
- end
45
- end
46
-
47
-
48
- end