mongoid 4.0.0.rc1 → 4.0.0.rc2

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: 33fe9286d3ba938ede032903cc4a474975d6f7fe
4
- data.tar.gz: 1d14ddf90e7ed9c9fc67cd0e8f609ce2e1e87f23
3
+ metadata.gz: 0047adcc376dc5ab66b47ee9134f3498c22926d2
4
+ data.tar.gz: c36d95ca80568bb70a33a472536e6689703b903c
5
5
  SHA512:
6
- metadata.gz: 267e9b0f0cf0a568200dd31043025f54fb75773f146d62a9c6fa5ec1561f6e9ae091608c39fe3ee6ce9bf568e681eb623799460c2d57f50a6b737a76f2e2d4a0
7
- data.tar.gz: 2fcb46e0a9ab3ebca70be65d93017f96bfb3bd44da5b9d3cf1e517e6bd622ed2028a6ef16ed00c0212ffffcabeafbf061c4c48dbe60307f4aef22fc27e34a9c6
6
+ metadata.gz: 53384fa62466c3142ae2b8f8040e42145d5c45624c476d3fec257fa3c13d5a3939e960fa91db71e1d7ddf68e7f9ede61c3789a5c100114713af4f59fede92407
7
+ data.tar.gz: f1a487e461294f61724d698a86487f406cce5e88be767915841cc2797267ba94d702094f74bccbbf576f46a5aa850044ef76e99f180617534c86da3d4b8aca9c
@@ -345,6 +345,9 @@ For instructions on upgrading to newer versions, visit
345
345
 
346
346
  ### Resolved Issues
347
347
 
348
+ * \#3676 Make pluck work with embedded associations
349
+ (Arthur Neves)
350
+
348
351
  * \#2898 Dirty attribute methods now properly handle field aliases.
349
352
  (Niels Ganser)
350
353
 
@@ -197,6 +197,17 @@ module Mongoid
197
197
  self
198
198
  end
199
199
 
200
+ def pluck(*fields)
201
+ fields = Array.wrap(fields)
202
+ documents.map do |doc|
203
+ if fields.size == 1
204
+ doc[fields.first]
205
+ else
206
+ fields.map { |n| doc[n] }.compact
207
+ end
208
+ end.compact
209
+ end
210
+
200
211
  # Skips the provided number of documents.
201
212
  #
202
213
  # @example Skip the documents.
@@ -259,12 +259,22 @@ module Mongoid
259
259
  send("_#{kind}_callbacks").each do |callback|
260
260
  chain.append(callback) if callback.kind == place
261
261
  end
262
- class_eval <<-EOM
263
- def #{name}()
264
- #{chain.compile}
262
+
263
+ if Gem::Version.new("4.1.0") <= Gem::Version.new(ActiveSupport::VERSION::STRING)
264
+ self.class.send :define_method, name do
265
+ runner = ActiveSupport::Callbacks::Filters::Environment.new(self, false, nil)
266
+ chain.compile.call(runner).value
265
267
  end
266
- protected :#{name}
267
- EOM
268
+ self.class.send :protected, name
269
+ else
270
+ class_eval <<-EOM
271
+ def #{name}()
272
+ #{chain.compile}
273
+ end
274
+ protected :#{name}
275
+ EOM
276
+ end
277
+
268
278
  end
269
279
  send(name)
270
280
  end
@@ -102,7 +102,7 @@ module Mongoid
102
102
  attrs[name] = value ? value.serializable_hash(options) : nil
103
103
  elsif names.include?(name) && !fields.has_key?(name)
104
104
  attrs[name] = read_attribute(name)
105
- else
105
+ elsif !attribute_missing?(name)
106
106
  attrs[name] = send(name)
107
107
  end
108
108
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid
3
- VERSION = "4.0.0.rc1"
3
+ VERSION = "4.0.0.rc2"
4
4
  end
@@ -21,12 +21,12 @@ development:
21
21
  # read: secondary_preferred
22
22
 
23
23
  # How many times Moped should attempt to retry an operation after
24
- # failure. (default: 30)
25
- # max_retries: 30
24
+ # failure. (default: The number of nodes in the cluster)
25
+ # max_retries: 20
26
26
 
27
27
  # The time in seconds that Moped should wait before retrying an
28
- # operation on failure. (default: 1)
29
- # retry_interval: 1
28
+ # operation on failure. (default: 0.25)
29
+ # retry_interval: 0.25
30
30
  # Configure Mongoid specific options. (optional)
31
31
  options:
32
32
  # Includes the root model name in json serialization. (default: false)
@@ -729,6 +729,63 @@ describe Mongoid::Contextual::Memory do
729
729
  end
730
730
  end
731
731
 
732
+ describe "#pluck" do
733
+
734
+ let(:hobrecht) do
735
+ Address.new(street: "hobrecht")
736
+ end
737
+
738
+ let(:friedel) do
739
+ Address.new(street: "friedel")
740
+ end
741
+
742
+ let(:criteria) do
743
+ Address.all.tap do |crit|
744
+ crit.documents = [ hobrecht, friedel ]
745
+ end
746
+ end
747
+
748
+ let(:context) do
749
+ described_class.new(criteria)
750
+ end
751
+
752
+ context "when plucking" do
753
+
754
+ let!(:plucked) do
755
+ context.pluck(:street)
756
+ end
757
+
758
+ it "returns the values" do
759
+ expect(plucked).to eq([ "hobrecht", "friedel" ])
760
+ end
761
+ end
762
+
763
+ context "when plucking a field that doesnt exist" do
764
+
765
+ context "when pluck one field" do
766
+
767
+ let(:plucked) do
768
+ context.pluck(:foo)
769
+ end
770
+
771
+ it "returns a empty array" do
772
+ expect(plucked).to eq([])
773
+ end
774
+ end
775
+
776
+ context "when pluck multiple fields" do
777
+
778
+ let(:plucked) do
779
+ context.pluck(:foo, :bar)
780
+ end
781
+
782
+ it "returns a empty array" do
783
+ expect(plucked).to eq([[], []])
784
+ end
785
+ end
786
+ end
787
+ end
788
+
732
789
  describe "#skip" do
733
790
 
734
791
  let(:hobrecht) do
@@ -421,6 +421,7 @@ describe Mongoid::Interceptable do
421
421
 
422
422
  before(:all) do
423
423
  Band.define_model_callbacks(:rearrange)
424
+ Band.after_rearrange { }
424
425
  end
425
426
 
426
427
  after(:all) do
@@ -231,6 +231,24 @@ describe Mongoid::Serializable do
231
231
  )
232
232
  end
233
233
  end
234
+
235
+ context "when only two attributes are loaded" do
236
+ before do
237
+ person.save
238
+ end
239
+
240
+ let(:from_db) do
241
+ Person.only("_id", "username").first
242
+ end
243
+
244
+ let(:hash) do
245
+ from_db.serializable_hash
246
+ end
247
+
248
+ it "returns those two attributes only" do
249
+ expect(hash.keys).to eq(["_id", "username"])
250
+ end
251
+ end
234
252
  end
235
253
 
236
254
  context "when a model has dynamic fields" 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: 4.0.0.rc1
4
+ version: 4.0.0.rc2
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-06-02 00:00:00.000000000 Z
11
+ date: 2014-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.0
19
+ version: '4.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
- version: 4.0.0
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: tzinfo
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.0.0.rc1
47
+ version: 2.0.0.rc2
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.0.rc1
54
+ version: 2.0.0.rc2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: origin
57
57
  requirement: !ruby/object:Gem::Requirement