mongoid 3.1.5 → 3.1.6
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/lib/mongoid/components.rb +0 -1
- data/lib/mongoid/dirty.rb +0 -1
- data/lib/mongoid/extensions/hash.rb +12 -4
- data/lib/mongoid/hierarchy.rb +1 -0
- data/lib/mongoid/paranoia.rb +0 -1
- data/lib/mongoid/persistence.rb +5 -0
- data/lib/mongoid/persistence/deletion.rb +0 -1
- data/lib/mongoid/relations/embedded/batchable.rb +0 -1
- data/lib/mongoid/timestamps.rb +1 -1
- data/lib/mongoid/timestamps/created.rb +6 -2
- data/lib/mongoid/timestamps/timeless.rb +30 -8
- data/lib/mongoid/timestamps/updated.rb +10 -4
- data/lib/mongoid/version.rb +1 -1
- data/spec/app/models/definition.rb +1 -0
- data/spec/mongoid/contextual/mongo_spec.rb +20 -0
- data/spec/mongoid/fields_spec.rb +14 -0
- data/spec/mongoid/hierarchy_spec.rb +7 -0
- data/spec/mongoid/relations/referenced/many_spec.rb +19 -0
- data/spec/mongoid/timestamps/timeless_spec.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d24616c46c93a31777a37b97c93cca0b10df2625
|
4
|
+
data.tar.gz: 000fc93a80cfc7e296f305a1ddca2d77517578aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71d177604ae5df43f63a5f45b1fa68ea2bedf263009ca58406e23ef6c3fdbe09f0b76bdf5e4c70a9612c515f3aa2fca8ae384d62ede1e86629f788905822e483
|
7
|
+
data.tar.gz: f840e9a8796efaa27b3536c95270c9e5abcbe233718a546095cc09671fd1d6edb8c7d16b55505ad33e1737ab610fb422b04318d0486c37841a2b9c495959ca2f
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,19 @@
|
|
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.6
|
7
|
+
|
8
|
+
### Resolved Issues
|
9
|
+
|
10
|
+
* \#3337 Ensure localized fields map is cloned with inheritance.
|
11
|
+
|
12
|
+
* \#3262 Fixed atomic array operations on HABTM foreign key fields from turning
|
13
|
+
single elements into arrays.
|
14
|
+
|
15
|
+
* \#3282 Fixed .timeless option to use a thread local instead of a class attribute.
|
16
|
+
Also remove the timeless methods from all docs, and only add to timestamps docs.
|
17
|
+
(Arthur Neves)
|
18
|
+
|
6
19
|
## 3.1.5
|
7
20
|
|
8
21
|
### Resolved Issues
|
data/lib/mongoid/components.rb
CHANGED
data/lib/mongoid/dirty.rb
CHANGED
@@ -40,11 +40,11 @@ module Mongoid
|
|
40
40
|
each_pair do |key, value|
|
41
41
|
if key =~ /\$/
|
42
42
|
value.each_pair do |_key, _value|
|
43
|
-
value[_key] = mongoize_for(klass, _key, _value)
|
43
|
+
value[_key] = mongoize_for(key, klass, _key, _value)
|
44
44
|
end
|
45
45
|
(consolidated[key] ||= {}).merge!(value)
|
46
46
|
else
|
47
|
-
(consolidated["$set"] ||= {}).merge!(key => mongoize_for(klass, key, value))
|
47
|
+
(consolidated["$set"] ||= {}).merge!(key => mongoize_for(key, klass, key, value))
|
48
48
|
end
|
49
49
|
end
|
50
50
|
consolidated
|
@@ -166,9 +166,17 @@ module Mongoid
|
|
166
166
|
# @return [ Object ] The mongoized value.
|
167
167
|
#
|
168
168
|
# @since 3.1.0
|
169
|
-
def mongoize_for(klass, key, value)
|
169
|
+
def mongoize_for(operator, klass, key, value)
|
170
170
|
field = klass.fields[key.to_s]
|
171
|
-
|
171
|
+
if field
|
172
|
+
val = field.mongoize(value)
|
173
|
+
if Mongoid::Persistence::LIST_OPERATIONS.include?(operator) && field.resizable?
|
174
|
+
val = val.first if !value.is_a?(Array)
|
175
|
+
end
|
176
|
+
val
|
177
|
+
else
|
178
|
+
value
|
179
|
+
end
|
172
180
|
end
|
173
181
|
|
174
182
|
module ClassMethods
|
data/lib/mongoid/hierarchy.rb
CHANGED
@@ -169,6 +169,7 @@ module Mongoid
|
|
169
169
|
super
|
170
170
|
@_type = nil
|
171
171
|
subclass.aliased_fields = aliased_fields.dup
|
172
|
+
subclass.localized_fields = localized_fields.dup
|
172
173
|
subclass.fields = fields.dup
|
173
174
|
subclass.pre_processed_defaults = pre_processed_defaults.dup
|
174
175
|
subclass.post_processed_defaults = post_processed_defaults.dup
|
data/lib/mongoid/paranoia.rb
CHANGED
data/lib/mongoid/persistence.rb
CHANGED
@@ -21,6 +21,11 @@ module Mongoid
|
|
21
21
|
include Atomic
|
22
22
|
include Mongoid::Atomic::Positionable
|
23
23
|
|
24
|
+
# The atomic operations that deal with arrays or sets in the db.
|
25
|
+
#
|
26
|
+
# @since 4.0.0
|
27
|
+
LIST_OPERATIONS = [ "$addToSet", "$push", "$pull", "$pullAll" ].freeze
|
28
|
+
|
24
29
|
# Remove the document from the database with callbacks.
|
25
30
|
#
|
26
31
|
# @example Destroy a document.
|
data/lib/mongoid/timestamps.rb
CHANGED
@@ -9,8 +9,10 @@ module Mongoid
|
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
|
11
11
|
included do
|
12
|
+
include Mongoid::Timestamps::Timeless
|
13
|
+
|
12
14
|
field :created_at, type: Time
|
13
|
-
set_callback :create, :before, :set_created_at
|
15
|
+
set_callback :create, :before, :set_created_at
|
14
16
|
end
|
15
17
|
|
16
18
|
# Update the created_at field on the Document to the current time. This is
|
@@ -19,11 +21,13 @@ module Mongoid
|
|
19
21
|
# @example Set the created at time.
|
20
22
|
# person.set_created_at
|
21
23
|
def set_created_at
|
22
|
-
if !created_at
|
24
|
+
if !timeless? && !created_at
|
23
25
|
time = Time.now.utc
|
24
26
|
self.updated_at = time if is_a?(Updated) && !updated_at_changed?
|
25
27
|
self.created_at = time
|
26
28
|
end
|
29
|
+
|
30
|
+
self.class.clear_timeless_option
|
27
31
|
end
|
28
32
|
end
|
29
33
|
end
|
@@ -7,11 +7,6 @@ module Mongoid
|
|
7
7
|
module Timeless
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
|
-
included do
|
11
|
-
class_attribute :timestamping
|
12
|
-
self.timestamping = true
|
13
|
-
end
|
14
|
-
|
15
10
|
# Clears out the timeless option.
|
16
11
|
#
|
17
12
|
# @example Clear the timeless option.
|
@@ -21,7 +16,7 @@ module Mongoid
|
|
21
16
|
#
|
22
17
|
# @since 3.1.4
|
23
18
|
def clear_timeless_option
|
24
|
-
self.class.
|
19
|
+
self.class.clear_timeless_option
|
25
20
|
end
|
26
21
|
|
27
22
|
# Begin an execution that should skip timestamping.
|
@@ -33,10 +28,22 @@ module Mongoid
|
|
33
28
|
#
|
34
29
|
# @since 2.3.0
|
35
30
|
def timeless
|
36
|
-
self.class.
|
31
|
+
self.class.timeless
|
37
32
|
self
|
38
33
|
end
|
39
34
|
|
35
|
+
def timeless?
|
36
|
+
self.class.timeless?
|
37
|
+
end
|
38
|
+
|
39
|
+
class << self
|
40
|
+
|
41
|
+
def timeless_table
|
42
|
+
Thread.current['[mongoid]:timeless'] ||= Hash.new
|
43
|
+
end
|
44
|
+
delegate :[]=, :[], to: :timeless_table
|
45
|
+
end
|
46
|
+
|
40
47
|
private
|
41
48
|
|
42
49
|
module ClassMethods
|
@@ -50,9 +57,24 @@ module Mongoid
|
|
50
57
|
#
|
51
58
|
# @since 2.3.0
|
52
59
|
def timeless
|
53
|
-
|
60
|
+
counter = 0
|
61
|
+
counter += 1 if self < Mongoid::Timestamps::Created
|
62
|
+
counter += 1 if self < Mongoid::Timestamps::Updated
|
63
|
+
Timeless[name] = counter
|
54
64
|
self
|
55
65
|
end
|
66
|
+
|
67
|
+
def clear_timeless_option
|
68
|
+
if counter = Timeless[name]
|
69
|
+
counter -= 1
|
70
|
+
Timeless[name] = (counter == 0) ? nil : counter
|
71
|
+
end
|
72
|
+
true
|
73
|
+
end
|
74
|
+
|
75
|
+
def timeless?
|
76
|
+
!!Timeless[name]
|
77
|
+
end
|
56
78
|
end
|
57
79
|
end
|
58
80
|
end
|
@@ -9,9 +9,11 @@ module Mongoid
|
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
|
11
11
|
included do
|
12
|
+
include Mongoid::Timestamps::Timeless
|
13
|
+
|
12
14
|
field :updated_at, type: Time
|
13
|
-
set_callback :create, :before, :set_updated_at
|
14
|
-
set_callback :update, :before, :set_updated_at
|
15
|
+
set_callback :create, :before, :set_updated_at
|
16
|
+
set_callback :update, :before, :set_updated_at
|
15
17
|
end
|
16
18
|
|
17
19
|
# Update the updated_at field on the Document to the current time.
|
@@ -20,7 +22,11 @@ module Mongoid
|
|
20
22
|
# @example Set the updated at time.
|
21
23
|
# person.set_updated_at
|
22
24
|
def set_updated_at
|
23
|
-
|
25
|
+
if able_to_set_updated_at?
|
26
|
+
self.updated_at = Time.now.utc unless updated_at_changed?
|
27
|
+
end
|
28
|
+
|
29
|
+
self.class.clear_timeless_option
|
24
30
|
end
|
25
31
|
|
26
32
|
# Is the updated timestamp able to be set?
|
@@ -32,7 +38,7 @@ module Mongoid
|
|
32
38
|
#
|
33
39
|
# @since 2.4.0
|
34
40
|
def able_to_set_updated_at?
|
35
|
-
!frozen? &&
|
41
|
+
!frozen? && !timeless? && (new_record? || changed?)
|
36
42
|
end
|
37
43
|
end
|
38
44
|
end
|
data/lib/mongoid/version.rb
CHANGED
@@ -1500,6 +1500,26 @@ describe Mongoid::Contextual::Mongo do
|
|
1500
1500
|
described_class.new(criteria)
|
1501
1501
|
end
|
1502
1502
|
|
1503
|
+
context "when adding an element to a HABTM set" do
|
1504
|
+
|
1505
|
+
let(:person) do
|
1506
|
+
Person.create
|
1507
|
+
end
|
1508
|
+
|
1509
|
+
let(:preference) do
|
1510
|
+
Preference.create
|
1511
|
+
end
|
1512
|
+
|
1513
|
+
before do
|
1514
|
+
Person.where(id: person.id).
|
1515
|
+
update("$addToSet" => { preference_ids: preference.id })
|
1516
|
+
end
|
1517
|
+
|
1518
|
+
it "adds a single element to the array" do
|
1519
|
+
expect(person.reload.preference_ids).to eq([ preference.id ])
|
1520
|
+
end
|
1521
|
+
end
|
1522
|
+
|
1503
1523
|
context "when providing attributes" do
|
1504
1524
|
|
1505
1525
|
context "when the attributes are of the correct type" do
|
data/spec/mongoid/fields_spec.rb
CHANGED
@@ -1250,4 +1250,18 @@ describe Mongoid::Fields do
|
|
1250
1250
|
end
|
1251
1251
|
end
|
1252
1252
|
end
|
1253
|
+
|
1254
|
+
context "when a localized field is a boolean" do
|
1255
|
+
|
1256
|
+
context "when the default is true" do
|
1257
|
+
|
1258
|
+
let(:definition) do
|
1259
|
+
Definition.new
|
1260
|
+
end
|
1261
|
+
|
1262
|
+
it "returns the proper predicate result" do
|
1263
|
+
expect(definition).to be_active
|
1264
|
+
end
|
1265
|
+
end
|
1266
|
+
end
|
1253
1267
|
end
|
@@ -100,6 +100,13 @@ describe Mongoid::Hierarchy do
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
+
describe "#inherited" do
|
104
|
+
|
105
|
+
it "duplicates the localized fields" do
|
106
|
+
expect(Actress.localized_fields).to_not equal(Actor.localized_fields)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
103
110
|
describe "#parentize" do
|
104
111
|
|
105
112
|
let(:address) do
|
@@ -18,6 +18,25 @@ describe Mongoid::Relations::Referenced::Many do
|
|
18
18
|
|
19
19
|
describe "##{method}" do
|
20
20
|
|
21
|
+
context "when providing the base class in child contructor" do
|
22
|
+
|
23
|
+
let(:person) do
|
24
|
+
Person.create
|
25
|
+
end
|
26
|
+
|
27
|
+
let!(:post) do
|
28
|
+
person.posts.send(method, Post.new(person: person))
|
29
|
+
end
|
30
|
+
|
31
|
+
it "only adds the relation once" do
|
32
|
+
expect(person.posts.size).to eq(1)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "only persists the relation once" do
|
36
|
+
expect(person.reload.posts.size).to eq(1)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
21
40
|
context "when the relations are not polymorphic" do
|
22
41
|
|
23
42
|
context "when the parent is a new record" do
|
@@ -81,7 +81,7 @@ describe Mongoid::Timestamps::Timeless do
|
|
81
81
|
end
|
82
82
|
|
83
83
|
it "clears out the timeless option after save" do
|
84
|
-
expect(document).
|
84
|
+
expect(document).to_not be_timeless
|
85
85
|
end
|
86
86
|
|
87
87
|
context "when subsequently persisting" do
|
@@ -111,7 +111,7 @@ describe Mongoid::Timestamps::Timeless do
|
|
111
111
|
end
|
112
112
|
|
113
113
|
it "clears out the timeless option after save" do
|
114
|
-
expect(document).
|
114
|
+
expect(document).to_not be_timeless
|
115
115
|
end
|
116
116
|
|
117
117
|
context "when subsequently persisting" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.6
|
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-
|
11
|
+
date: 2013-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -774,7 +774,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
774
774
|
version: 1.3.6
|
775
775
|
requirements: []
|
776
776
|
rubyforge_project: mongoid
|
777
|
-
rubygems_version: 2.
|
777
|
+
rubygems_version: 2.1.11
|
778
778
|
signing_key:
|
779
779
|
specification_version: 4
|
780
780
|
summary: Elegant Persistance in Ruby for MongoDB.
|