mongoid 5.1.3 → 5.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mongoid/attributes.rb +1 -1
- data/lib/mongoid/contextual/mongo.rb +1 -2
- data/lib/mongoid/copyable.rb +14 -3
- data/lib/mongoid/fields/localized.rb +3 -3
- data/lib/mongoid/persistable/settable.rb +4 -2
- data/lib/mongoid/version.rb +1 -1
- data/spec/mongoid/attributes_spec.rb +45 -0
- data/spec/mongoid/contextual/mongo_spec.rb +0 -5
- data/spec/mongoid/copyable_spec.rb +12 -1
- data/spec/mongoid/fields/localized_spec.rb +15 -0
- data/spec/mongoid/persistable/settable_spec.rb +29 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79c4a036b0cdf460779fe1d838cd9c47fefa997a
|
4
|
+
data.tar.gz: f9eccd20ec1cf43dc5696e9f28b66ac1511b92cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 373ef0d42a812e2bd55b9f0c84fb4c40ef0720821127ad615b9fe1f30a15273dbe68126bb0e5c4981af9fbb30f90c51ba0dfba2dfae7738db75e3d128398acee
|
7
|
+
data.tar.gz: ea57593ae912660e765caaa3effce3b3355944fb77859ad8d52166b8f6ab8a6b013f2d01380ebb513ec67b4606040f2cd912894459558c8f7bc305d50349d673
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/mongoid/attributes.rb
CHANGED
@@ -259,7 +259,7 @@ module Mongoid
|
|
259
259
|
if field && field.localized?
|
260
260
|
selection.key?("#{name}.#{::I18n.locale}")
|
261
261
|
else
|
262
|
-
selection.keys.collect { |k| k.partition('.').first }.include?(name)
|
262
|
+
selection.key?(name) || selection.keys.collect { |k| k.partition('.').first }.include?(name)
|
263
263
|
end
|
264
264
|
end
|
265
265
|
|
data/lib/mongoid/copyable.rb
CHANGED
@@ -45,7 +45,7 @@ module Mongoid
|
|
45
45
|
# @since 3.0.22
|
46
46
|
def clone_document
|
47
47
|
attrs = as_document.__deep_copy__
|
48
|
-
process_localized_attributes(attrs)
|
48
|
+
process_localized_attributes(self, attrs)
|
49
49
|
attrs
|
50
50
|
end
|
51
51
|
|
@@ -60,12 +60,23 @@ module Mongoid
|
|
60
60
|
# @param [ Hash ] attrs The attributes.
|
61
61
|
#
|
62
62
|
# @since 3.0.20
|
63
|
-
def process_localized_attributes(attrs)
|
64
|
-
localized_fields.keys.each do |name|
|
63
|
+
def process_localized_attributes(klass, attrs)
|
64
|
+
klass.localized_fields.keys.each do |name|
|
65
65
|
if value = attrs.delete(name)
|
66
66
|
attrs["#{name}_translations"] = value
|
67
67
|
end
|
68
68
|
end
|
69
|
+
klass.embedded_relations.each do |_, metadata|
|
70
|
+
next unless attrs.present? && attrs[metadata.key].present?
|
71
|
+
|
72
|
+
if metadata.macro == :embeds_many
|
73
|
+
attrs[metadata.key].each do |attr|
|
74
|
+
process_localized_attributes(metadata.klass, attr)
|
75
|
+
end
|
76
|
+
else
|
77
|
+
process_localized_attributes(metadata.klass, attrs[metadata.key])
|
78
|
+
end
|
79
|
+
end
|
69
80
|
end
|
70
81
|
end
|
71
82
|
end
|
@@ -77,10 +77,10 @@ module Mongoid
|
|
77
77
|
# @since 3.0.0
|
78
78
|
def lookup(object)
|
79
79
|
locale = ::I18n.locale
|
80
|
-
if
|
80
|
+
if value = object[locale.to_s]
|
81
|
+
value
|
82
|
+
elsif fallbacks? && ::I18n.respond_to?(:fallbacks)
|
81
83
|
object[::I18n.fallbacks[locale].map(&:to_s).find{ |loc| object.has_key?(loc) }]
|
82
|
-
else
|
83
|
-
object[locale.to_s]
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
@@ -23,9 +23,11 @@ module Mongoid
|
|
23
23
|
prepare_atomic_operation do |ops|
|
24
24
|
process_atomic_operations(setters) do |field, value|
|
25
25
|
process_attribute(field.to_s, value)
|
26
|
-
|
26
|
+
unless relations.include?(field.to_s)
|
27
|
+
ops[atomic_attribute_name(field)] = attributes[field]
|
28
|
+
end
|
27
29
|
end
|
28
|
-
{ "$set" => ops }
|
30
|
+
{ "$set" => ops } unless ops.empty?
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
data/lib/mongoid/version.rb
CHANGED
@@ -38,6 +38,42 @@ describe Mongoid::Attributes do
|
|
38
38
|
it "does not raise an error" do
|
39
39
|
expect(from_db.desc).to eq("test")
|
40
40
|
end
|
41
|
+
|
42
|
+
context "accessing via []" do
|
43
|
+
|
44
|
+
it "does not raise an error" do
|
45
|
+
expect(from_db["desc"]).to eq("en" => "test")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when calling only on a sub-document" do
|
50
|
+
|
51
|
+
let(:title) {"Executive"}
|
52
|
+
let(:city) {"NYC"}
|
53
|
+
let!(:agent) do
|
54
|
+
agent = Agent.new(:title => title)
|
55
|
+
agent.build_address(:city => city)
|
56
|
+
agent.save()
|
57
|
+
agent
|
58
|
+
end
|
59
|
+
let(:from_db) do
|
60
|
+
Agent.only(:title, "address.city").first
|
61
|
+
end
|
62
|
+
|
63
|
+
context "when the field is in the only" do
|
64
|
+
|
65
|
+
it "does not raise an error" do
|
66
|
+
expect(from_db.address.city).to eq(city)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "accessing via []" do
|
71
|
+
|
72
|
+
it "does not raise an error" do
|
73
|
+
expect(from_db["address.city"]).to eq(city)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
41
77
|
end
|
42
78
|
|
43
79
|
context 'when the attribute is a hash field' do
|
@@ -86,6 +122,15 @@ describe Mongoid::Attributes do
|
|
86
122
|
from_db.title
|
87
123
|
}.to raise_error(ActiveModel::MissingAttributeError)
|
88
124
|
end
|
125
|
+
|
126
|
+
context "accessing via []" do
|
127
|
+
|
128
|
+
it "raises an error" do
|
129
|
+
expect {
|
130
|
+
from_db["title"]
|
131
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
132
|
+
end
|
133
|
+
end
|
89
134
|
end
|
90
135
|
|
91
136
|
context "when excluding with without" do
|
@@ -1003,11 +1003,6 @@ describe Mongoid::Contextual::Mongo do
|
|
1003
1003
|
|
1004
1004
|
context "when passed the symbol field name" do
|
1005
1005
|
|
1006
|
-
it "limits query to that field" do
|
1007
|
-
expect(criteria).to receive(:only).with(:name).and_call_original
|
1008
|
-
context.map(:name)
|
1009
|
-
end
|
1010
|
-
|
1011
1006
|
it "performs mapping" do
|
1012
1007
|
expect(context.map(:name)).to eq ["Depeche Mode", "New Order"]
|
1013
1008
|
end
|
@@ -20,7 +20,7 @@ describe Mongoid::Copyable do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
let!(:address) do
|
23
|
-
person.addresses.build(street: "Bond")
|
23
|
+
person.addresses.build(street: "Bond", name: "Bond")
|
24
24
|
end
|
25
25
|
|
26
26
|
let!(:name) do
|
@@ -93,6 +93,7 @@ describe Mongoid::Copyable do
|
|
93
93
|
I18n.enforce_available_locales = false
|
94
94
|
I18n.locale = 'pt_BR'
|
95
95
|
person.desc = "descrição"
|
96
|
+
person.addresses.first.name = "descrição"
|
96
97
|
person.save
|
97
98
|
end
|
98
99
|
|
@@ -122,6 +123,16 @@ describe Mongoid::Copyable do
|
|
122
123
|
I18n.locale = :fr
|
123
124
|
expect(copy.desc).to be_nil
|
124
125
|
end
|
126
|
+
|
127
|
+
it 'sets embedded translations' do
|
128
|
+
I18n.locale = 'pt_BR'
|
129
|
+
expect(copy.addresses.first.name).to eq("descrição")
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'sets embedded english version' do
|
133
|
+
I18n.locale = :en
|
134
|
+
expect(copy.addresses.first.name).to eq("Bond")
|
135
|
+
end
|
125
136
|
end
|
126
137
|
|
127
138
|
context "when cloning a loaded document" do
|
@@ -174,6 +174,21 @@ describe Mongoid::Fields::Localized do
|
|
174
174
|
expect(value).to be_nil
|
175
175
|
end
|
176
176
|
end
|
177
|
+
|
178
|
+
context 'when fallbacks are empty' do
|
179
|
+
|
180
|
+
before do
|
181
|
+
::I18n.fallbacks[:de] = [ ]
|
182
|
+
end
|
183
|
+
|
184
|
+
let(:value) do
|
185
|
+
field.demongoize({ 'de' => 'testen' })
|
186
|
+
end
|
187
|
+
|
188
|
+
it "returns the value" do
|
189
|
+
expect(value).to eq('testen')
|
190
|
+
end
|
191
|
+
end
|
177
192
|
end
|
178
193
|
end
|
179
194
|
end
|
@@ -134,6 +134,35 @@ describe Mongoid::Persistable::Settable do
|
|
134
134
|
|
135
135
|
it_behaves_like "a settable embedded document"
|
136
136
|
end
|
137
|
+
|
138
|
+
context 'when the field is a relation' do
|
139
|
+
|
140
|
+
let(:person) do
|
141
|
+
Person.create
|
142
|
+
end
|
143
|
+
|
144
|
+
let(:pet) do
|
145
|
+
Animal.new(name: "somepet")
|
146
|
+
end
|
147
|
+
|
148
|
+
let(:home_phone) do
|
149
|
+
Phone.new(number: "555-555-5555")
|
150
|
+
end
|
151
|
+
|
152
|
+
let(:office_phone) do
|
153
|
+
Phone.new(number: "666-666-6666")
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should persist changes of embeds_one field" do
|
157
|
+
person.set(pet: pet)
|
158
|
+
expect(person.reload.pet).to eq(pet)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should persist changes of embeds_many fields" do
|
162
|
+
person.set({ phone_numbers: [home_phone, office_phone].map { |p| p.as_document} })
|
163
|
+
expect(person.reload.phone_numbers).to eq([home_phone, office_phone])
|
164
|
+
end
|
165
|
+
end
|
137
166
|
end
|
138
167
|
end
|
139
168
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.1.
|
4
|
+
version: 5.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Durran Jordan
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
ZIvvwAhgCjVW5QCi2I1noxXLmtZ3XDawWu8kaGtu8giHXcwL3941m8hvFZ/Wr9Yi
|
31
31
|
JvcXJt2a4/JvwnIs2hmKuyfhZmB9HEE5wQQaCMnnC14=
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2016-
|
33
|
+
date: 2016-08-12 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: activemodel
|
@@ -811,7 +811,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
811
811
|
version: 1.3.6
|
812
812
|
requirements: []
|
813
813
|
rubyforge_project: mongoid
|
814
|
-
rubygems_version: 2.
|
814
|
+
rubygems_version: 2.5.1
|
815
815
|
signing_key:
|
816
816
|
specification_version: 4
|
817
817
|
summary: Elegant Persistence in Ruby for MongoDB.
|
metadata.gz.sig
CHANGED
Binary file
|