mongoid_includes 3.0.2 → 4.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.
@@ -56,5 +56,117 @@ describe Mongoid::Includes::Criteria do
56
56
  }.to raise_error(Mongoid::Includes::Errors::InvalidPolymorphicIncludes)
57
57
  end
58
58
  end
59
+
60
+ context 'eager loading polymorphic belongs_to associations with multiple concrete types' do
61
+ before(:context) do
62
+ class Main
63
+ include Mongoid::Document
64
+ belongs_to :related, polymorphic: true, optional: true
65
+ end
66
+
67
+ class Related
68
+ include Mongoid::Document
69
+ has_one :parent, as: :related
70
+ end
71
+
72
+ class Two < Related; end
73
+ class Three < Related; end
74
+ end
75
+
76
+ after(:context) do
77
+ %i[Main Related Two Three].each do |const|
78
+ Object.send(:remove_const, const) if Object.const_defined?(const, false)
79
+ end
80
+ end
81
+
82
+ it 'loads the related documents for each concrete type without raising' do
83
+ Main.create!(related: Two.create!)
84
+ Main.create!(related: Three.create!)
85
+
86
+ loaded = nil
87
+ expect { loaded = Main.includes(:related).entries }.not_to raise_error
88
+ expect(loaded.map { |doc| doc.related.class }).to match_array([Two, Three])
89
+ expect { Main.last.related.id }.not_to raise_error
90
+ end
91
+ end
92
+
93
+ context 'polymorphic eager loading in a fresh Ruby process' do
94
+ let(:project_root) { File.expand_path('../../..', __dir__) }
95
+
96
+ it 'does not error when includes is evaluated from the CLI' do
97
+ require 'open3'
98
+
99
+ database_name = "mongoid_includes_spec_#{SecureRandom.hex(6)}"
100
+ base_script = <<~RUBY
101
+ require 'bundler/setup'
102
+ require 'mongoid'
103
+ require 'mongoid_includes'
104
+
105
+ Mongoid.load_configuration(
106
+ clients: {
107
+ default: {
108
+ database: '#{database_name}',
109
+ hosts: %w[localhost:27017]
110
+ }
111
+ }
112
+ )
113
+
114
+ class Main
115
+ include Mongoid::Document
116
+ belongs_to :related, polymorphic: true, optional: true
117
+ end
118
+
119
+ class Related
120
+ include Mongoid::Document
121
+ has_one :parent, as: :related
122
+ end
123
+
124
+ class Two < Related; end
125
+ class Three < Related; end
126
+ RUBY
127
+
128
+ init_script = base_script + <<~RUBY
129
+ client = Mongoid::Clients.default
130
+ begin
131
+ client.database.drop
132
+ rescue Mongo::Error::OperationFailure
133
+ end
134
+
135
+ Main.destroy_all
136
+ Related.destroy_all
137
+
138
+ Main.create!(related: Two.create!)
139
+ Main.create!(related: Three.create!)
140
+ RUBY
141
+
142
+ bad_script = base_script + <<~RUBY
143
+ Main.includes(:related).entries
144
+ Main.last.related.id
145
+
146
+ Mongoid::Clients.default.database.drop
147
+ RUBY
148
+
149
+ bundle_gemfile = ENV.fetch(
150
+ 'BUNDLE_GEMFILE',
151
+ File.join(project_root, 'Gemfile')
152
+ )
153
+
154
+ run_script = lambda do |script|
155
+ Open3.capture2e(
156
+ { 'BUNDLE_GEMFILE' => bundle_gemfile },
157
+ RbConfig.ruby,
158
+ '-',
159
+ chdir: project_root,
160
+ stdin_data: script
161
+ )
162
+ end
163
+
164
+ init_out, init_status = run_script.call(init_script)
165
+ expect(init_status).to be_success, "failed to prepare polymorphic data: #{init_out}"
166
+
167
+ bad_out, bad_status = run_script.call(bad_script)
168
+ expect(bad_status).to be_success, "expected CLI reproduction to succeed, got #{bad_status.exitstatus}: #{bad_out}"
169
+ end
170
+ end
59
171
  end
60
172
  end
data/spec/spec_helper.rb CHANGED
@@ -54,3 +54,5 @@ RSpec.configure do |config|
54
54
  Mongoid.purge!
55
55
  end
56
56
  end
57
+
58
+ Time.zone = 'UTC'
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_includes
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Máximo Mussini
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2022-11-04 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: mongoid
@@ -16,20 +15,20 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: 7.0.10
18
+ version: 8.0.0
20
19
  - - "<"
21
20
  - !ruby/object:Gem::Version
22
- version: 9.0.0
21
+ version: 10.0.0
23
22
  type: :runtime
24
23
  prerelease: false
25
24
  version_requirements: !ruby/object:Gem::Requirement
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- version: 7.0.10
28
+ version: 8.0.0
30
29
  - - "<"
31
30
  - !ruby/object:Gem::Version
32
- version: 9.0.0
31
+ version: 10.0.0
33
32
  description: Mongoid::Includes improves eager loading in Mongoid, supporting polymorphic
34
33
  associations, and up to two-levels of eager loading.
35
34
  email:
@@ -38,7 +37,6 @@ executables: []
38
37
  extensions: []
39
38
  extra_rdoc_files: []
40
39
  files:
41
- - CHANGELOG.md
42
40
  - LICENSE.txt
43
41
  - README.md
44
42
  - Rakefile
@@ -77,11 +75,10 @@ files:
77
75
  - spec/support/models/preference.rb
78
76
  - spec/support/models/record.rb
79
77
  - spec/support/models/song.rb
80
- homepage: https://github.com/ElMassimo/mongoid_includes
78
+ homepage: https://github.com/cacheventures/mongoid_includes
81
79
  licenses:
82
80
  - MIT
83
81
  metadata: {}
84
- post_install_message:
85
82
  rdoc_options:
86
83
  - "--charset=UTF-8"
87
84
  require_paths:
@@ -97,8 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
94
  - !ruby/object:Gem::Version
98
95
  version: '0'
99
96
  requirements: []
100
- rubygems_version: 3.2.32
101
- signing_key:
97
+ rubygems_version: 3.6.9
102
98
  specification_version: 4
103
99
  summary: Improved eager loading support for Mongoid.
104
100
  test_files:
data/CHANGELOG.md DELETED
@@ -1,54 +0,0 @@
1
- ## Mongoid::Includes 3.0.2 (2022-11-03) ##
2
-
3
- * [perf: avoid queries when foreign keys are empty](https://github.com/ElMassimo/mongoid_includes/commit/9f4c0c8bf1560a319c663fae77015c638caec56b)
4
-
5
- ## Mongoid::Includes 3.0.1 (2022-11-03) ##
6
-
7
- * Allow installing this library with Mongoid `8.0`.
8
-
9
- ## Mongoid::Includes 3.0.0 (2020-10-29) ##
10
-
11
- * Add support for Mongoid `7.1`.
12
- * Avoid making a query when the foreign keys are empty.
13
-
14
- ## Mongoid::Includes 2.1.0 (2017-07-03) ##
15
-
16
- * Fix bug where `includes` ignores the `:with` option if the association is polymorphic. Thanks @nickcherry for the bug report!
17
-
18
- ## Mongoid::Includes 2.0.0 (2017-01-10) ##
19
-
20
- * Support Mongoid 6.0.1, fixes related to [changes in Mongoid internals](https://github.com/mongodb/mongoid/pull/4326). Thanks @mityakoval and @forumd for the bug reports!
21
-
22
- ## Mongoid::Includes 1.1.3 (2016-10-17) ##
23
-
24
- * Fix eager loading for [self-referencing associations](https://github.com/ElMassimo/mongoid_includes/pull/6). Thanks @rmachielse!
25
-
26
- ## Mongoid::Includes 1.1.2 (2016-05-26) ##
27
-
28
- * Change gem dependencies to [support Mongoid 6](https://github.com/ElMassimo/mongoid_includes/pull/3). Thanks @joostverdoorn!
29
-
30
- ## Mongoid::Includes 1.1.1 (2016-01-12) ##
31
-
32
- * Fix bug with nested includes when the related document is `nil`.
33
-
34
- ## Mongoid::Includes 1.1.0 (2015-11-04) ##
35
-
36
- * Fix bug with optional polymorphic `belongs_to` relations where the name of the relation does not match an actual class name.
37
-
38
- ## Mongoid::Includes 1.0.3 (2015-10-10) ##
39
-
40
- * Add support for Mongoid 5.
41
-
42
- ## Mongoid::Includes 1.0.2 (2015-10-08) ##
43
-
44
- * Fix error when using `merge` or `merge!` with a criteria and `includes`.
45
- * Replace the internal structure with a Set to be more robust when avoiding duplicate relations.
46
-
47
- ## Mongoid::Includes 1.0.1 (August 5, 2015) ##
48
-
49
- * Fix error messages for polymorphic includes.
50
- * Add :with option that receives the criteria that will be used to include documents.
51
-
52
- ## Mongoid::Includes 1.0.0 (July 30, 2015) ##
53
-
54
- * Initial Version.