Skip to content

Commit 05c8d0d

Browse files
authored
Merge pull request #11 from ElMassimo/fix/eager-loading-refactor
Fix error after Mongoid eager loading internals were refactored in 6.0.1
2 parents d69ba3a + 40805ea commit 05c8d0d

8 files changed

Lines changed: 209 additions & 63 deletions

File tree

.travis.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,19 @@ language: ruby
33
bundler_args: --without development
44

55
rvm:
6-
- 2.0.0
7-
- 2.1.1
8-
- 2.2.2
6+
- 2.3.3
97

108
gemfile:
119
- Gemfile
12-
- gemfiles/mongoid4.gemfile
1310
- gemfiles/mongoid6.gemfile
1411

1512
env:
1613
global:
1714
- CI="travis"
1815
- JRUBY_OPTS="--server -J-Xms512m -J-Xmx1024m"
1916
matrix:
20-
- MONGODB=2.4.14
2117
- MONGODB=2.6.10
2218

23-
matrix:
24-
exclude:
25-
- rvm: 2.0.0
26-
gemfile: gemfiles/mongoid6.gemfile
27-
- rvm: 2.1.1
28-
gemfile: gemfiles/mongoid6.gemfile
29-
3019
before_script:
3120
- wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-${MONGODB}.tgz -O /tmp/mongodb.tgz
3221
- tar -xvf /tmp/mongodb.tgz

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ gemspec
55
gem 'bundler'
66
gem 'rake'
77
gem 'pry'
8-
gem 'mongoid', '~> 5.0.0'
8+
gem 'mongoid', '6.0.1'
99

1010
group :test do
1111
gem 'rspec-given', '~> 3.5'

Gemfile.lock

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,31 @@ PATH
77
GEM
88
remote: https://rubygems.org/
99
specs:
10-
activemodel (4.2.4)
11-
activesupport (= 4.2.4)
12-
builder (~> 3.1)
13-
activesupport (4.2.4)
10+
activemodel (5.0.1)
11+
activesupport (= 5.0.1)
12+
activesupport (5.0.1)
13+
concurrent-ruby (~> 1.0, >= 1.0.2)
1414
i18n (~> 0.7)
15-
json (~> 1.7, >= 1.7.7)
1615
minitest (~> 5.1)
17-
thread_safe (~> 0.3, >= 0.3.4)
1816
tzinfo (~> 1.1)
19-
bson (3.2.6)
20-
builder (3.2.2)
17+
bson (4.2.1)
2118
codeclimate-test-reporter (0.4.7)
2219
simplecov (>= 0.7.1, < 1.0.0)
2320
coderay (1.1.0)
21+
concurrent-ruby (1.0.4)
2422
diff-lcs (1.2.5)
2523
docile (1.1.5)
2624
given_core (3.7.1)
2725
sorcerer (>= 0.3.7)
2826
i18n (0.7.0)
2927
json (1.8.3)
3028
method_source (0.8.2)
31-
minitest (5.8.1)
32-
mongo (2.1.1)
33-
bson (~> 3.0)
34-
mongoid (5.0.0)
35-
activemodel (~> 4.0)
36-
mongo (~> 2.1)
37-
origin (~> 2.1)
38-
tzinfo (>= 0.3.37)
39-
origin (2.1.1)
29+
minitest (5.10.1)
30+
mongo (2.4.1)
31+
bson (>= 4.2.1, < 5.0.0)
32+
mongoid (6.0.1)
33+
activemodel (~> 5.0)
34+
mongo (~> 2.3)
4035
pry (0.10.1)
4136
coderay (~> 1.1.0)
4237
method_source (~> 0.8.1)
@@ -80,7 +75,7 @@ PLATFORMS
8075
DEPENDENCIES
8176
bundler
8277
codeclimate-test-reporter
83-
mongoid (~> 5.0.0)
78+
mongoid (= 6.0.1)
8479
mongoid_includes!
8580
pry
8681
rake

gemfiles/mongoid4.gemfile.lock

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
PATH
2+
remote: ..
3+
specs:
4+
mongoid_includes (1.1.3)
5+
mongoid (>= 4.0.0, < 7.0.0)
6+
7+
GEM
8+
remote: https://rubygems.org/
9+
specs:
10+
activemodel (4.2.7.1)
11+
activesupport (= 4.2.7.1)
12+
builder (~> 3.1)
13+
activesupport (4.2.7.1)
14+
i18n (~> 0.7)
15+
json (~> 1.7, >= 1.7.7)
16+
minitest (~> 5.1)
17+
thread_safe (~> 0.3, >= 0.3.4)
18+
tzinfo (~> 1.1)
19+
bson (3.2.6)
20+
builder (3.2.2)
21+
codeclimate-test-reporter (1.0.4)
22+
simplecov
23+
coderay (1.1.1)
24+
connection_pool (2.2.1)
25+
diff-lcs (1.2.5)
26+
docile (1.1.5)
27+
given_core (3.8.0)
28+
sorcerer (>= 0.3.7)
29+
i18n (0.7.0)
30+
json (1.8.3)
31+
method_source (0.8.2)
32+
minitest (5.10.1)
33+
mongoid (4.0.2)
34+
activemodel (~> 4.0)
35+
moped (~> 2.0.0)
36+
origin (~> 2.1)
37+
tzinfo (>= 0.3.37)
38+
moped (2.0.7)
39+
bson (~> 3.0)
40+
connection_pool (~> 2.0)
41+
optionable (~> 0.2.0)
42+
optionable (0.2.0)
43+
origin (2.3.0)
44+
pry (0.10.4)
45+
coderay (~> 1.1.0)
46+
method_source (~> 0.8.1)
47+
slop (~> 3.4)
48+
rake (12.0.0)
49+
rspec (3.5.0)
50+
rspec-core (~> 3.5.0)
51+
rspec-expectations (~> 3.5.0)
52+
rspec-mocks (~> 3.5.0)
53+
rspec-core (3.5.4)
54+
rspec-support (~> 3.5.0)
55+
rspec-expectations (3.5.0)
56+
diff-lcs (>= 1.2.0, < 2.0)
57+
rspec-support (~> 3.5.0)
58+
rspec-given (3.8.0)
59+
given_core (= 3.8.0)
60+
rspec (>= 2.14.0)
61+
rspec-mocks (3.5.0)
62+
diff-lcs (>= 1.2.0, < 2.0)
63+
rspec-support (~> 3.5.0)
64+
rspec-support (3.5.0)
65+
simplecov (0.12.0)
66+
docile (~> 1.1.0)
67+
json (>= 1.8, < 3)
68+
simplecov-html (~> 0.10.0)
69+
simplecov-html (0.10.0)
70+
slop (3.6.0)
71+
sorcerer (1.0.2)
72+
thread_safe (0.3.5)
73+
tomparse (0.4.2)
74+
tzinfo (1.2.2)
75+
thread_safe (~> 0.1)
76+
yard (0.9.7)
77+
yard-tomdoc (0.7.1)
78+
tomparse (>= 0.4.0)
79+
yard
80+
81+
PLATFORMS
82+
ruby
83+
84+
DEPENDENCIES
85+
bundler
86+
codeclimate-test-reporter
87+
mongoid (~> 4.0.2)
88+
mongoid_includes!
89+
pry
90+
rake
91+
rspec-given (~> 3.5)
92+
yard
93+
yard-tomdoc
94+
95+
BUNDLED WITH
96+
1.12.5

gemfiles/mongoid6.gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ gemspec path: '..'
55
gem 'bundler'
66
gem 'rake'
77
gem 'pry'
8-
gem 'mongoid', github: 'mongodb/mongoid', ref: '7c2ff52a0c5292b8e6bf3a9a29bbb19abae3dd5f'
8+
gem 'mongoid', '~> 6.0.3'
99

1010
group :test do
1111
gem 'rspec-given', '~> 3.5'

gemfiles/mongoid6.gemfile.lock

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
PATH
2+
remote: ..
3+
specs:
4+
mongoid_includes (1.1.3)
5+
mongoid (>= 4.0.0, < 7.0.0)
6+
7+
GEM
8+
remote: https://rubygems.org/
9+
specs:
10+
activemodel (5.0.0.1)
11+
activesupport (= 5.0.0.1)
12+
activesupport (5.0.0.1)
13+
concurrent-ruby (~> 1.0, >= 1.0.2)
14+
i18n (~> 0.7)
15+
minitest (~> 5.1)
16+
tzinfo (~> 1.1)
17+
bson (4.2.0)
18+
codeclimate-test-reporter (1.0.3)
19+
simplecov
20+
coderay (1.1.1)
21+
concurrent-ruby (1.0.2)
22+
diff-lcs (1.2.5)
23+
docile (1.1.5)
24+
given_core (3.8.0)
25+
sorcerer (>= 0.3.7)
26+
i18n (0.7.0)
27+
json (2.0.2)
28+
method_source (0.8.2)
29+
minitest (5.10.1)
30+
mongo (2.4.0)
31+
bson (~> 4.2.0)
32+
mongoid (6.0.3)
33+
activemodel (~> 5.0)
34+
mongo (~> 2.3)
35+
pry (0.10.4)
36+
coderay (~> 1.1.0)
37+
method_source (~> 0.8.1)
38+
slop (~> 3.4)
39+
rake (12.0.0)
40+
rspec (3.5.0)
41+
rspec-core (~> 3.5.0)
42+
rspec-expectations (~> 3.5.0)
43+
rspec-mocks (~> 3.5.0)
44+
rspec-core (3.5.4)
45+
rspec-support (~> 3.5.0)
46+
rspec-expectations (3.5.0)
47+
diff-lcs (>= 1.2.0, < 2.0)
48+
rspec-support (~> 3.5.0)
49+
rspec-given (3.8.0)
50+
given_core (= 3.8.0)
51+
rspec (>= 2.14.0)
52+
rspec-mocks (3.5.0)
53+
diff-lcs (>= 1.2.0, < 2.0)
54+
rspec-support (~> 3.5.0)
55+
rspec-support (3.5.0)
56+
simplecov (0.12.0)
57+
docile (~> 1.1.0)
58+
json (>= 1.8, < 3)
59+
simplecov-html (~> 0.10.0)
60+
simplecov-html (0.10.0)
61+
slop (3.6.0)
62+
sorcerer (1.0.2)
63+
thread_safe (0.3.5)
64+
tomparse (0.4.2)
65+
tzinfo (1.2.2)
66+
thread_safe (~> 0.1)
67+
yard (0.9.5)
68+
yard-tomdoc (0.7.1)
69+
tomparse (>= 0.4.0)
70+
yard
71+
72+
PLATFORMS
73+
ruby
74+
75+
DEPENDENCIES
76+
bundler
77+
codeclimate-test-reporter
78+
mongoid (~> 6.0.3)
79+
mongoid_includes!
80+
pry
81+
rake
82+
rspec-given (~> 3.5)
83+
yard
84+
yard-tomdoc
85+
86+
BUNDLED WITH
87+
1.12.5

lib/mongoid/includes/eager_load.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ module EagerLoad
66

77
# Override: Partitions the inclusions into the different types.
88
def eager_load(docs)
9-
return false unless eager_loadable?
10-
11-
nested_inclusions, inclusions = criteria.inclusions.partition(&:nested?)
12-
polymorphic_inclusions, inclusions = inclusions.partition(&:polymorphic_belongs_to?)
13-
full_preload(docs, inclusions, polymorphic_inclusions, nested_inclusions)
9+
if eager_loadable?
10+
nested_inclusions, inclusions = criteria.inclusions.partition(&:nested?)
11+
polymorphic_inclusions, inclusions = inclusions.partition(&:polymorphic_belongs_to?)
12+
full_preload(docs, inclusions, polymorphic_inclusions, nested_inclusions)
13+
end
1414

15-
self.eager_loaded = true
15+
docs
1616
end
1717

1818
# Internal: Performs the normal inclusions first, which allows to perform

spec/mongoid/includes/simple_inclusions_spec.rb

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,6 @@ class D
306306
end
307307
end
308308

309-
it 'does not eager load the first document' do
310-
doc = criteria.first
311-
expect_query(1) do
312-
expect(doc.person).to eq(person)
313-
end
314-
end
315-
316309
it 'returns the last document' do
317310
expect(document).to eq(post_two)
318311
end
@@ -368,13 +361,6 @@ class D
368361
end
369362
end
370363

371-
it 'does not eager load the last document' do
372-
doc = criteria.last
373-
expect_query(1) do
374-
expect(doc.band).to eq(tool)
375-
end
376-
end
377-
378364
it 'returns the document' do
379365
expect(document).to eq(address_one)
380366
end
@@ -400,13 +386,6 @@ class D
400386
end
401387
end
402388

403-
it 'does not eager load the first document' do
404-
doc = criteria.first
405-
expect_query(1) do
406-
expect(doc.band).to eq(depeche)
407-
end
408-
end
409-
410389
it 'returns the document' do
411390
expect(document).to eq(address_two)
412391
end
@@ -500,7 +479,7 @@ class D
500479
end
501480

502481
before do
503-
expect(new_context).to receive(:eager_load_one).with(person).once.and_call_original
482+
expect(new_context).to receive(:eager_load).with([person]).once.and_call_original
504483
end
505484

506485
let!(:from_db) do
@@ -551,7 +530,7 @@ class D
551530
end
552531

553532
before do
554-
expect(context).to receive(:eager_load_one).with(person).once.and_call_original
533+
expect(context).to receive(:eager_load).with([person]).once.and_call_original
555534
end
556535

557536
let!(:from_db) do
@@ -914,7 +893,7 @@ class D
914893
end
915894

916895
before do
917-
expect(context).to receive(:eager_load).with([ game_one, game_two ]).once.and_call_original
896+
expect(context).to receive(:preload).twice.and_call_original
918897
end
919898

920899
let!(:documents) do
@@ -977,7 +956,7 @@ class D
977956
end
978957

979958
before do
980-
expect(context).to receive(:eager_load).with([ person ]).once.and_call_original
959+
expect(context).to receive(:preload).twice.and_call_original
981960
end
982961

983962
let!(:documents) do

0 commit comments

Comments
 (0)