mongoid_includes 2.1.0 → 3.0.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 +5 -5
- data/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/lib/mongoid/includes.rb +1 -1
- data/lib/mongoid/includes/{relations → association}/eager.rb +2 -2
- data/lib/mongoid/includes/criteria.rb +1 -1
- data/lib/mongoid/includes/inclusion.rb +9 -15
- data/lib/mongoid/includes/inclusions.rb +8 -3
- data/lib/mongoid/includes/version.rb +1 -1
- data/lib/mongoid_includes.rb +1 -1
- data/spec/mongo.log +19882 -0
- data/spec/mongoid/includes/inclusions_spec.rb +3 -5
- data/spec/mongoid/includes/polymorphic_includes_spec.rb +8 -2
- data/spec/mongoid/includes/simple_inclusions_spec.rb +1 -13
- data/spec/spec_helper.rb +7 -6
- data/spec/support/helpers.rb +13 -36
- data/spec/support/models/address.rb +1 -37
- data/spec/support/models/game.rb +1 -5
- data/spec/support/models/musician.rb +0 -4
- data/spec/support/models/person.rb +3 -18
- data/spec/support/models/post.rb +2 -0
- data/spec/support/models/record.rb +0 -43
- metadata +23 -25
@@ -20,11 +20,9 @@ describe Mongoid::Includes::Inclusions do
|
|
20
20
|
And { result.class == Mongoid::Includes::Inclusions }
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
}
|
27
|
-
Then { inclusions.size == 3 }
|
23
|
+
it 'prevents duplicates' do
|
24
|
+
new_criteria = criteria.includes(:albums)
|
25
|
+
expect(new_criteria.inclusions.size).to eq 3
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
@@ -6,7 +6,7 @@ describe Mongoid::Includes::Criteria do
|
|
6
6
|
Given(:inclusions) { criteria.inclusions }
|
7
7
|
|
8
8
|
context 'multiple inclusions through polymorphic associations' do
|
9
|
-
Given(:pink_floyd) { Band.create!(name: 'Pink Floyd') }
|
9
|
+
Given(:pink_floyd) { Band.create!(name: 'Pink Floyd', musician_ids: [nil, '']) }
|
10
10
|
Given(:jethro) { Band.create!(name: 'Jethro Tull') }
|
11
11
|
Given {
|
12
12
|
Artist.create!(name: 'David Gilmour', associated_act: pink_floyd)
|
@@ -31,7 +31,7 @@ describe Mongoid::Includes::Criteria do
|
|
31
31
|
}
|
32
32
|
|
33
33
|
describe ':with inclusions should not be overriden' do
|
34
|
-
When(:artists) { expect_query(
|
34
|
+
When(:artists) { expect_query(4) { criteria.entries } } # There are no musicians, so no query should be made.
|
35
35
|
Given(:albums) { artists.map(&:associated_act).flat_map(&:albums) }
|
36
36
|
Then { artists.size == 2 }
|
37
37
|
And {
|
@@ -49,6 +49,12 @@ describe Mongoid::Includes::Criteria do
|
|
49
49
|
And { inclusions.first.nested? }
|
50
50
|
And { inclusions.last.polymorphic? && inclusions.last.modifier }
|
51
51
|
end
|
52
|
+
|
53
|
+
it 'should fail if a polymorphic association is not disambiguated' do
|
54
|
+
expect {
|
55
|
+
criteria.includes(:musicians, from: :associated_act)
|
56
|
+
}.to raise_error(Mongoid::Includes::Errors::InvalidPolymorphicIncludes)
|
57
|
+
end
|
52
58
|
end
|
53
59
|
end
|
54
60
|
end
|
@@ -327,7 +327,7 @@ describe Mongoid::Includes::Criteria do
|
|
327
327
|
end
|
328
328
|
|
329
329
|
let!(:depeche) do
|
330
|
-
Band.create!(name: 'Depeche Mode')
|
330
|
+
Band.create!(name: 'Depeche Mode', records: [Record.new(name: 'Music for the Masses')])
|
331
331
|
end
|
332
332
|
|
333
333
|
let!(:tool) do
|
@@ -347,10 +347,6 @@ describe Mongoid::Includes::Criteria do
|
|
347
347
|
peep.reload.addresses.includes(:band)
|
348
348
|
end
|
349
349
|
|
350
|
-
let(:context) do
|
351
|
-
criteria.context
|
352
|
-
end
|
353
|
-
|
354
350
|
let!(:document) do
|
355
351
|
criteria.first
|
356
352
|
end
|
@@ -372,10 +368,6 @@ describe Mongoid::Includes::Criteria do
|
|
372
368
|
peep.reload.addresses.includes(:band)
|
373
369
|
end
|
374
370
|
|
375
|
-
let(:context) do
|
376
|
-
criteria.context
|
377
|
-
end
|
378
|
-
|
379
371
|
let!(:document) do
|
380
372
|
criteria.last
|
381
373
|
end
|
@@ -397,10 +389,6 @@ describe Mongoid::Includes::Criteria do
|
|
397
389
|
peep.reload.addresses.includes(:band)
|
398
390
|
end
|
399
391
|
|
400
|
-
let(:context) do
|
401
|
-
criteria.context
|
402
|
-
end
|
403
|
-
|
404
392
|
let!(:documents) do
|
405
393
|
criteria.to_a
|
406
394
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
CodeClimate::TestReporter.start
|
4
|
-
end
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
5
3
|
|
6
4
|
require 'rspec/given'
|
7
5
|
require 'pry'
|
@@ -45,8 +43,11 @@ Mongoid.configure do |config|
|
|
45
43
|
)
|
46
44
|
end
|
47
45
|
|
48
|
-
|
49
|
-
|
46
|
+
# Logging to the console is useful for debugging queries.
|
47
|
+
Mongo::Logger.logger = Logger.new('./spec/mongo.log')
|
48
|
+
|
49
|
+
def log_mongo_to_console
|
50
|
+
Mongo::Logger.logger = Logger.new($stdout)
|
50
51
|
end
|
51
52
|
|
52
53
|
RSpec.configure do |config|
|
data/spec/support/helpers.rb
CHANGED
@@ -1,43 +1,20 @@
|
|
1
1
|
module Mongoid
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
@events = []
|
7
|
-
end
|
8
|
-
|
9
|
-
def instrument
|
10
|
-
subscriber = ActiveSupport::Notifications.subscribe('query.moped') do |*args|
|
11
|
-
@events << ActiveSupport::Notifications::Event.new(*args)
|
12
|
-
end
|
13
|
-
yield
|
14
|
-
ensure
|
15
|
-
ActiveSupport::Notifications.unsubscribe(subscriber)
|
16
|
-
end
|
17
|
-
|
18
|
-
def inspect
|
19
|
-
@events.map { |e| e.payload[:ops].map(&:log_inspect) }.join("\n")
|
2
|
+
module SpecHelpers
|
3
|
+
def connection_class
|
4
|
+
Mongo::Server::ConnectionBase
|
20
5
|
end
|
21
|
-
end
|
22
|
-
end
|
23
6
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
def expect_query(number, &block)
|
34
|
-
query_counter = Mongoid::QueryCounter.new
|
35
|
-
query_counter.instrument(&block)
|
36
|
-
expect(query_counter.events.size).to(eq(number), %[
|
37
|
-
Expected to receive #{number} queries, it received #{query_counter.events.size}
|
38
|
-
#{query_counter.inspect}
|
39
|
-
])
|
7
|
+
def expect_query(number)
|
8
|
+
rv = nil
|
9
|
+
RSpec::Mocks.with_temporary_scope do
|
10
|
+
if number > 0
|
11
|
+
expect_any_instance_of(connection_class).to receive(:command_started).exactly(number).times.and_call_original
|
12
|
+
else
|
13
|
+
expect_any_instance_of(connection_class).not_to receive(:command_started)
|
14
|
+
end
|
15
|
+
rv = yield
|
40
16
|
end
|
17
|
+
rv
|
41
18
|
end
|
42
19
|
|
43
20
|
def expect_no_queries(&block)
|
@@ -26,44 +26,8 @@ class Address
|
|
26
26
|
|
27
27
|
belongs_to :band
|
28
28
|
|
29
|
-
embedded_in :addressable, polymorphic: true
|
30
|
-
def extension
|
31
|
-
"Testing"
|
32
|
-
end
|
33
|
-
def doctor?
|
34
|
-
title == "Dr"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
scope :without_postcode, ->{ where(postcode: nil) }
|
39
|
-
scope :rodeo, ->{ where(street: "Rodeo Dr") } do
|
40
|
-
def mansion?
|
41
|
-
all? { |address| address.street == "Rodeo Dr" }
|
42
|
-
end
|
43
|
-
end
|
29
|
+
embedded_in :addressable, polymorphic: true
|
44
30
|
|
45
31
|
validates_presence_of :street, on: :update
|
46
32
|
validates_format_of :street, with: /\D/, allow_nil: true
|
47
|
-
|
48
|
-
def set_parent=(set = false)
|
49
|
-
self.parent_title = addressable.title if set
|
50
|
-
end
|
51
|
-
|
52
|
-
def <=>(other)
|
53
|
-
street <=> other.street
|
54
|
-
end
|
55
|
-
|
56
|
-
class << self
|
57
|
-
def california
|
58
|
-
where(state: "CA")
|
59
|
-
end
|
60
|
-
|
61
|
-
def homes
|
62
|
-
where(address_type: "Home")
|
63
|
-
end
|
64
|
-
|
65
|
-
def streets
|
66
|
-
all.map(&:street)
|
67
|
-
end
|
68
|
-
end
|
69
33
|
end
|
data/spec/support/models/game.rb
CHANGED
@@ -7,11 +7,7 @@ class Game
|
|
7
7
|
|
8
8
|
belongs_to :person, index: true, validate: true
|
9
9
|
|
10
|
-
|
11
|
-
belongs_to :parent, class_name: "Game", foreign_key: "parent-id", optional: true
|
12
|
-
else
|
13
|
-
belongs_to :parent, class_name: "Game", foreign_key: "parent-id"
|
14
|
-
end
|
10
|
+
belongs_to :parent, class_name: "Game", foreign_key: "parent-id", optional: true
|
15
11
|
|
16
12
|
accepts_nested_attributes_for :person
|
17
13
|
|
@@ -47,26 +47,11 @@ class Person
|
|
47
47
|
|
48
48
|
attr_reader :rescored
|
49
49
|
|
50
|
-
embeds_many :addresses, as: :addressable, validate: false
|
51
|
-
def extension
|
52
|
-
"Testing"
|
53
|
-
end
|
54
|
-
def find_by_street(street)
|
55
|
-
where(street: street).first
|
56
|
-
end
|
57
|
-
end
|
50
|
+
embeds_many :addresses, as: :addressable, validate: false
|
58
51
|
|
59
|
-
has_one :game, dependent: :destroy, validate: false
|
60
|
-
def extension
|
61
|
-
"Testing"
|
62
|
-
end
|
63
|
-
end
|
52
|
+
has_one :game, dependent: :destroy, validate: false
|
64
53
|
|
65
|
-
has_many :posts, dependent: :
|
66
|
-
def extension
|
67
|
-
"Testing"
|
68
|
-
end
|
69
|
-
end
|
54
|
+
has_many :posts, dependent: :delete_all, validate: false
|
70
55
|
|
71
56
|
has_and_belongs_to_many :preferences, index: true, dependent: :nullify, validate: false
|
72
57
|
end
|
data/spec/support/models/post.rb
CHANGED
@@ -3,48 +3,5 @@ class Record
|
|
3
3
|
|
4
4
|
field :name, type: String
|
5
5
|
|
6
|
-
field :before_create_called, type: Mongoid::Boolean, default: false
|
7
|
-
field :before_save_called, type: Mongoid::Boolean, default: false
|
8
|
-
field :before_update_called, type: Mongoid::Boolean, default: false
|
9
|
-
field :before_validation_called, type: Mongoid::Boolean, default: false
|
10
|
-
field :before_destroy_called, type: Mongoid::Boolean, default: false
|
11
|
-
|
12
6
|
embedded_in :band
|
13
|
-
|
14
|
-
before_create :before_create_stub
|
15
|
-
before_save :before_save_stub
|
16
|
-
before_update :before_update_stub
|
17
|
-
before_validation :before_validation_stub
|
18
|
-
before_destroy :before_destroy_stub
|
19
|
-
|
20
|
-
after_destroy :access_band
|
21
|
-
|
22
|
-
def before_create_stub
|
23
|
-
self.before_create_called = true
|
24
|
-
end
|
25
|
-
|
26
|
-
def before_save_stub
|
27
|
-
self.before_save_called = true
|
28
|
-
end
|
29
|
-
|
30
|
-
def before_update_stub
|
31
|
-
self.before_update_called = true
|
32
|
-
end
|
33
|
-
|
34
|
-
def before_validation_stub
|
35
|
-
self.before_validation_called = true
|
36
|
-
end
|
37
|
-
|
38
|
-
def before_destroy_stub
|
39
|
-
self.before_destroy_called = true
|
40
|
-
end
|
41
|
-
|
42
|
-
def access_band
|
43
|
-
band.name
|
44
|
-
end
|
45
|
-
|
46
|
-
def dont_call_me_twice
|
47
|
-
end
|
48
|
-
|
49
|
-
validate { dont_call_me_twice }
|
50
7
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_includes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Máximo Mussini
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 7.0.10
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 8.0.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 7.0.10
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 8.0.0
|
33
33
|
description: Mongoid::Includes improves eager loading in Mongoid, supporting polymorphic
|
34
34
|
associations, and up to two-levels of eager loading.
|
35
35
|
email:
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- Rakefile
|
45
45
|
- lib/config/locales/en.yml
|
46
46
|
- lib/mongoid/includes.rb
|
47
|
+
- lib/mongoid/includes/association/eager.rb
|
47
48
|
- lib/mongoid/includes/criteria.rb
|
48
49
|
- lib/mongoid/includes/eager_load.rb
|
49
50
|
- lib/mongoid/includes/errors.rb
|
@@ -51,7 +52,6 @@ files:
|
|
51
52
|
- lib/mongoid/includes/errors/invalid_polymorphic_includes.rb
|
52
53
|
- lib/mongoid/includes/inclusion.rb
|
53
54
|
- lib/mongoid/includes/inclusions.rb
|
54
|
-
- lib/mongoid/includes/relations/eager.rb
|
55
55
|
- lib/mongoid/includes/version.rb
|
56
56
|
- lib/mongoid_includes.rb
|
57
57
|
- spec/mongo.log
|
@@ -81,7 +81,7 @@ homepage: https://github.com/ElMassimo/mongoid_includes
|
|
81
81
|
licenses:
|
82
82
|
- MIT
|
83
83
|
metadata: {}
|
84
|
-
post_install_message:
|
84
|
+
post_install_message:
|
85
85
|
rdoc_options:
|
86
86
|
- "--charset=UTF-8"
|
87
87
|
require_paths:
|
@@ -97,33 +97,31 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
99
|
requirements: []
|
100
|
-
|
101
|
-
|
102
|
-
signing_key:
|
100
|
+
rubygems_version: 3.1.2
|
101
|
+
signing_key:
|
103
102
|
specification_version: 4
|
104
103
|
summary: Improved eager loading support for Mongoid.
|
105
104
|
test_files:
|
106
|
-
- spec/mongo.log
|
107
|
-
- spec/mongoid/includes/criteria_spec.rb
|
108
|
-
- spec/mongoid/includes/errors/invalid_includes_spec.rb
|
109
|
-
- spec/mongoid/includes/errors/invalid_polymorphic_includes_spec.rb
|
110
105
|
- spec/mongoid/includes/inclusions_spec.rb
|
111
|
-
- spec/mongoid/includes/nested_inclusions_spec.rb
|
112
106
|
- spec/mongoid/includes/polymorphic_includes_spec.rb
|
113
107
|
- spec/mongoid/includes/simple_inclusions_spec.rb
|
108
|
+
- spec/mongoid/includes/nested_inclusions_spec.rb
|
109
|
+
- spec/mongoid/includes/criteria_spec.rb
|
110
|
+
- spec/mongoid/includes/errors/invalid_polymorphic_includes_spec.rb
|
111
|
+
- spec/mongoid/includes/errors/invalid_includes_spec.rb
|
114
112
|
- spec/spec_helper.rb
|
115
|
-
- spec/support/config/mongoid.yml
|
116
113
|
- spec/support/helpers.rb
|
117
|
-
- spec/support/
|
114
|
+
- spec/support/config/mongoid.yml
|
115
|
+
- spec/support/models/song.rb
|
116
|
+
- spec/support/models/node.rb
|
117
|
+
- spec/support/models/musician.rb
|
118
|
+
- spec/support/models/record.rb
|
118
119
|
- spec/support/models/album.rb
|
119
120
|
- spec/support/models/artist.rb
|
120
|
-
- spec/support/models/band.rb
|
121
121
|
- spec/support/models/game.rb
|
122
|
-
- spec/support/models/musician.rb
|
123
|
-
- spec/support/models/node.rb
|
124
122
|
- spec/support/models/person.rb
|
123
|
+
- spec/support/models/band.rb
|
125
124
|
- spec/support/models/post.rb
|
125
|
+
- spec/support/models/address.rb
|
126
126
|
- spec/support/models/preference.rb
|
127
|
-
- spec/
|
128
|
-
- spec/support/models/song.rb
|
129
|
-
has_rdoc:
|
127
|
+
- spec/mongo.log
|