mongoid 7.1.5 → 7.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +1 -1
  5. data/Rakefile +33 -7
  6. data/lib/mongoid/association/referenced/has_one/proxy.rb +6 -1
  7. data/lib/mongoid/attributes.rb +8 -1
  8. data/lib/mongoid/criteria/queryable/selector.rb +0 -4
  9. data/lib/mongoid/document.rb +3 -2
  10. data/lib/mongoid/errors/mongoid_error.rb +1 -1
  11. data/lib/mongoid/interceptable.rb +3 -1
  12. data/lib/mongoid/reloadable.rb +5 -0
  13. data/lib/mongoid/validatable/associated.rb +1 -1
  14. data/lib/mongoid/validatable/presence.rb +3 -3
  15. data/lib/mongoid/validatable/uniqueness.rb +1 -1
  16. data/lib/mongoid/version.rb +1 -1
  17. data/lib/rails/generators/mongoid/config/config_generator.rb +8 -1
  18. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +1 -1
  19. data/spec/app/models/customer.rb +11 -0
  20. data/spec/app/models/customer_address.rb +12 -0
  21. data/spec/app/models/dictionary.rb +6 -0
  22. data/spec/app/models/person.rb +2 -0
  23. data/spec/app/models/series.rb +1 -0
  24. data/spec/app/models/wiki_page.rb +1 -0
  25. data/spec/integration/app_spec.rb +178 -88
  26. data/spec/integration/associations/embeds_many_spec.rb +24 -0
  27. data/spec/integration/associations/embeds_one_spec.rb +24 -0
  28. data/spec/integration/associations/has_many_spec.rb +42 -0
  29. data/spec/integration/associations/has_one_spec.rb +42 -0
  30. data/spec/integration/callbacks_models.rb +49 -0
  31. data/spec/integration/callbacks_spec.rb +216 -0
  32. data/spec/integration/document_spec.rb +21 -0
  33. data/spec/lite_spec_helper.rb +6 -6
  34. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +50 -0
  35. data/spec/mongoid/atomic/paths_spec.rb +41 -0
  36. data/spec/mongoid/attributes_spec.rb +241 -0
  37. data/spec/mongoid/contextual/atomic_spec.rb +17 -4
  38. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +36 -0
  39. data/spec/mongoid/document_query_spec.rb +51 -0
  40. data/spec/mongoid/errors/mongoid_error_spec.rb +20 -8
  41. data/spec/mongoid/factory_spec.rb +2 -2
  42. data/spec/mongoid/persistable/savable_spec.rb +4 -4
  43. data/spec/mongoid/persistable/settable_spec.rb +30 -0
  44. data/spec/mongoid/persistable_spec.rb +2 -2
  45. data/spec/shared/LICENSE +20 -0
  46. data/spec/shared/bin/get-mongodb-download-url +17 -0
  47. data/spec/shared/bin/s3-copy +45 -0
  48. data/spec/shared/bin/s3-upload +69 -0
  49. data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
  50. data/spec/shared/lib/mrss/cluster_config.rb +226 -0
  51. data/spec/shared/lib/mrss/constraints.rb +368 -0
  52. data/spec/shared/lib/mrss/docker_runner.rb +271 -0
  53. data/spec/shared/lib/mrss/lite_constraints.rb +191 -0
  54. data/spec/shared/lib/mrss/server_version_registry.rb +115 -0
  55. data/spec/shared/lib/mrss/spec_organizer.rb +179 -0
  56. data/spec/shared/lib/mrss/utils.rb +15 -0
  57. data/spec/shared/share/Dockerfile.erb +322 -0
  58. data/spec/shared/share/haproxy-1.conf +16 -0
  59. data/spec/shared/share/haproxy-2.conf +17 -0
  60. data/spec/shared/shlib/distro.sh +73 -0
  61. data/spec/shared/shlib/server.sh +317 -0
  62. data/spec/shared/shlib/set_env.sh +131 -0
  63. data/spec/spec_helper.rb +3 -1
  64. data/spec/support/constraints.rb +0 -226
  65. data/spec/support/spec_config.rb +8 -0
  66. metadata +538 -493
  67. metadata.gz.sig +0 -0
  68. data/spec/support/child_process_helper.rb +0 -76
  69. data/spec/support/lite_constraints.rb +0 -22
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ require 'spec_helper'
5
+
6
+ describe 'embeds_many associations' do
7
+
8
+ context 're-associating the same object' do
9
+ context 'with dependent: destroy' do
10
+ let(:canvas) do
11
+ Canvas.create!(shapes: [Shape.new])
12
+ end
13
+
14
+ let!(:shape) { canvas.shapes.first }
15
+
16
+ it 'does not destroy the dependent object' do
17
+ canvas.shapes = [shape]
18
+ canvas.save!
19
+ canvas.reload
20
+ canvas.shapes.should == [shape]
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ require 'spec_helper'
5
+
6
+ describe 'embeds_one associations' do
7
+
8
+ context 're-associating the same object' do
9
+ context 'with dependent: destroy' do
10
+ let(:canvas) do
11
+ Canvas.create!(palette: Palette.new)
12
+ end
13
+
14
+ let!(:palette) { canvas.palette }
15
+
16
+ it 'does not destroy the dependent object' do
17
+ canvas.palette = canvas.palette
18
+ canvas.save!
19
+ canvas.reload
20
+ canvas.palette.should == palette
21
+ end
22
+ end
23
+ end
24
+ end
@@ -31,4 +31,46 @@ describe 'has_many associations' do
31
31
  Album.count.should == 0
32
32
  end
33
33
  end
34
+
35
+ context 're-associating the same object' do
36
+ context 'with dependent: destroy' do
37
+ let(:wiki_page) do
38
+ WikiPage.create!
39
+ end
40
+
41
+ let!(:comment) do
42
+ Comment.create!(wiki_page: wiki_page, title: 'hi') do
43
+ wiki_page.reload
44
+ end
45
+ end
46
+
47
+ it 'does not destroy the dependent object' do
48
+ wiki_page.comments.should == [comment]
49
+ wiki_page.comments = [comment]
50
+ wiki_page.save!
51
+ wiki_page.reload
52
+ wiki_page.comments.should == [comment]
53
+ end
54
+ end
55
+
56
+ context 'without dependent: destroy' do
57
+ let(:series) do
58
+ Series.create!
59
+ end
60
+
61
+ let!(:book) do
62
+ Book.create!(series: series).tap do
63
+ series.reload
64
+ end
65
+ end
66
+
67
+ it 'does not destroy the dependent object' do
68
+ series.books.should == [book]
69
+ series.books = [book]
70
+ series.save!
71
+ series.reload
72
+ series.books.should == [book]
73
+ end
74
+ end
75
+ end
34
76
  end
@@ -31,4 +31,46 @@ describe 'has_one associations' do
31
31
  Game.count.should == 0
32
32
  end
33
33
  end
34
+
35
+ context 're-associating the same object' do
36
+ context 'with dependent: destroy' do
37
+ let(:person) do
38
+ Person.create!
39
+ end
40
+
41
+ let!(:game) do
42
+ Game.create!(person: person) do
43
+ person.reload
44
+ end
45
+ end
46
+
47
+ it 'does not destroy the dependent object' do
48
+ person.game.should == game
49
+ person.game = person.game
50
+ person.save!
51
+ person.reload
52
+ person.game.should == game
53
+ end
54
+ end
55
+
56
+ context 'without dependent: destroy' do
57
+ let(:person) do
58
+ Person.create!
59
+ end
60
+
61
+ let!(:account) do
62
+ Account.create!(person: person, name: 'foo').tap do
63
+ person.reload
64
+ end
65
+ end
66
+
67
+ it 'does not destroy the dependent object' do
68
+ person.account.should == account
69
+ person.account = person.account
70
+ person.save!
71
+ person.reload
72
+ person.account.should == account
73
+ end
74
+ end
75
+ end
34
76
  end
@@ -0,0 +1,49 @@
1
+ class Galaxy
2
+ include Mongoid::Document
3
+
4
+ field :age, type: Integer
5
+
6
+ before_validation :set_age
7
+
8
+ embeds_many :stars
9
+
10
+ private
11
+
12
+ def set_age
13
+ self.age ||= 100_000
14
+ end
15
+ end
16
+
17
+ class Star
18
+ include Mongoid::Document
19
+
20
+ embedded_in :galaxy
21
+
22
+ field :age, type: Integer
23
+
24
+ before_validation :set_age
25
+
26
+ embeds_many :planets
27
+
28
+ private
29
+
30
+ def set_age
31
+ self.age ||= 42_000
32
+ end
33
+ end
34
+
35
+ class Planet
36
+ include Mongoid::Document
37
+
38
+ embedded_in :star
39
+
40
+ field :age, type: Integer
41
+
42
+ before_validation :set_age
43
+
44
+ private
45
+
46
+ def set_age
47
+ self.age ||= 2_000
48
+ end
49
+ end
@@ -0,0 +1,216 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ require 'spec_helper'
5
+ require_relative './callbacks_models'
6
+
7
+ describe 'callbacks integration tests' do
8
+ context 'when modifying attributes in a callback' do
9
+
10
+ context 'when creating top-level document' do
11
+ context 'top level document' do
12
+ let(:instance) do
13
+ Galaxy.create!
14
+ end
15
+
16
+ it 'writes the attribute value into the model' do
17
+ instance.age.should == 100_000
18
+ end
19
+
20
+ it 'persists the attribute value' do
21
+ Galaxy.find(instance.id).age.should == 100_000
22
+ end
23
+ end
24
+
25
+ context 'embedded document' do
26
+ shared_examples 'persists the attribute value' do
27
+ it 'writes the attribute value into the model' do
28
+ instance.stars.first.age.should == 42_000
29
+ end
30
+
31
+ it 'persists the attribute value' do
32
+ Galaxy.find(instance.id).stars.first.age.should == 42_000
33
+ end
34
+ end
35
+
36
+ context 'set as a document instance' do
37
+ let(:instance) do
38
+ Galaxy.create!(stars: [Star.new])
39
+ end
40
+
41
+ include_examples 'persists the attribute value'
42
+ end
43
+
44
+ context 'set as attributes on parent' do
45
+ let(:instance) do
46
+ Galaxy.create!(stars: [{}])
47
+ end
48
+
49
+ include_examples 'persists the attribute value'
50
+ end
51
+ end
52
+
53
+ context 'nested embedded document' do
54
+ shared_examples 'persists the attribute value' do
55
+ it 'writes the attribute value into the model' do
56
+ instance.stars.first.planets.first.age.should == 2_000
57
+ end
58
+
59
+ it 'persists the attribute value' do
60
+ Galaxy.find(instance.id).stars.first.planets.first.age.should == 2_000
61
+ end
62
+ end
63
+
64
+ context 'set as a document instance' do
65
+ let(:instance) do
66
+ Galaxy.create!(stars: [Star.new(
67
+ planets: [Planet.new],
68
+ )])
69
+ end
70
+
71
+ include_examples 'persists the attribute value'
72
+ end
73
+
74
+ context 'set as attributes on parent' do
75
+ let(:instance) do
76
+ Galaxy.create!(stars: [
77
+ planets: [{}],
78
+ ])
79
+ end
80
+
81
+ include_examples 'persists the attribute value'
82
+ end
83
+ end
84
+ end
85
+
86
+ context 'when updating top-level document via #save' do
87
+ let!(:instance) do
88
+ Galaxy.create!
89
+ end
90
+
91
+ context 'embedded document' do
92
+ shared_examples 'persists the attribute value' do
93
+ it 'writes the attribute value into the model' do
94
+ instance.stars.first.age.should == 42_000
95
+ end
96
+
97
+ it 'persists the attribute value' do
98
+ Galaxy.find(instance.id).stars.first.age.should == 42_000
99
+ end
100
+ end
101
+
102
+ context 'set as a document instance' do
103
+ before do
104
+ instance.stars = [Star.new]
105
+ instance.save!
106
+ end
107
+
108
+ include_examples 'persists the attribute value'
109
+ end
110
+
111
+ context 'set as attributes on parent' do
112
+ before do
113
+ instance.stars = [{}]
114
+ instance.save!
115
+ end
116
+
117
+ include_examples 'persists the attribute value'
118
+ end
119
+ end
120
+
121
+ context 'nested embedded document' do
122
+ shared_examples 'persists the attribute value' do
123
+ it 'writes the attribute value into the model' do
124
+ instance.stars.first.planets.first.age.should == 2_000
125
+ end
126
+
127
+ it 'persists the attribute value' do
128
+ Galaxy.find(instance.id).stars.first.planets.first.age.should == 2_000
129
+ end
130
+ end
131
+
132
+ context 'set as a document instance' do
133
+ before do
134
+ instance.stars = [Star.new(planets: [Planet.new])]
135
+ instance.save!
136
+ end
137
+
138
+ include_examples 'persists the attribute value'
139
+ end
140
+
141
+ context 'set as attributes on parent' do
142
+ before do
143
+ instance.stars = [planets: [{}]]
144
+ instance.save!
145
+ end
146
+
147
+ include_examples 'persists the attribute value'
148
+ end
149
+ end
150
+ end
151
+
152
+ context 'when updating top-level document via #update_attributes' do
153
+ let!(:instance) do
154
+ Galaxy.create!
155
+ end
156
+
157
+ context 'embedded document' do
158
+ shared_examples 'persists the attribute value' do
159
+ it 'writes the attribute value into the model' do
160
+ instance.stars.first.age.should == 42_000
161
+ end
162
+
163
+ it 'persists the attribute value' do
164
+ Galaxy.find(instance.id).stars.first.age.should == 42_000
165
+ end
166
+ end
167
+
168
+ context 'set as a document instance' do
169
+ before do
170
+ instance.update_attributes(stars: [Star.new])
171
+ end
172
+
173
+ include_examples 'persists the attribute value'
174
+ end
175
+
176
+ context 'set as attributes on parent' do
177
+ before do
178
+ instance.update_attributes(stars: [{}])
179
+ end
180
+
181
+ include_examples 'persists the attribute value'
182
+ end
183
+ end
184
+
185
+ context 'nested embedded document' do
186
+ shared_examples 'persists the attribute value' do
187
+ it 'writes the attribute value into the model' do
188
+ instance.stars.first.planets.first.age.should == 2_000
189
+ end
190
+
191
+ it 'persists the attribute value' do
192
+ pending 'MONGOID-4476'
193
+
194
+ Galaxy.find(instance.id).stars.first.planets.first.age.should == 2_000
195
+ end
196
+ end
197
+
198
+ context 'set as a document instance' do
199
+ before do
200
+ instance.update_attributes(stars: [Star.new(planets: [Planet.new])])
201
+ end
202
+
203
+ include_examples 'persists the attribute value'
204
+ end
205
+
206
+ context 'set as attributes on parent' do
207
+ before do
208
+ instance.update_attributes(stars: [planets: [{}]])
209
+ end
210
+
211
+ include_examples 'persists the attribute value'
212
+ end
213
+ end
214
+ end
215
+ end
216
+ end
@@ -19,4 +19,25 @@ describe Mongoid::Document do
19
19
  DelegatingPatient.default_client.should be Mongoid.default_client
20
20
  end
21
21
  end
22
+
23
+ describe '#reload' do
24
+ context 'when changing shard key value' do
25
+ require_topology :sharded
26
+
27
+ let(:profile) do
28
+ # Profile shard_key :name
29
+ Profile.create!(name: "Alice")
30
+ end
31
+
32
+ it "successfully reloads the document after saving an update to the sharded field" do
33
+ expect(profile.name).to eq("Alice")
34
+ profile.name = "Bob"
35
+ profile.save!
36
+
37
+ profile.reload
38
+
39
+ expect(profile.name).to eq("Bob")
40
+ end
41
+ end
42
+ end
22
43
  end
@@ -3,6 +3,7 @@
3
3
 
4
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
5
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "shared", "lib"))
6
7
 
7
8
  # Load byebug before mongoid, to place breakpoints in the lib methods.
8
9
  # But SpecConfig needs the driver code - require the driver here.
@@ -15,7 +16,7 @@ require "mongo"
15
16
  require 'pp'
16
17
 
17
18
  require 'support/spec_config'
18
- require 'support/lite_constraints'
19
+ require 'mrss/lite_constraints'
19
20
  require "support/session_registry"
20
21
 
21
22
  unless SpecConfig.instance.ci?
@@ -50,11 +51,10 @@ RSpec.configure do |config|
50
51
  config.add_formatter(RSpec::Core::Formatters::JsonFormatter, File.join(File.dirname(__FILE__), '../tmp/rspec.json'))
51
52
  end
52
53
 
53
- if SpecConfig.instance.ci?
54
+ if SpecConfig.instance.ci? && !%w(1 true yes).include?(ENV['INTERACTIVE']&.downcase)
54
55
  timeout = if SpecConfig.instance.app_tests?
55
- # Allow 5 minutes per test for the app tests, since they install
56
- # gems for Rails applications which can take a long time.
57
- 300
56
+ # App tests under JRuby take a REALLY long time (over 5 minutes per test).
57
+ 500
58
58
  else
59
59
  # Allow a max of 30 seconds per test.
60
60
  # Tests should take under 10 seconds ideally but it seems
@@ -68,7 +68,7 @@ RSpec.configure do |config|
68
68
  end
69
69
  end
70
70
 
71
- config.extend(LiteConstraints)
71
+ config.extend(Mrss::LiteConstraints)
72
72
  end
73
73
 
74
74
  # require all shared examples