mongoid 3.1.6 → 3.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d24616c46c93a31777a37b97c93cca0b10df2625
4
- data.tar.gz: 000fc93a80cfc7e296f305a1ddca2d77517578aa
3
+ metadata.gz: 49f91c3bfdee011f4254db9a310c1ee705534a6f
4
+ data.tar.gz: 17e51120acb04dc04419144c4f8c67731e58198e
5
5
  SHA512:
6
- metadata.gz: 71d177604ae5df43f63a5f45b1fa68ea2bedf263009ca58406e23ef6c3fdbe09f0b76bdf5e4c70a9612c515f3aa2fca8ae384d62ede1e86629f788905822e483
7
- data.tar.gz: f840e9a8796efaa27b3536c95270c9e5abcbe233718a546095cc09671fd1d6edb8c7d16b55505ad33e1737ab610fb422b04318d0486c37841a2b9c495959ca2f
6
+ metadata.gz: fa78c03c62ff52aeeb68a5f5bb1092df93321143a5c4b25e8661d5e5dca0ec46f57820f20b14a104905bb419aa925dba7767eec8bd97c252b5b9d07abea4ce00
7
+ data.tar.gz: 098d1c1762169ad463118552c61417156e8fd6a96964dd7d84c08fa31e6479f6ec4cedd9011f24cd20e9debaba84cae8c9abe310723937f28225fd0885f90e16
@@ -3,6 +3,16 @@
3
3
  For instructions on upgrading to newer versions, visit
4
4
  [mongoid.org](http://mongoid.org/en/mongoid/docs/upgrading.html).
5
5
 
6
+ ## 3.1.7
7
+
8
+ ### Resolved Issues
9
+
10
+ * \#3397 Fixed $ne matcher for embedded documents to match server behaviour.
11
+
12
+ * \#3414 Backkport skip and limit options on aggregation. (Wojciech Piekutowski)
13
+
14
+ * \#3469 Fix RegexpError: failed to allocate memory: /\./ on .hash_dot_syntax? (Dmitry Krasnoukhov)
15
+
6
16
  ## 3.1.6
7
17
 
8
18
  ### Resolved Issues
@@ -86,7 +86,7 @@ module Mongoid
86
86
  #
87
87
  # @since 1.0.0
88
88
  def read_attribute(name)
89
- normalized = name.to_s
89
+ normalized = database_field_name(name.to_s)
90
90
  if hash_dot_syntax?(normalized)
91
91
  attributes.__nested__(normalized)
92
92
  else
@@ -308,7 +308,7 @@ module Mongoid
308
308
  #
309
309
  # @since 3.0.15
310
310
  def hash_dot_syntax?(string)
311
- string =~ /\./
311
+ string.include?(".")
312
312
  end
313
313
 
314
314
  # Used for allowing accessor methods for dynamic attributes.
@@ -129,6 +129,8 @@ module Mongoid
129
129
  db_field = "$#{database_field_name(field)}"
130
130
  pipeline = []
131
131
  pipeline << { "$match" => criteria.nin(field => nil).selector }
132
+ pipeline << { "$sort" => criteria.options[:sort] } if criteria.options[:sort]
133
+ pipeline << { "$skip" => criteria.options[:skip] } if criteria.options[:skip]
132
134
  pipeline << { "$limit" => criteria.options[:limit] } if criteria.options[:limit]
133
135
  pipeline << {
134
136
  "$group" => {
@@ -0,0 +1,141 @@
1
+ # encoding: utf-8
2
+ module Mongoid
3
+ class Criteria
4
+ module Findable
5
+
6
+ # Execute the criteria or raise an error if no documents found.
7
+ #
8
+ # @example Execute or raise
9
+ # criteria.execute_or_raise(id)
10
+ #
11
+ # @param [ Object ] args The arguments passed.
12
+ #
13
+ # @raise [ Errors::DocumentNotFound ] If nothing returned.
14
+ #
15
+ # @return [ Document, Array<Document> ] The document(s).
16
+ #
17
+ # @since 2.0.0
18
+ def execute_or_raise(ids, multi)
19
+ result = multiple_from_db(ids)
20
+ check_for_missing_documents!(result, ids)
21
+ multi ? result : result.first
22
+ end
23
+
24
+ # Find the matchind document(s) in the criteria for the provided ids.
25
+ #
26
+ # @example Find by an id.
27
+ # criteria.find(BSON::ObjectId.new)
28
+ #
29
+ # @example Find by multiple ids.
30
+ # criteria.find([ BSON::ObjectId.new, BSON::ObjectId.new ])
31
+ #
32
+ # @param [ Array<BSON::ObjectId> ] args The ids to search for.
33
+ #
34
+ # @return [ Array<Document>, Document ] The matching document(s).
35
+ #
36
+ # @since 1.0.0
37
+ def find(*args)
38
+ ids = args.__find_args__
39
+ raise_invalid if ids.any?(&:nil?)
40
+ p "YOOO"
41
+ p ids
42
+ for_ids(ids).execute_or_raise(ids, args.multi_arged?)
43
+ end
44
+
45
+ # Adds a criterion to the +Criteria+ that specifies an id that must be matched.
46
+ #
47
+ # @example Add a single id criteria.
48
+ # criteria.for_ids([ 1 ])
49
+ #
50
+ # @example Add multiple id criteria.
51
+ # criteria.for_ids([ 1, 2 ])
52
+ #
53
+ # @param [ Array ] ids The array of ids.
54
+ #
55
+ # @return [ Criteria ] The cloned criteria.
56
+ def for_ids(ids)
57
+ ids = mongoize_ids(ids)
58
+ if ids.size > 1
59
+ send(id_finder, { _id: { "$in" => ids }})
60
+ else
61
+ send(id_finder, { _id: ids.first })
62
+ end
63
+ end
64
+
65
+ # Get the documents from the identity map, and if not found hit the
66
+ # database.
67
+ #
68
+ # @example Get the documents from the map or criteria.
69
+ # criteria.multiple_from_map_or_db(ids)
70
+ #
71
+ # @param [ ids ] The searched ids.
72
+ #
73
+ # @return [ Array<Document> ] The found documents.
74
+ def multiple_from_db(ids)
75
+ return entries if embedded?
76
+ ids = mongoize_ids(ids)
77
+ ids.empty? ? [] : from_database(ids)
78
+ end
79
+
80
+ private
81
+
82
+ # Get the finder used to generate the id query.
83
+ #
84
+ # @api private
85
+ #
86
+ # @example Get the id finder.
87
+ # criteria.id_finder
88
+ #
89
+ # @return [ Symbol ] The name of the finder method.
90
+ #
91
+ # @since 3.1.0
92
+ def id_finder
93
+ @id_finder ||= extract_id ? :all_of : :where
94
+ end
95
+
96
+ # Get documents from the database only.
97
+ #
98
+ # @api private
99
+ #
100
+ # @example Get documents from the database.
101
+ # criteria.from_database(ids)
102
+ #
103
+ # @param [ Array<Object> ] ids The ids to fetch with.
104
+ #
105
+ # @return [ Array<Document> ] The matching documents.
106
+ #
107
+ # @since 3.0.0
108
+ def from_database(ids)
109
+ (ids.size > 1 ? any_in(id: ids) : where(id: ids.first)).entries
110
+ end
111
+
112
+ # Convert all the ids to their proper types.
113
+ #
114
+ # @api private
115
+ #
116
+ # @example Convert the ids.
117
+ # criteria.mongoize_ids(ids)
118
+ #
119
+ # @param [ Array<Object> ] ids The ids to convert.
120
+ #
121
+ # @return [ Array<Object> ] The converted ids.
122
+ #
123
+ # @since 3.0.0
124
+ def mongoize_ids(ids)
125
+ ids.map{ |id| klass.fields["_id"].mongoize(id) }
126
+ end
127
+
128
+ # Convenience method of raising an invalid options error.
129
+ #
130
+ # @example Raise the error.
131
+ # criteria.raise_invalid
132
+ #
133
+ # @raise [ Errors::InvalidOptions ] The error.
134
+ #
135
+ # @since 2.0.0
136
+ def raise_invalid
137
+ raise Errors::InvalidFind.new
138
+ end
139
+ end
140
+ end
141
+ end
@@ -14,7 +14,7 @@ module Mongoid
14
14
  #
15
15
  # @return [ true, false ] If a value exists.
16
16
  def matches?(value)
17
- @attribute != value.values.first
17
+ !super(value.values.first)
18
18
  end
19
19
  end
20
20
  end
@@ -71,7 +71,7 @@ module Mongoid
71
71
  # @return [ String, Symbol ] The path to the field.
72
72
  #
73
73
  # @since 2.1.0
74
- def path(field = field)
74
+ def path(field = self.field)
75
75
  position = document.atomic_position
76
76
  position.blank? ? field : "#{position}.#{field}"
77
77
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid
3
- VERSION = "3.1.6"
3
+ VERSION = "3.1.7"
4
4
  end
@@ -17,7 +17,7 @@ module Rails
17
17
  def create_indexes(*globs)
18
18
  models(*globs).each do |model|
19
19
  next if model.index_options.empty?
20
- unless model.embedded?
20
+ if !model.embedded? || model.cyclic?
21
21
  model.create_indexes
22
22
  logger.info("MONGOID: Created indexes on #{model}:")
23
23
  model.index_options.each_pair do |index, options|
@@ -0,0 +1,9 @@
1
+ class Draft
2
+ include Mongoid::Document
3
+
4
+ field :text
5
+
6
+ recursively_embeds_one
7
+
8
+ index text: 1
9
+ end
@@ -0,0 +1,365 @@
1
+ require "spec_helper"
2
+
3
+ describe Mongoid::Atomic do
4
+
5
+ describe "#add_atomic_pull" do
6
+
7
+ let!(:person) do
8
+ Person.create
9
+ end
10
+
11
+ let(:address) do
12
+ person.addresses.create
13
+ end
14
+
15
+ let(:location) do
16
+ address.locations.create
17
+ end
18
+
19
+ before do
20
+ person.add_atomic_pull(address)
21
+ end
22
+
23
+ it "adds the document to the delayed atomic pulls" do
24
+ expect(person.delayed_atomic_pulls["addresses"]).to eq([ address ])
25
+ end
26
+
27
+ it "flags the document for destruction" do
28
+ expect(address).to be_flagged_for_destroy
29
+ end
30
+ end
31
+
32
+ describe "#add_atomic_unset" do
33
+
34
+ let!(:person) do
35
+ Person.new
36
+ end
37
+
38
+ let(:name) do
39
+ person.build_name
40
+ end
41
+
42
+ before do
43
+ person.add_atomic_unset(name)
44
+ end
45
+
46
+ it "adds the document to the delayed atomic unsets" do
47
+ expect(person.delayed_atomic_unsets["name"]).to eq([ name ])
48
+ end
49
+
50
+ it "flags the document for destruction" do
51
+ expect(name).to be_flagged_for_destroy
52
+ end
53
+ end
54
+
55
+ describe "#atomic_updates" do
56
+
57
+ context "when the document is persisted" do
58
+
59
+ let(:person) do
60
+ Person.create
61
+ end
62
+
63
+ context "when the document is modified" do
64
+
65
+ before do
66
+ person.title = "Sir"
67
+ end
68
+
69
+ it "returns the atomic updates" do
70
+ expect(person.atomic_updates).to eq({ "$set" => { "title" => "Sir" }})
71
+ end
72
+
73
+ context "when an embeds many child is added" do
74
+
75
+ let!(:address) do
76
+ person.addresses.build(street: "Oxford St")
77
+ end
78
+
79
+ it "returns a $set and $pushAll for modifications" do
80
+ expect(person.atomic_updates).to eq(
81
+ {
82
+ "$set" => { "title" => "Sir" },
83
+ "$pushAll" => { "addresses" => [
84
+ { "_id" => "oxford-st", "street" => "Oxford St" }
85
+ ]}
86
+ }
87
+ )
88
+ end
89
+ end
90
+
91
+ context "when an embeds one child is added" do
92
+
93
+ let!(:name) do
94
+ person.build_name(first_name: "Lionel")
95
+ end
96
+
97
+ it "returns a $set for modifications" do
98
+ expect(person.atomic_updates).to eq(
99
+ {
100
+ "$set" => {
101
+ "title" => "Sir",
102
+ "name" => { "_id" => "Lionel-", "first_name" => "Lionel" }
103
+ }
104
+ }
105
+ )
106
+ end
107
+ end
108
+
109
+ context "when an existing embeds many gets modified" do
110
+
111
+ let!(:address) do
112
+ person.addresses.create(street: "Oxford St")
113
+ end
114
+
115
+ before do
116
+ address.street = "Bond St"
117
+ end
118
+
119
+ context "when asking for the updates from the root" do
120
+
121
+ it "returns the $set with correct position and modifications" do
122
+ expect(person.atomic_updates).to eq(
123
+ { "$set" => { "title" => "Sir", "addresses.0.street" => "Bond St" }}
124
+ )
125
+ end
126
+ end
127
+
128
+ context "when asking for the updates from the child" do
129
+
130
+ it "returns the $set with correct position and modifications" do
131
+ expect(address.atomic_updates).to eq(
132
+ { "$set" => { "addresses.0.street" => "Bond St" }}
133
+ )
134
+ end
135
+ end
136
+
137
+ context "when an existing 2nd level embedded child gets modified" do
138
+
139
+ let!(:location) do
140
+ address.locations.create(name: "Home")
141
+ end
142
+
143
+ before do
144
+ location.name = "Work"
145
+ end
146
+
147
+ context "when asking for the updates from the root" do
148
+
149
+ it "returns the $set with correct positions and modifications" do
150
+ expect(person.atomic_updates).to eq(
151
+ { "$set" => {
152
+ "title" => "Sir",
153
+ "addresses.0.street" => "Bond St",
154
+ "addresses.0.locations.0.name" => "Work" }
155
+ }
156
+ )
157
+ end
158
+ end
159
+
160
+ context "when asking for the updates from the 1st level child" do
161
+
162
+ it "returns the $set with correct positions and modifications" do
163
+ expect(address.atomic_updates).to eq(
164
+ { "$set" => {
165
+ "addresses.0.street" => "Bond St",
166
+ "addresses.0.locations.0.name" => "Work" }
167
+ }
168
+ )
169
+ end
170
+ end
171
+
172
+ context "when asking for the updates from the 2nd level child" do
173
+
174
+ it "returns the $set with correct positions and modifications" do
175
+ expect(location.atomic_updates).to eq(
176
+ { "$set" => {
177
+ "addresses.0.locations.0.name" => "Work" }
178
+ }
179
+ )
180
+ end
181
+ end
182
+ end
183
+
184
+ context "when a 2nd level embedded child gets added" do
185
+
186
+ let!(:location) do
187
+ address.locations.build(name: "Home")
188
+ end
189
+
190
+ context "when asking for the updates from the root" do
191
+
192
+ it "returns the $set with correct positions and modifications" do
193
+ expect(person.atomic_updates).to eq(
194
+ {
195
+ "$set" => {
196
+ "title" => "Sir",
197
+ "addresses.0.street" => "Bond St"
198
+ },
199
+ conflicts: {
200
+ "$pushAll" => {
201
+ "addresses.0.locations" => [{ "_id" => location.id, "name" => "Home" }]
202
+ }
203
+ }
204
+ }
205
+ )
206
+ end
207
+ end
208
+
209
+ context "when asking for the updates from the 1st level child" do
210
+
211
+ it "returns the $set with correct positions and modifications" do
212
+ expect(address.atomic_updates).to eq(
213
+ {
214
+ "$set" => {
215
+ "addresses.0.street" => "Bond St"
216
+ },
217
+ conflicts: {
218
+ "$pushAll" => {
219
+ "addresses.0.locations" => [{ "_id" => location.id, "name" => "Home" }]
220
+ }
221
+ }
222
+ }
223
+ )
224
+ end
225
+ end
226
+ end
227
+
228
+ context "when an embedded child gets unset" do
229
+
230
+ before do
231
+ person.attributes = { addresses: nil }
232
+ end
233
+
234
+ let(:updates) do
235
+ person.atomic_updates
236
+ end
237
+
238
+ it "returns the $set for the first level and $unset for other." do
239
+ expect(updates).to eq({
240
+ "$unset" => { "addresses" => true },
241
+ "$set" => { "title" => "Sir" }
242
+ })
243
+ end
244
+ end
245
+
246
+ context "when adding a new second level child" do
247
+
248
+ let!(:new_address) do
249
+ person.addresses.build(street: "Another")
250
+ end
251
+
252
+ let!(:location) do
253
+ new_address.locations.build(name: "Home")
254
+ end
255
+
256
+ context "when asking for the updates from the root document" do
257
+
258
+ it "returns the $set for 1st level and other for the 2nd level" do
259
+ expect(person.atomic_updates).to eq(
260
+ {
261
+ "$set" => {
262
+ "title" => "Sir",
263
+ "addresses.0.street" => "Bond St"
264
+ },
265
+ conflicts: {
266
+ "$pushAll" => {
267
+ "addresses" => [{
268
+ "_id" => new_address.id,
269
+ "street" => "Another",
270
+ "locations" => [
271
+ "_id" => location.id,
272
+ "name" => "Home"
273
+ ]
274
+ }]
275
+ }
276
+ }
277
+ }
278
+ )
279
+ end
280
+ end
281
+
282
+ context "when asking for the updates from the 1st level document" do
283
+
284
+ it "returns the $set for 1st level and other for the 2nd level" do
285
+ expect(address.atomic_updates).to eq(
286
+ { "$set" => { "addresses.0.street" => "Bond St" }}
287
+ )
288
+ end
289
+ end
290
+ end
291
+
292
+ context "when adding a new child beetween two existing and updating one of them" do
293
+
294
+ let!(:new_address) do
295
+ person.addresses.build(street: "Ipanema")
296
+ end
297
+
298
+ let!(:location) do
299
+ new_address.locations.build(name: "Home")
300
+ end
301
+
302
+ before do
303
+ person.addresses[0] = new_address
304
+ person.addresses[1] = address
305
+ end
306
+
307
+ it "returns the $set for 1st and 2nd level and other for the 3nd level" do
308
+ expect(person.atomic_updates).to eq(
309
+ {
310
+ "$set" => {
311
+ "title" => "Sir"
312
+ },
313
+ "$pushAll" => {
314
+ "addresses" => [{
315
+ "_id" => new_address.id,
316
+ "street" => "Ipanema",
317
+ "locations" => [
318
+ "_id" => location.id,
319
+ "name" => "Home"
320
+ ]
321
+ }]
322
+ },
323
+ conflicts: {
324
+ "$set" => { "addresses.0.street"=>"Bond St" }
325
+ }
326
+ }
327
+ )
328
+ end
329
+ end
330
+ end
331
+
332
+ context "when adding new embedded docs at multiple levels" do
333
+
334
+ let!(:address) do
335
+ person.addresses.build(street: "Another")
336
+ end
337
+
338
+ let!(:location) do
339
+ address.locations.build(name: "Home")
340
+ end
341
+
342
+ it "returns the proper $sets and $pushAlls for all levels" do
343
+ expect(person.atomic_updates).to eq(
344
+ {
345
+ "$set" => {
346
+ "title" => "Sir",
347
+ },
348
+ "$pushAll" => {
349
+ "addresses" => [{
350
+ "_id" => address.id,
351
+ "street" => "Another",
352
+ "locations" => [
353
+ "_id" => location.id,
354
+ "name" => "Home"
355
+ ]
356
+ }]
357
+ }
358
+ }
359
+ )
360
+ end
361
+ end
362
+ end
363
+ end
364
+ end
365
+ end
@@ -15,8 +15,7 @@ describe Mongoid::Atomic::Positionable do
15
15
  "$set" => {
16
16
  "field" => "value",
17
17
  "children.0.field" => "value",
18
- "children.0.children.1.children.3.field" => "value",
19
- "children.0.children.1.children.3.field" => "value",
18
+ "children.0.children.1.children.3.field" => "value"
20
19
  },
21
20
  "$pushAll" => {
22
21
  "children.0.children.1.children.3.fields" => [ "value", "value" ]
@@ -113,8 +112,7 @@ describe Mongoid::Atomic::Positionable do
113
112
  "$set" => {
114
113
  "field" => "value",
115
114
  "children.$.field" => "value",
116
- "children.$.children.1.children.3.field" => "value",
117
- "children.$.children.1.children.3.field" => "value",
115
+ "children.$.children.1.children.3.field" => "value"
118
116
  },
119
117
  "$pushAll" => {
120
118
  "children.$.children.1.children.3.fields" => [ "value", "value" ]
@@ -142,8 +140,7 @@ describe Mongoid::Atomic::Positionable do
142
140
  "$set" => {
143
141
  "field" => "value",
144
142
  "children.0.field" => "value",
145
- "children.0.children.1.children.3.field" => "value",
146
- "children.0.children.1.children.3.field" => "value",
143
+ "children.0.children.1.children.3.field" => "value"
147
144
  },
148
145
  "$pushAll" => {
149
146
  "children.0.children.1.children.3.fields" => [ "value", "value" ]
@@ -172,8 +169,7 @@ describe Mongoid::Atomic::Positionable do
172
169
  "$set" => {
173
170
  "field" => "value",
174
171
  "children.$.field" => "value",
175
- "children.0.children.$.children.3.field" => "value",
176
- "children.0.children.$.children.3.field" => "value",
172
+ "children.0.children.$.children.3.field" => "value"
177
173
  },
178
174
  "$pushAll" => {
179
175
  "children.0.children.$.children.3.fields" => [ "value", "value" ]
@@ -206,8 +202,7 @@ describe Mongoid::Atomic::Positionable do
206
202
  "$set" => {
207
203
  "field" => "value",
208
204
  "children.$.field" => "value",
209
- "children.0.children.1.children.$.field" => "value",
210
- "children.0.children.1.children.$.field" => "value",
205
+ "children.0.children.1.children.$.field" => "value"
211
206
  },
212
207
  "$pushAll" => {
213
208
  "children.0.children.1.children.$.fields" => [ "value", "value" ]
@@ -887,6 +887,21 @@ describe Mongoid::Attributes do
887
887
  end
888
888
  end
889
889
  end
890
+
891
+ context "when attribute has an aliased name" do
892
+
893
+ let(:person) do
894
+ Person.new
895
+ end
896
+
897
+ before(:each) do
898
+ person.write_attribute(:t, "aliased field to test")
899
+ end
900
+
901
+ it "returns the value of the aliased field" do
902
+ expect(person.read_attribute(:test)).to eq("aliased field to test")
903
+ end
904
+ end
890
905
  end
891
906
 
892
907
  describe "#read_attribute_before_type_cast" do
@@ -108,6 +108,38 @@ describe Mongoid::Contextual::Aggregable::Mongo do
108
108
  aggregates["sum"].should eq(1000)
109
109
  end
110
110
  end
111
+
112
+ context "when only 1 document is emitted because of sorting, skip and limit" do
113
+
114
+ let(:criteria) do
115
+ Band.desc(:name).skip(1).limit(1)
116
+ end
117
+
118
+ let(:aggregates) do
119
+ context.aggregates(:likes)
120
+ end
121
+
122
+ it "returns an avg" do
123
+ expect(aggregates["avg"]).to eq(1000)
124
+ end
125
+
126
+ it "returns a count of documents with that field" do
127
+ expect(aggregates["count"]).to eq(1)
128
+ end
129
+
130
+ it "returns a max" do
131
+ expect(aggregates["max"]).to eq(1000)
132
+ end
133
+
134
+ it "returns a min" do
135
+ expect(aggregates["min"]).to eq(1000)
136
+ end
137
+
138
+ it "returns a sum" do
139
+ expect(aggregates["sum"]).to eq(1000)
140
+ end
141
+ end
142
+
111
143
  end
112
144
 
113
145
  context "when the field does not exist" do
@@ -100,7 +100,7 @@ describe Mongoid::Contextual::Atomic do
100
100
  end
101
101
 
102
102
  it "does not error on non initialized fields" do
103
- smiths.reload.likes.should be_nil
103
+ smiths.reload.likes.should eq(0)
104
104
  end
105
105
  end
106
106
 
@@ -115,7 +115,7 @@ describe Mongoid::Contextual::Atomic do
115
115
  end
116
116
 
117
117
  it "does not error on non initialized fields" do
118
- smiths.reload.likes.should be_nil
118
+ smiths.reload.likes.should eq(13)
119
119
  end
120
120
  end
121
121
 
@@ -130,10 +130,10 @@ describe Mongoid::Contextual::Atomic do
130
130
  end
131
131
 
132
132
  it "does not error on non initialized fields" do
133
- smiths.reload.likes.should be_nil
133
+ smiths.reload.likes.should eq(10)
134
134
  end
135
135
  end
136
- end
136
+ end if mongodb_version > "2.5"
137
137
 
138
138
  describe "#inc" do
139
139
 
@@ -4726,7 +4726,7 @@ describe Mongoid::Criteria do
4726
4726
  end
4727
4727
 
4728
4728
  it "executes the criteria while properly giving the hint to Mongo" do
4729
- expect { criteria.to_ary }.to raise_error(Moped::Errors::QueryFailure, %r{failed with error 10113: "bad hint"})
4729
+ expect { criteria.to_ary }.to raise_error(Moped::Errors::QueryFailure)
4730
4730
  end
4731
4731
  end
4732
4732
 
@@ -4741,7 +4741,7 @@ describe Mongoid::Criteria do
4741
4741
  end
4742
4742
 
4743
4743
  it "executes the criteria while properly giving the hint to Mongo" do
4744
- expect { criteria.to_ary }.to raise_error(Moped::Errors::QueryFailure, %r{failed with error 10113: "bad hint"})
4744
+ expect { criteria.to_ary }.to raise_error(Moped::Errors::QueryFailure)
4745
4745
  end
4746
4746
  end
4747
4747
 
@@ -21,5 +21,26 @@ describe Mongoid::Matchers::Ne do
21
21
  matcher.matches?("$ne" => "first").should be_false
22
22
  end
23
23
  end
24
+
25
+ context "when the value is an array" do
26
+
27
+ let(:array_matcher) do
28
+ described_class.new([ "first" ])
29
+ end
30
+
31
+ context "when the value is in the array" do
32
+
33
+ it "returns false" do
34
+ expect(array_matcher.matches?("$ne" => "first")).to be false
35
+ end
36
+ end
37
+
38
+ context "when the value is not in the array" do
39
+
40
+ it "returns true" do
41
+ expect(array_matcher.matches?("$ne" => "second")).to be true
42
+ end
43
+ end
44
+ end
24
45
  end
25
46
  end
@@ -84,6 +84,21 @@ describe "Rails::Mongoid" do
84
84
  indexes
85
85
  end
86
86
  end
87
+
88
+ context "when index is defined on self-embedded (cyclic) model" do
89
+ let(:klass) do
90
+ Draft
91
+ end
92
+
93
+ let(:model_paths) do
94
+ [ "spec/app/models/draft.rb" ]
95
+ end
96
+
97
+ it "creates the indexes for the models" do
98
+ klass.should_receive(:create_indexes).once
99
+ indexes
100
+ end
101
+ end
87
102
  end
88
103
 
89
104
  describe ".remove_indexes" do
@@ -45,6 +45,11 @@ def mongohq_connectable?
45
45
  ENV["MONGOHQ_REPL_PASS"].present?
46
46
  end
47
47
 
48
+ def mongodb_version
49
+ session = Mongoid::Sessions.default
50
+ session.command(buildinfo: 1)["version"]
51
+ end
52
+
48
53
  # Set the database that the spec suite connects to.
49
54
  Mongoid.configure do |config|
50
55
  config.load_configuration(CONFIG)
@@ -91,3 +96,5 @@ end
91
96
  ActiveSupport::Inflector.inflections do |inflect|
92
97
  inflect.singular("address_components", "address_component")
93
98
  end
99
+
100
+ I18n.enforce_available_locales = false
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.6
4
+ version: 3.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-02 00:00:00.000000000 Z
11
+ date: 2015-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: tzinfo
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.3.29
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.3.29
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: moped
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.4'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.4'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: origin
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.0'
69
69
  description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written
@@ -74,27 +74,33 @@ executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
+ - CHANGELOG.md
78
+ - LICENSE
79
+ - README.md
80
+ - Rakefile
77
81
  - lib/config/locales/en.yml
82
+ - lib/mongoid.rb
83
+ - lib/mongoid/atomic.rb
78
84
  - lib/mongoid/atomic/modifiers.rb
85
+ - lib/mongoid/atomic/paths.rb
86
+ - lib/mongoid/atomic/paths/embedded.rb
79
87
  - lib/mongoid/atomic/paths/embedded/many.rb
80
88
  - lib/mongoid/atomic/paths/embedded/one.rb
81
- - lib/mongoid/atomic/paths/embedded.rb
82
89
  - lib/mongoid/atomic/paths/root.rb
83
- - lib/mongoid/atomic/paths.rb
84
90
  - lib/mongoid/atomic/positionable.rb
85
- - lib/mongoid/atomic.rb
91
+ - lib/mongoid/attributes.rb
86
92
  - lib/mongoid/attributes/processing.rb
87
93
  - lib/mongoid/attributes/readonly.rb
88
- - lib/mongoid/attributes.rb
89
94
  - lib/mongoid/callbacks.rb
90
95
  - lib/mongoid/components.rb
96
+ - lib/mongoid/config.rb
91
97
  - lib/mongoid/config/environment.rb
92
98
  - lib/mongoid/config/inflections.rb
93
99
  - lib/mongoid/config/options.rb
100
+ - lib/mongoid/config/validators.rb
94
101
  - lib/mongoid/config/validators/option.rb
95
102
  - lib/mongoid/config/validators/session.rb
96
- - lib/mongoid/config/validators.rb
97
- - lib/mongoid/config.rb
103
+ - lib/mongoid/contextual.rb
98
104
  - lib/mongoid/contextual/aggregable/memory.rb
99
105
  - lib/mongoid/contextual/aggregable/mongo.rb
100
106
  - lib/mongoid/contextual/atomic.rb
@@ -106,9 +112,9 @@ files:
106
112
  - lib/mongoid/contextual/memory.rb
107
113
  - lib/mongoid/contextual/mongo.rb
108
114
  - lib/mongoid/contextual/queryable.rb
109
- - lib/mongoid/contextual.rb
110
115
  - lib/mongoid/copyable.rb
111
116
  - lib/mongoid/criteria.rb
117
+ - lib/mongoid/criteria/#findable.rb#
112
118
  - lib/mongoid/criterion/findable.rb
113
119
  - lib/mongoid/criterion/inspection.rb
114
120
  - lib/mongoid/criterion/marshalable.rb
@@ -117,6 +123,7 @@ files:
117
123
  - lib/mongoid/dirty.rb
118
124
  - lib/mongoid/document.rb
119
125
  - lib/mongoid/equality.rb
126
+ - lib/mongoid/errors.rb
120
127
  - lib/mongoid/errors/ambiguous_relationship.rb
121
128
  - lib/mongoid/errors/callback.rb
122
129
  - lib/mongoid/errors/delete_restriction.rb
@@ -157,8 +164,8 @@ files:
157
164
  - lib/mongoid/errors/unsupported_javascript.rb
158
165
  - lib/mongoid/errors/validations.rb
159
166
  - lib/mongoid/errors/versioning_not_on_root.rb
160
- - lib/mongoid/errors.rb
161
167
  - lib/mongoid/evolvable.rb
168
+ - lib/mongoid/extensions.rb
162
169
  - lib/mongoid/extensions/array.rb
163
170
  - lib/mongoid/extensions/big_decimal.rb
164
171
  - lib/mongoid/extensions/boolean.rb
@@ -180,22 +187,22 @@ files:
180
187
  - lib/mongoid/extensions/time.rb
181
188
  - lib/mongoid/extensions/time_with_zone.rb
182
189
  - lib/mongoid/extensions/true_class.rb
183
- - lib/mongoid/extensions.rb
184
190
  - lib/mongoid/factory.rb
191
+ - lib/mongoid/fields.rb
185
192
  - lib/mongoid/fields/foreign_key.rb
186
193
  - lib/mongoid/fields/localized.rb
187
194
  - lib/mongoid/fields/standard.rb
188
- - lib/mongoid/fields/validators/macro.rb
189
195
  - lib/mongoid/fields/validators.rb
190
- - lib/mongoid/fields.rb
196
+ - lib/mongoid/fields/validators/macro.rb
191
197
  - lib/mongoid/finders.rb
192
198
  - lib/mongoid/hierarchy.rb
193
199
  - lib/mongoid/identity_map.rb
194
- - lib/mongoid/indexes/validators/options.rb
195
200
  - lib/mongoid/indexes.rb
201
+ - lib/mongoid/indexes/validators/options.rb
196
202
  - lib/mongoid/inspection.rb
197
203
  - lib/mongoid/json.rb
198
204
  - lib/mongoid/loggable.rb
205
+ - lib/mongoid/matchers.rb
199
206
  - lib/mongoid/matchers/all.rb
200
207
  - lib/mongoid/matchers/and.rb
201
208
  - lib/mongoid/matchers/default.rb
@@ -210,11 +217,12 @@ files:
210
217
  - lib/mongoid/matchers/or.rb
211
218
  - lib/mongoid/matchers/size.rb
212
219
  - lib/mongoid/matchers/strategies.rb
213
- - lib/mongoid/matchers.rb
214
220
  - lib/mongoid/multi_parameter_attributes.rb
215
221
  - lib/mongoid/nested_attributes.rb
216
222
  - lib/mongoid/observer.rb
217
223
  - lib/mongoid/paranoia.rb
224
+ - lib/mongoid/persistence.rb
225
+ - lib/mongoid/persistence/atomic.rb
218
226
  - lib/mongoid/persistence/atomic/add_to_set.rb
219
227
  - lib/mongoid/persistence/atomic/bit.rb
220
228
  - lib/mongoid/persistence/atomic/inc.rb
@@ -227,25 +235,25 @@ files:
227
235
  - lib/mongoid/persistence/atomic/rename.rb
228
236
  - lib/mongoid/persistence/atomic/sets.rb
229
237
  - lib/mongoid/persistence/atomic/unset.rb
230
- - lib/mongoid/persistence/atomic.rb
231
238
  - lib/mongoid/persistence/deletion.rb
232
239
  - lib/mongoid/persistence/insertion.rb
233
240
  - lib/mongoid/persistence/modification.rb
241
+ - lib/mongoid/persistence/operations.rb
234
242
  - lib/mongoid/persistence/operations/embedded/insert.rb
235
243
  - lib/mongoid/persistence/operations/embedded/remove.rb
236
244
  - lib/mongoid/persistence/operations/insert.rb
237
245
  - lib/mongoid/persistence/operations/remove.rb
238
246
  - lib/mongoid/persistence/operations/update.rb
239
247
  - lib/mongoid/persistence/operations/upsert.rb
240
- - lib/mongoid/persistence/operations.rb
241
248
  - lib/mongoid/persistence/upsertion.rb
242
- - lib/mongoid/persistence.rb
243
249
  - lib/mongoid/railtie.rb
244
250
  - lib/mongoid/railties/database.rake
245
251
  - lib/mongoid/railties/document.rb
252
+ - lib/mongoid/relations.rb
246
253
  - lib/mongoid/relations/accessors.rb
247
254
  - lib/mongoid/relations/auto_save.rb
248
255
  - lib/mongoid/relations/binding.rb
256
+ - lib/mongoid/relations/bindings.rb
249
257
  - lib/mongoid/relations/bindings/embedded/in.rb
250
258
  - lib/mongoid/relations/bindings/embedded/many.rb
251
259
  - lib/mongoid/relations/bindings/embedded/one.rb
@@ -253,8 +261,8 @@ files:
253
261
  - lib/mongoid/relations/bindings/referenced/many.rb
254
262
  - lib/mongoid/relations/bindings/referenced/many_to_many.rb
255
263
  - lib/mongoid/relations/bindings/referenced/one.rb
256
- - lib/mongoid/relations/bindings.rb
257
264
  - lib/mongoid/relations/builder.rb
265
+ - lib/mongoid/relations/builders.rb
258
266
  - lib/mongoid/relations/builders/embedded/in.rb
259
267
  - lib/mongoid/relations/builders/embedded/many.rb
260
268
  - lib/mongoid/relations/builders/embedded/one.rb
@@ -264,12 +272,11 @@ files:
264
272
  - lib/mongoid/relations/builders/referenced/many.rb
265
273
  - lib/mongoid/relations/builders/referenced/many_to_many.rb
266
274
  - lib/mongoid/relations/builders/referenced/one.rb
267
- - lib/mongoid/relations/builders.rb
275
+ - lib/mongoid/relations/cascading.rb
268
276
  - lib/mongoid/relations/cascading/delete.rb
269
277
  - lib/mongoid/relations/cascading/destroy.rb
270
278
  - lib/mongoid/relations/cascading/nullify.rb
271
279
  - lib/mongoid/relations/cascading/restrict.rb
272
- - lib/mongoid/relations/cascading.rb
273
280
  - lib/mongoid/relations/constraint.rb
274
281
  - lib/mongoid/relations/conversions.rb
275
282
  - lib/mongoid/relations/counter_cache.rb
@@ -293,30 +300,30 @@ files:
293
300
  - lib/mongoid/relations/referenced/one.rb
294
301
  - lib/mongoid/relations/reflections.rb
295
302
  - lib/mongoid/relations/synchronization.rb
296
- - lib/mongoid/relations/targets/enumerable.rb
297
303
  - lib/mongoid/relations/targets.rb
304
+ - lib/mongoid/relations/targets/enumerable.rb
298
305
  - lib/mongoid/relations/touchable.rb
299
- - lib/mongoid/relations.rb
300
306
  - lib/mongoid/reloading.rb
301
307
  - lib/mongoid/scoping.rb
302
308
  - lib/mongoid/serialization.rb
309
+ - lib/mongoid/sessions.rb
303
310
  - lib/mongoid/sessions/factory.rb
304
311
  - lib/mongoid/sessions/mongo_uri.rb
305
- - lib/mongoid/sessions/validators/storage.rb
306
312
  - lib/mongoid/sessions/validators.rb
307
- - lib/mongoid/sessions.rb
313
+ - lib/mongoid/sessions/validators/storage.rb
308
314
  - lib/mongoid/sharding.rb
309
315
  - lib/mongoid/state.rb
310
- - lib/mongoid/threaded/lifecycle.rb
311
316
  - lib/mongoid/threaded.rb
312
- - lib/mongoid/timestamps/created/short.rb
317
+ - lib/mongoid/threaded/lifecycle.rb
318
+ - lib/mongoid/timestamps.rb
313
319
  - lib/mongoid/timestamps/created.rb
320
+ - lib/mongoid/timestamps/created/short.rb
314
321
  - lib/mongoid/timestamps/short.rb
315
322
  - lib/mongoid/timestamps/timeless.rb
316
- - lib/mongoid/timestamps/updated/short.rb
317
323
  - lib/mongoid/timestamps/updated.rb
318
- - lib/mongoid/timestamps.rb
324
+ - lib/mongoid/timestamps/updated/short.rb
319
325
  - lib/mongoid/unit_of_work.rb
326
+ - lib/mongoid/validations.rb
320
327
  - lib/mongoid/validations/associated.rb
321
328
  - lib/mongoid/validations/format.rb
322
329
  - lib/mongoid/validations/length.rb
@@ -325,12 +332,10 @@ files:
325
332
  - lib/mongoid/validations/presence.rb
326
333
  - lib/mongoid/validations/queryable.rb
327
334
  - lib/mongoid/validations/uniqueness.rb
328
- - lib/mongoid/validations.rb
329
335
  - lib/mongoid/version.rb
330
336
  - lib/mongoid/versioning.rb
331
- - lib/mongoid.rb
332
- - lib/rack/mongoid/middleware/identity_map.rb
333
337
  - lib/rack/mongoid.rb
338
+ - lib/rack/mongoid/middleware/identity_map.rb
334
339
  - lib/rails/generators/mongoid/config/config_generator.rb
335
340
  - lib/rails/generators/mongoid/config/templates/mongoid.yml
336
341
  - lib/rails/generators/mongoid/model/model_generator.rb
@@ -340,10 +345,6 @@ files:
340
345
  - lib/rails/generators/mongoid_generator.rb
341
346
  - lib/rails/mongoid.rb
342
347
  - lib/support/ruby_version.rb
343
- - CHANGELOG.md
344
- - LICENSE
345
- - README.md
346
- - Rakefile
347
348
  - spec/app/models/account.rb
348
349
  - spec/app/models/acolyte.rb
349
350
  - spec/app/models/actor.rb
@@ -401,6 +402,7 @@ files:
401
402
  - spec/app/models/doctor.rb
402
403
  - spec/app/models/dog.rb
403
404
  - spec/app/models/dokument.rb
405
+ - spec/app/models/draft.rb
404
406
  - spec/app/models/driver.rb
405
407
  - spec/app/models/drug.rb
406
408
  - spec/app/models/email.rb
@@ -533,6 +535,7 @@ files:
533
535
  - spec/app/models/word_origin.rb
534
536
  - spec/app/models/writer.rb
535
537
  - spec/config/mongoid.yml
538
+ - spec/mongoid/#atomic_spec.rb#
536
539
  - spec/mongoid/atomic/modifiers_spec.rb
537
540
  - spec/mongoid/atomic/paths/embedded/many_spec.rb
538
541
  - spec/mongoid/atomic/paths/embedded/one_spec.rb
@@ -764,17 +767,17 @@ require_paths:
764
767
  - lib
765
768
  required_ruby_version: !ruby/object:Gem::Requirement
766
769
  requirements:
767
- - - '>='
770
+ - - ">="
768
771
  - !ruby/object:Gem::Version
769
772
  version: '1.9'
770
773
  required_rubygems_version: !ruby/object:Gem::Requirement
771
774
  requirements:
772
- - - '>='
775
+ - - ">="
773
776
  - !ruby/object:Gem::Version
774
777
  version: 1.3.6
775
778
  requirements: []
776
779
  rubyforge_project: mongoid
777
- rubygems_version: 2.1.11
780
+ rubygems_version: 2.4.5
778
781
  signing_key:
779
782
  specification_version: 4
780
783
  summary: Elegant Persistance in Ruby for MongoDB.
@@ -836,6 +839,7 @@ test_files:
836
839
  - spec/app/models/doctor.rb
837
840
  - spec/app/models/dog.rb
838
841
  - spec/app/models/dokument.rb
842
+ - spec/app/models/draft.rb
839
843
  - spec/app/models/driver.rb
840
844
  - spec/app/models/drug.rb
841
845
  - spec/app/models/email.rb
@@ -968,6 +972,7 @@ test_files:
968
972
  - spec/app/models/word_origin.rb
969
973
  - spec/app/models/writer.rb
970
974
  - spec/config/mongoid.yml
975
+ - spec/mongoid/#atomic_spec.rb#
971
976
  - spec/mongoid/atomic/modifiers_spec.rb
972
977
  - spec/mongoid/atomic/paths/embedded/many_spec.rb
973
978
  - spec/mongoid/atomic/paths/embedded/one_spec.rb