mongoid_includes 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -4
- data/lib/mongoid/includes/inclusion.rb +2 -2
- data/lib/mongoid/includes/inclusions.rb +7 -0
- data/lib/mongoid/includes/version.rb +1 -1
- data/spec/mongo.log +6656 -0
- data/spec/mongoid/includes/polymorphic_includes_spec.rb +54 -0
- data/spec/support/models/artist.rb +2 -0
- metadata +6 -2
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mongoid::Includes::Criteria do
|
4
|
+
|
5
|
+
describe '#includes' do
|
6
|
+
Given(:inclusions) { criteria.inclusions }
|
7
|
+
|
8
|
+
context 'multiple inclusions through polymorphic associations' do
|
9
|
+
Given(:pink_floyd) { Band.create!(name: 'Pink Floyd') }
|
10
|
+
Given(:jethro) { Band.create!(name: 'Jethro Tull') }
|
11
|
+
Given {
|
12
|
+
Artist.create!(name: 'David Gilmour', associated_act: pink_floyd)
|
13
|
+
wywh = Album.create!(name: 'Wish You Were Here', release: Date.new(1975), owner: pink_floyd)
|
14
|
+
Album.create!(name: 'The Dark Side of the Moon', release: Date.new(1973), owner: pink_floyd)
|
15
|
+
|
16
|
+
Artist.create!(name: 'Ian Anderson', associated_act: jethro)
|
17
|
+
standup = Album.create!(name: 'Stand Up', release: Date.new(1969), owner: jethro)
|
18
|
+
Album.create!(name: 'Aqualung', release: Date.new(1971), owner: jethro)
|
19
|
+
|
20
|
+
Song.create!(name: 'Shine On', album: wywh)
|
21
|
+
Song.create!(name: 'We Used to Know', album: standup)
|
22
|
+
}
|
23
|
+
Given(:criteria) {
|
24
|
+
Artist
|
25
|
+
.includes(:musicians, from: :associated_act, from_class: Band)
|
26
|
+
.includes(:associated_act, with: ->(bands) {
|
27
|
+
bands
|
28
|
+
.includes(:albums, with: ->(albums) { albums.gt(release: 1970) })
|
29
|
+
.includes(:songs, from: :albums, with: ->(songs) { songs })
|
30
|
+
})
|
31
|
+
}
|
32
|
+
|
33
|
+
describe ':with inclusions should not be overriden' do
|
34
|
+
When(:artists) { expect_query(5) { criteria.entries } }
|
35
|
+
Given(:albums) { artists.map(&:associated_act).flat_map(&:albums) }
|
36
|
+
Then { artists.size == 2 }
|
37
|
+
And {
|
38
|
+
expect_no_queries { albums.size == 3 } # gt(release: 1970)
|
39
|
+
}
|
40
|
+
And {
|
41
|
+
expect_no_queries { albums.flat_map(&:songs).size == 1 } # Only "Shine On"
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'should not replace an includes with an specified modifier with a generic one' do
|
46
|
+
Given(:inclusions) { new_criteria.inclusions.to_a }
|
47
|
+
When(:new_criteria) { criteria.includes(:musicians, from: :associated_act, from_class: Band) }
|
48
|
+
Then { inclusions.size == 2 }
|
49
|
+
And { inclusions.first.nested? }
|
50
|
+
And { inclusions.last.polymorphic? && inclusions.last.modifier }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
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: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Máximo Mussini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -54,11 +54,13 @@ files:
|
|
54
54
|
- lib/mongoid/includes/relations/eager.rb
|
55
55
|
- lib/mongoid/includes/version.rb
|
56
56
|
- lib/mongoid_includes.rb
|
57
|
+
- spec/mongo.log
|
57
58
|
- spec/mongoid/includes/criteria_spec.rb
|
58
59
|
- spec/mongoid/includes/errors/invalid_includes_spec.rb
|
59
60
|
- spec/mongoid/includes/errors/invalid_polymorphic_includes_spec.rb
|
60
61
|
- spec/mongoid/includes/inclusions_spec.rb
|
61
62
|
- spec/mongoid/includes/nested_inclusions_spec.rb
|
63
|
+
- spec/mongoid/includes/polymorphic_includes_spec.rb
|
62
64
|
- spec/mongoid/includes/simple_inclusions_spec.rb
|
63
65
|
- spec/spec_helper.rb
|
64
66
|
- spec/support/config/mongoid.yml
|
@@ -101,11 +103,13 @@ signing_key:
|
|
101
103
|
specification_version: 4
|
102
104
|
summary: Improved eager loading support for Mongoid.
|
103
105
|
test_files:
|
106
|
+
- spec/mongo.log
|
104
107
|
- spec/mongoid/includes/criteria_spec.rb
|
105
108
|
- spec/mongoid/includes/errors/invalid_includes_spec.rb
|
106
109
|
- spec/mongoid/includes/errors/invalid_polymorphic_includes_spec.rb
|
107
110
|
- spec/mongoid/includes/inclusions_spec.rb
|
108
111
|
- spec/mongoid/includes/nested_inclusions_spec.rb
|
112
|
+
- spec/mongoid/includes/polymorphic_includes_spec.rb
|
109
113
|
- spec/mongoid/includes/simple_inclusions_spec.rb
|
110
114
|
- spec/spec_helper.rb
|
111
115
|
- spec/support/config/mongoid.yml
|