mongoid 6.1.0.rc0 → 6.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd1c5f3e10aa8f29d9a04da6580f7b2bd22b67e1
4
- data.tar.gz: 0244eacd65adceb037276b870846e0a5fca9407a
3
+ metadata.gz: c57e0133222699f9072fe67b609e7212327028ff
4
+ data.tar.gz: f2f799925ab8ca3b9126b16fe5a8d52c03fb1146
5
5
  SHA512:
6
- metadata.gz: 28d80be687ea4b751298f72401eb18a45a3350c362cd78d83bd2a7fe6f51be41259dabec2ba856c752747b071dd4c18b41661325d7ba6f9e015a29557eb641f9
7
- data.tar.gz: 22091327a5876754cba1a2cfaea2362e07abbf9e5613ac1a272637f06e379ca9d72878379ceb52e0bc2687baf5e007b27bb1569112c6545abc1e29682bc031ef
6
+ metadata.gz: 8139bde85b47d8920a022f4f1a3c68796c446192128be7a7ceb59607c82be58404a956e89676e61ce61a6f39fd691b4b8f39bf2a31663ef64f482a5271986484
7
+ data.tar.gz: d500146fa38cbdf1e5d915fa164ef465f4b0ba3ffc7568d77fc85bc9576b61dab8efdbffa42ff8fb2b72063997b8207c264ec52a2f11c04140f09c2a5532b778
Binary file
data.tar.gz.sig CHANGED
@@ -1,3 +1 @@
1
- V����J���R���Q���b#��YĐ�3�Z=խ7��>�Zh3����� Wt���F63�@�$>�"(bh5��n)SWj���� B()�_�
2
- �����8XOGi�7w���_[��݁�Ҟ��H��pļ\ D�0��৔@�WU=������j.���
3
- �3�������U%��h�:w2A���R����(٘0�PbK����:Q4( ���)Q����T�ݧ~�F��:�[�U��=@:�<̯�1�.�
1
+ xp���ewE���lSeCQݔ�oNѨ+jSF7���0p�*=-2U����?ЌGE��`a#K�|#�i�e��Z���cB�?��l=�LL�Q��K�>�bB#w�{B �q� b>$2��(ٛL k��G��� _ ˸,,��%Z�}n��k2빎$Ґ��&I���"�$oͮ,cIt&b2 :�ܭ���y����vz؟��k�;����l�w>��\�=E��<�ˬ����o��a��
data/README.md CHANGED
@@ -26,12 +26,12 @@ Mongoid is tested against MRI 2.2, 2.3 and JRuby (9.1).
26
26
  Documentation
27
27
  -------------
28
28
 
29
- Please see the [MongoDB website](http://docs.mongodb.org/ecosystem/tutorial/ruby-mongoid-tutorial/#ruby-mongoid-tutorial) for up-to-date documentation on 5.0.0:
29
+ Please see the [MongoDB website](http://docs.mongodb.org/ecosystem/tutorial/ruby-mongoid-tutorial/#ruby-mongoid-tutorial) for up-to-date documentation.
30
30
 
31
31
  License
32
32
  -------
33
33
 
34
- Copyright (c) 2009-2016 Durran Jordan
34
+ Copyright (c) 2009-2017 Durran Jordan
35
35
 
36
36
  Permission is hereby granted, free of charge, to any person obtaining
37
37
  a copy of this software and associated documentation files (the
@@ -242,6 +242,18 @@ module Mongoid
242
242
  (selection.values.first == 1 && !selection_included?(name, selection, field))
243
243
  end
244
244
 
245
+ # Return type-casted attributes.
246
+ #
247
+ # @example Type-casted attributes.
248
+ # document.typed_attributes
249
+ #
250
+ # @return [ Object ] The hash with keys and values of the type-casted attributes.
251
+ #
252
+ # @since 6.1.0
253
+ def typed_attributes
254
+ attribute_names.map { |name| [name, send(name)] }.to_h
255
+ end
256
+
245
257
  private
246
258
 
247
259
  def selection_excluded?(name, selection, field)
@@ -37,7 +37,7 @@ module Mongoid
37
37
  # @since 4.0.0
38
38
  def define_dynamic_reader(name)
39
39
  return unless name.valid_method_name?
40
- class_eval <<-READER
40
+ class_eval <<-READER, __FILE__, __LINE__ + 1
41
41
  def #{name}
42
42
  attribute_will_change!(#{name.inspect})
43
43
  read_attribute(#{name.inspect})
@@ -56,7 +56,7 @@ module Mongoid
56
56
  #
57
57
  # @since 4.0.0
58
58
  def define_dynamic_before_type_cast_reader(name)
59
- class_eval <<-READER
59
+ class_eval <<-READER, __FILE__, __LINE__ + 1
60
60
  def #{name}_before_type_cast
61
61
  attribute_will_change!(#{name.inspect})
62
62
  read_attribute_before_type_cast(#{name.inspect})
@@ -77,7 +77,7 @@ module Mongoid
77
77
  def define_dynamic_writer(name)
78
78
  return unless name.valid_method_name?
79
79
 
80
- class_eval <<-WRITER
80
+ class_eval <<-WRITER, __FILE__, __LINE__ + 1
81
81
  def #{name}=(value)
82
82
  write_attribute(#{name.inspect}, value)
83
83
  end
@@ -31,7 +31,7 @@ module Mongoid
31
31
  def option(name, options = {})
32
32
  defaults[name] = settings[name] = options[:default]
33
33
 
34
- class_eval <<-RUBY
34
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
35
35
  def #{name}
36
36
  settings[#{name.inspect}]
37
37
  end
@@ -196,6 +196,8 @@ module Mongoid
196
196
  # @since 1.0.0
197
197
  def initialize(klass)
198
198
  @klass = klass
199
+ @embedded = nil
200
+ @none = nil
199
201
  klass ? super(klass.aliased_fields, klass.fields) : super({}, {})
200
202
  end
201
203
 
@@ -65,6 +65,7 @@ module Mongoid
65
65
  @options = Options.new(aliases, serializers)
66
66
  @selector = Selector.new(aliases, serializers)
67
67
  @pipeline = Pipeline.new(aliases)
68
+ @aggregating = nil
68
69
  yield(self) if block_given?
69
70
  end
70
71
 
@@ -46,13 +46,13 @@ module Mongoid
46
46
  # @since 1.0.0
47
47
  def __forward__(name, receiver)
48
48
  if self.class == Module
49
- module_eval <<-SEL
49
+ module_eval <<-SEL, __FILE__, __LINE__ + 1
50
50
  def #{name}(*args, &block)
51
51
  #{receiver}.__send__(:#{name}, *args, &block)
52
52
  end
53
53
  SEL
54
54
  else
55
- (class << self; self; end).class_eval <<-SEL
55
+ singleton_class.class_eval <<-SEL, __FILE__, __LINE__ + 1
56
56
  def #{name}(*args, &block)
57
57
  #{receiver}.__send__(:#{name}, *args, &block)
58
58
  end
@@ -110,6 +110,7 @@ module Mongoid
110
110
  #
111
111
  # @since 1.0.0
112
112
  def initialize(attrs = nil)
113
+ @__parent = nil
113
114
  _building do
114
115
  @new_record = true
115
116
  @attributes ||= {}
@@ -27,7 +27,9 @@ module Mongoid
27
27
  field = field_and_value_hash.keys.first.to_s
28
28
 
29
29
  if fields[field] && fields[field].type == Hash && attributes.key?(field)
30
- process_attribute(field.to_s, attributes[field].merge(field_and_value_hash[field]))
30
+ merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
31
+ value = attributes[field].merge(field_and_value_hash[field], &merger)
32
+ process_attribute(field.to_s, value)
31
33
  else
32
34
  process_attribute(field.to_s, field_and_value_hash[field])
33
35
  end
@@ -26,12 +26,7 @@ module Mongoid
26
26
  def update_attribute(name, value)
27
27
  as_writable_attribute!(name, value) do |access|
28
28
  normalized = name.to_s
29
- setter = "#{normalized}="
30
- if respond_to?(setter)
31
- send(setter, value)
32
- else
33
- write_attribute(access, value)
34
- end
29
+ process_attribute(normalized, value)
35
30
  save(validate: false)
36
31
  end
37
32
  end
@@ -160,7 +160,7 @@ module Mongoid
160
160
  #
161
161
  # @since 3.0.0
162
162
  def existence_check(name)
163
- module_eval <<-END
163
+ module_eval <<-END, __FILE__, __LINE__ + 1
164
164
  def #{name}?
165
165
  without_autobuild { !__send__(:#{name}).blank? }
166
166
  end
@@ -64,7 +64,7 @@ module Mongoid
64
64
  # @since 2.0.0.rc.1
65
65
  def builder(name, metadata)
66
66
  re_define_method("build_#{name}") do |*args|
67
- attributes, options = parse_args(*args)
67
+ attributes, _options = parse_args(*args)
68
68
  document = Factory.build(metadata.klass, attributes)
69
69
  _building do
70
70
  child = send("#{name}=", document)
@@ -89,7 +89,7 @@ module Mongoid
89
89
  # @since 2.0.0.rc.1
90
90
  def creator(name, metadata)
91
91
  re_define_method("create_#{name}") do |*args|
92
- attributes, options = parse_args(*args)
92
+ attributes, _options = parse_args(*args)
93
93
  document = Factory.build(metadata.klass, attributes)
94
94
  doc = _assigning do
95
95
  send("#{name}=", document)
@@ -14,9 +14,9 @@ module Mongoid
14
14
  end
15
15
 
16
16
  def eager_load(docs)
17
- docs.tap do |docs|
17
+ docs.tap do |d|
18
18
  if eager_loadable?
19
- preload(criteria.inclusions, docs)
19
+ preload(criteria.inclusions, d)
20
20
  end
21
21
  end
22
22
  end
@@ -24,7 +24,7 @@ module Mongoid
24
24
  # @example Find multiple relation metadata by macro.
25
25
  # person.reflect_on_all_associations(:embeds_many)
26
26
  #
27
- # @param [ Array<String, Symbol> ] *macros The relation macros.
27
+ # @param [ Array<Symbol> ] *macros The relation macros.
28
28
  #
29
29
  # @return [ Array<Metadata> ] The matching relation metadata.
30
30
  def reflect_on_all_associations(*macros)
@@ -50,11 +50,13 @@ module Mongoid
50
50
  # @example Find multiple relation metadata by macro.
51
51
  # Person.reflect_on_all_associations(:embeds_many)
52
52
  #
53
- # @param [ Array<String, Symbol> ] *macros The relation macros.
53
+ # @param [ Array<Symbol> ] *macros The relation macros.
54
54
  #
55
55
  # @return [ Array<Metadata> ] The matching relation metadata.
56
56
  def reflect_on_all_associations(*macros)
57
- relations.values.select { |meta| macros.include?(meta.macro) }
57
+ association_reflections = relations.values
58
+ association_reflections.select! { |reflection| macros.include?(reflection.macro) } unless macros.empty?
59
+ association_reflections
58
60
  end
59
61
  end
60
62
  end
@@ -81,7 +81,7 @@ module Mongoid
81
81
  # @return [ Symbol ] The method name.
82
82
  def define_relation_touch_method(name, extra_field = nil)
83
83
  method_name = "touch_#{name}_after_create_or_destroy"
84
- class_eval <<-TOUCH
84
+ class_eval <<-TOUCH, __FILE__, __LINE__ + 1
85
85
  def #{method_name}
86
86
  without_autobuild do
87
87
  relation = __send__(:#{name})
@@ -117,7 +117,7 @@ module Mongoid
117
117
  # @since 3.0.0
118
118
  def queryable
119
119
  crit = Threaded.current_scope(self) || Criteria.new(self)
120
- crit.embedded = true if crit.klass.embedded?
120
+ crit.embedded = true if (crit.klass.embedded? && !crit.klass.cyclic?)
121
121
  crit
122
122
  end
123
123
 
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid
3
- VERSION = "6.1.0.rc0"
3
+ VERSION = "6.1.0"
4
4
  end
@@ -51,8 +51,8 @@ development:
51
51
  # via ismaster commands. (default: 10)
52
52
  # heartbeat_frequency: 10
53
53
 
54
- # The time in seconds for selecting servers for a near read preference. (default: 5)
55
- # local_threshold: 5
54
+ # The time in seconds for selecting servers for a near read preference. (default: 0.015)
55
+ # local_threshold: 0.015
56
56
 
57
57
  # The timeout in seconds for selecting a server for an operation. (default: 30)
58
58
  # server_selection_timeout: 30
@@ -2,4 +2,5 @@ class Dokument
2
2
  include Mongoid::Document
3
3
  include Mongoid::Timestamps
4
4
  embeds_many :addresses, as: :addressable, validate: false
5
+ field :title
5
6
  end
@@ -1,4 +1,5 @@
1
1
  class Subscription
2
2
  include Mongoid::Document
3
3
  has_many :packs, class_name: "ShippingPack"
4
+ field :packs_count, type: Integer
4
5
  end
@@ -1385,6 +1385,21 @@ describe Mongoid::Attributes do
1385
1385
  end
1386
1386
  end
1387
1387
 
1388
+ describe "#typed_attributes" do
1389
+
1390
+ let(:date_time) do
1391
+ DateTime.current
1392
+ end
1393
+
1394
+ let(:user) do
1395
+ User.new(last_login: date_time)
1396
+ end
1397
+
1398
+ it 'returns typecasted attributes' do
1399
+ expect(user.typed_attributes).to include("last_login" => date_time)
1400
+ end
1401
+ end
1402
+
1388
1403
  [:attributes=, :write_attributes].each do |method|
1389
1404
 
1390
1405
  describe "##{method}" do
@@ -261,6 +261,50 @@ describe Mongoid::Persistable::Settable do
261
261
  expect(church.reload.location).to eq({ 'city' => 'Berlin', 'street' => 'Yorckstr.'})
262
262
  end
263
263
  end
264
+
265
+ context 'when the field is a bested hash' do
266
+
267
+ context 'when a leaf value in the nested hash is updated' do
268
+
269
+ let(:church) do
270
+ Church.new.tap do |a|
271
+ a.location = {'address' => {'city' => 'Berlin', 'street' => 'Yorckstr'}}
272
+ a.name = 'Church1'
273
+ a.save
274
+ end
275
+ end
276
+
277
+ before do
278
+ church.set('location.address.city' => 'Munich')
279
+ end
280
+
281
+ it 'does not reset the nested hash' do
282
+ expect(church.name).to eq('Church1')
283
+ expect(church.location).to eql({'address' => {'city' => 'Munich', 'street' => 'Yorckstr'}})
284
+ end
285
+ end
286
+
287
+
288
+ context 'when the nested hash is many levels deep' do
289
+
290
+ let(:church) do
291
+ Church.new.tap do |a|
292
+ a.location = {'address' => {'state' => {'address' => {'city' => 'Berlin', 'street' => 'Yorckstr'}}}}
293
+ a.name = 'Church1'
294
+ a.save
295
+ end
296
+ end
297
+
298
+ before do
299
+ church.set('location.address.state.address.city' => 'Munich')
300
+ end
301
+
302
+ it 'does not reset the nested hash' do
303
+ expect(church.name).to eq('Church1')
304
+ expect(church.location).to eql({'address' => {'state' => {'address' => {'city' => 'Munich', 'street' => 'Yorckstr'}}}})
305
+ end
306
+ end
307
+ end
264
308
  end
265
309
 
266
310
  context 'when the field is not already set locally' do
@@ -112,6 +112,24 @@ describe Mongoid::Persistable::Updatable do
112
112
  end
113
113
  end
114
114
 
115
+ context "when dynamic attributes are not enabled" do
116
+
117
+ it "raises exception for an unknown attribute " do
118
+ account = Account.create
119
+
120
+ expect {
121
+ account.update_attribute(:somethingnew, "somethingnew")
122
+ }.to raise_error(Mongoid::Errors::UnknownAttribute)
123
+ end
124
+
125
+ it "will update value of aliased field" do
126
+ person = Person.create
127
+ person.update_attribute(:t, "test_value")
128
+ expect(person.reload.t).to eq "test_value"
129
+ expect(person.test).to eq "test_value"
130
+ end
131
+ end
132
+
115
133
  context "when provided a symbol attribute name" do
116
134
 
117
135
  let(:post) do
@@ -21,6 +21,17 @@ describe Mongoid::Relations::Cyclic do
21
21
  it "sets cyclic to true" do
22
22
  expect(document.cyclic).to be true
23
23
  end
24
+
25
+ context "when a query is executed" do
26
+
27
+ before do
28
+ document.save
29
+ end
30
+
31
+ it "queries the database, not memory" do
32
+ expect(Role.first).to be_a(Role)
33
+ end
34
+ end
24
35
  end
25
36
 
26
37
  context "when the name is not inflected easily" do
@@ -133,6 +144,17 @@ describe Mongoid::Relations::Cyclic do
133
144
  expect(document.class.relations['child_mango']).to be_cascading_callbacks
134
145
  end
135
146
  end
147
+
148
+ context "when a query is executed" do
149
+
150
+ before do
151
+ document.save
152
+ end
153
+
154
+ it "queries the database, not memory" do
155
+ expect(Shelf.first).to be_a(Shelf)
156
+ end
157
+ end
136
158
  end
137
159
 
138
160
  context "when building a namespaced hierarchy" do
@@ -74,23 +74,23 @@ describe Mongoid::Relations::Reflections do
74
74
  expect(relations.size).to eq(1)
75
75
  end
76
76
  end
77
- end
78
77
 
79
- context "when no relations exist for the macros" do
78
+ context "when no argument supplied" do
80
79
 
81
- let(:relations) do
82
- klass.reflect_on_all_associations(:embeds_one)
83
- end
80
+ let(:relations) do
81
+ klass.reflect_on_all_associations
82
+ end
84
83
 
85
- it "returns an empty array" do
86
- expect(relations).to be_empty
84
+ it "returns an array of all relations" do
85
+ expect(relations.size).to eq(3)
86
+ end
87
87
  end
88
88
  end
89
89
 
90
- context "when no argument supplied" do
90
+ context "when no relations exist for the macros" do
91
91
 
92
92
  let(:relations) do
93
- klass.reflect_on_all_associations
93
+ klass.reflect_on_all_associations(:embeds_one)
94
94
  end
95
95
 
96
96
  it "returns an empty array" do
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: 6.1.0.rc0
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan
@@ -30,7 +30,7 @@ cert_chain:
30
30
  cGiNQIiHBj/9/xHfOyOthBPUevTiVnuffarDr434z/LGLwYzgaG5EcJFvZqpvUpP
31
31
  fGcAPtAZUMGLXwcOB1BJEFkDxUQIJiEpSmf4YzzZhEM=
32
32
  -----END CERTIFICATE-----
33
- date: 2016-12-22 00:00:00.000000000 Z
33
+ date: 2017-01-26 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: activemodel
@@ -862,7 +862,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
862
862
  version: 1.3.6
863
863
  requirements: []
864
864
  rubyforge_project: mongoid
865
- rubygems_version: 2.6.8
865
+ rubygems_version: 2.4.5.1
866
866
  signing_key:
867
867
  specification_version: 4
868
868
  summary: Elegant Persistence in Ruby for MongoDB.
metadata.gz.sig CHANGED
Binary file