mongoid 4.0.0.beta2 → 4.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -3
- data/lib/mongoid/composable.rb +3 -1
- data/lib/mongoid/fields/validators/macro.rb +4 -2
- data/lib/mongoid/persistable.rb +3 -0
- data/lib/mongoid/relations/touchable.rb +1 -1
- data/lib/mongoid/version.rb +1 -1
- data/spec/mongoid/attributes/readonly_spec.rb +42 -2
- data/spec/mongoid/contextual/atomic_spec.rb +12 -6
- data/spec/mongoid/fields_spec.rb +7 -5
- data/spec/spec_helper.rb +5 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33fe9286d3ba938ede032903cc4a474975d6f7fe
|
4
|
+
data.tar.gz: 1d14ddf90e7ed9c9fc67cd0e8f609ce2e1e87f23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 267e9b0f0cf0a568200dd31043025f54fb75773f146d62a9c6fa5ec1561f6e9ae091608c39fe3ee6ce9bf568e681eb623799460c2d57f50a6b737a76f2e2d4a0
|
7
|
+
data.tar.gz: 2fcb46e0a9ab3ebca70be65d93017f96bfb3bd44da5b9d3cf1e517e6bd622ed2028a6ef16ed00c0212ffffcabeafbf061c4c48dbe60307f4aef22fc27e34a9c6
|
data/CHANGELOG.md
CHANGED
@@ -185,9 +185,6 @@ For instructions on upgrading to newer versions, visit
|
|
185
185
|
* \#2956 Caching on queries now only happens when `cache` is specifically
|
186
186
|
called. (Arthur Neves)
|
187
187
|
|
188
|
-
* \#2898 Dirty attribute methods now properly handle field aliases.
|
189
|
-
(Niels Ganser)
|
190
|
-
|
191
188
|
* \#2659 `Mongoid::Railtie` now properly uses only one initializer and
|
192
189
|
the name has changed to `mongoid.load-config`.
|
193
190
|
|
@@ -223,6 +220,9 @@ For instructions on upgrading to newer versions, visit
|
|
223
220
|
apply the default scope to the document, if the scope is not complex.
|
224
221
|
|
225
222
|
* \#2200 Mass assignment security now mirrors Rails 4's behavior.
|
223
|
+
`without_protection` option was also removed.
|
224
|
+
`attr_accessible` class method was removed.
|
225
|
+
Mongoid and Strong parameters should work fine for mass assignment protection.
|
226
226
|
|
227
227
|
* `delete_all` and `destroy_all` no longer take a `:conditions` hash but
|
228
228
|
just the raw attributes.
|
@@ -345,6 +345,15 @@ For instructions on upgrading to newer versions, visit
|
|
345
345
|
|
346
346
|
### Resolved Issues
|
347
347
|
|
348
|
+
* \#2898 Dirty attribute methods now properly handle field aliases.
|
349
|
+
(Niels Ganser)
|
350
|
+
|
351
|
+
* \#3620 Add ActiveModel module instance methods to prohibited_methods list.
|
352
|
+
(Arthur Neves)
|
353
|
+
|
354
|
+
* \#3610 Don't allow atomic operations on read-only attributes
|
355
|
+
(Frederico Araujo)
|
356
|
+
|
348
357
|
* \#3619 Don't validate documents that are flagged for destruction.
|
349
358
|
(Christopher J. Bottaro)
|
350
359
|
|
data/lib/mongoid/composable.rb
CHANGED
@@ -51,8 +51,10 @@ module Mongoid
|
|
51
51
|
#
|
52
52
|
# @since 3.0.0
|
53
53
|
def validate_name(klass, name, options)
|
54
|
-
|
55
|
-
|
54
|
+
[name, "#{name}?".to_sym, "#{name}=".to_sym].each do |n|
|
55
|
+
if Mongoid.destructive_fields.include?(n)
|
56
|
+
raise Errors::InvalidField.new(klass, n)
|
57
|
+
end
|
56
58
|
end
|
57
59
|
|
58
60
|
if !options[:overwrite] && klass.fields.keys.include?(name.to_s)
|
data/lib/mongoid/persistable.rb
CHANGED
@@ -165,6 +165,9 @@ module Mongoid
|
|
165
165
|
# @since 4.0.0
|
166
166
|
def process_atomic_operations(operations)
|
167
167
|
operations.each do |field, value|
|
168
|
+
unless attribute_writable?(field)
|
169
|
+
raise Errors::ReadonlyAttribute.new(field, value)
|
170
|
+
end
|
168
171
|
normalized = database_field_name(field)
|
169
172
|
yield(normalized, value)
|
170
173
|
remove_change(normalized)
|
@@ -31,7 +31,7 @@ module Mongoid
|
|
31
31
|
touches = touch_atomic_updates(field)
|
32
32
|
unless touches.empty?
|
33
33
|
selector = atomic_selector
|
34
|
-
_root.collection.
|
34
|
+
_root.collection.where(selector).update(positionally(selector, touches))
|
35
35
|
end
|
36
36
|
run_callbacks(:touch)
|
37
37
|
true
|
data/lib/mongoid/version.rb
CHANGED
@@ -60,11 +60,11 @@ describe Mongoid::Attributes::Readonly do
|
|
60
60
|
context "when updating an existing readonly field" do
|
61
61
|
|
62
62
|
before do
|
63
|
-
Person.attr_readonly :title, :terms
|
63
|
+
Person.attr_readonly :title, :terms, :score
|
64
64
|
end
|
65
65
|
|
66
66
|
let(:person) do
|
67
|
-
Person.create(title: "sir", terms: true)
|
67
|
+
Person.create(title: "sir", terms: true, score: 1)
|
68
68
|
end
|
69
69
|
|
70
70
|
context "when updating via the setter" do
|
@@ -83,6 +83,46 @@ describe Mongoid::Attributes::Readonly do
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
+
context "when updating via inc" do
|
87
|
+
|
88
|
+
context 'with single field operation' do
|
89
|
+
it "raises an error " do
|
90
|
+
expect {
|
91
|
+
person.inc(score: 1)
|
92
|
+
}.to raise_error(Mongoid::Errors::ReadonlyAttribute)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'with multiple fields operation' do
|
97
|
+
it "raises an error " do
|
98
|
+
expect {
|
99
|
+
person.inc(score: 1, age: 1)
|
100
|
+
}.to raise_error(Mongoid::Errors::ReadonlyAttribute)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "when updating via bit" do
|
106
|
+
|
107
|
+
context 'with single field operation' do
|
108
|
+
it "raises an error " do
|
109
|
+
expect {
|
110
|
+
person.bit(score: { or: 13 })
|
111
|
+
}.to raise_error(Mongoid::Errors::ReadonlyAttribute)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'with multiple fields operation' do
|
116
|
+
it "raises an error " do
|
117
|
+
expect {
|
118
|
+
person.bit(
|
119
|
+
age: { and: 13 }, score: { or: 13 }, inte: { and: 13, or: 10 }
|
120
|
+
)
|
121
|
+
}.to raise_error(Mongoid::Errors::ReadonlyAttribute)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
86
126
|
context "when updating via []=" do
|
87
127
|
|
88
128
|
before do
|
@@ -103,8 +103,10 @@ describe Mongoid::Contextual::Atomic do
|
|
103
103
|
expect(depeche_mode.reload.likes).to eq(12)
|
104
104
|
end
|
105
105
|
|
106
|
-
|
107
|
-
|
106
|
+
if mongodb_version > "2.5"
|
107
|
+
it "does not error on non initialized fields" do
|
108
|
+
expect(smiths.reload.likes).to eq(0)
|
109
|
+
end
|
108
110
|
end
|
109
111
|
end
|
110
112
|
|
@@ -118,8 +120,10 @@ describe Mongoid::Contextual::Atomic do
|
|
118
120
|
expect(depeche_mode.reload.likes).to eq(61)
|
119
121
|
end
|
120
122
|
|
121
|
-
|
122
|
-
|
123
|
+
if mongodb_version > "2.5"
|
124
|
+
it "does not error on non initialized fields" do
|
125
|
+
expect(smiths.reload.likes).to eq(13)
|
126
|
+
end
|
123
127
|
end
|
124
128
|
end
|
125
129
|
|
@@ -133,8 +137,10 @@ describe Mongoid::Contextual::Atomic do
|
|
133
137
|
expect(depeche_mode.reload.likes).to eq(14)
|
134
138
|
end
|
135
139
|
|
136
|
-
|
137
|
-
|
140
|
+
if mongodb_version > "2.5"
|
141
|
+
it "does not error on non initialized fields" do
|
142
|
+
expect(smiths.reload.likes).to eq(10)
|
143
|
+
end
|
138
144
|
end
|
139
145
|
end
|
140
146
|
end
|
data/spec/mongoid/fields_spec.rb
CHANGED
@@ -815,12 +815,14 @@ describe Mongoid::Fields do
|
|
815
815
|
|
816
816
|
context "when the field name conflicts with mongoid's internals" do
|
817
817
|
|
818
|
-
|
818
|
+
[:__metadata, :invalid].each do |meth|
|
819
|
+
context "when the field is named #{meth}" do
|
819
820
|
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
821
|
+
it "raises an error" do
|
822
|
+
expect {
|
823
|
+
Person.field(meth)
|
824
|
+
}.to raise_error(Mongoid::Errors::InvalidField)
|
825
|
+
end
|
824
826
|
end
|
825
827
|
end
|
826
828
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -62,6 +62,11 @@ def purge_database_alt!
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
def mongodb_version
|
66
|
+
session = Mongoid::Sessions.default
|
67
|
+
session.command(buildinfo: 1)["version"]
|
68
|
+
end
|
69
|
+
|
65
70
|
# Set the database that the spec suite connects to.
|
66
71
|
Mongoid.configure do |config|
|
67
72
|
config.load_configuration(CONFIG)
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.0.
|
4
|
+
version: 4.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Durran Jordan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-02 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: 4.0.0
|
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: 4.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 2.0.
|
47
|
+
version: 2.0.0.rc1
|
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
|
-
version: 2.0.
|
54
|
+
version: 2.0.0.rc1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: origin
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|