mongoid 7.1.7 → 7.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93d8b658e53d12f1deb7a131e3d58155fead7576955078187f3b3181072c193f
4
- data.tar.gz: 35e629224f7495969e5a695a9641043ad61b92d61b57926b1d1956bd2f5e1d7c
3
+ metadata.gz: 3031b4d96e1f46535064f6f7a2c6ee4147f44fa720b04d2efc471b48719a223b
4
+ data.tar.gz: 4db94d4b166a4bc7c48af8f4e767f9be5fd8565f98f655eb836407c3034d45cf
5
5
  SHA512:
6
- metadata.gz: 33920733722a4da26c23190788ef198d86d0d3edfcedc3d53bc7364d9abfbda7c54634af875c678757745c1d18b225457ef8e0a5b5711db7e76b93350548d14b
7
- data.tar.gz: cb0acea4219ce1972fe67b63f988b0f31197ab44142288e5af4fe84e63f602dbc9b7dcc23edbf54cc5e465288c23346f62d3cf0632e0b37a59fabc6acb1c6925
6
+ metadata.gz: 9368cdc3d7a4c906f8e7bea921f842206f2ab0d0528cbf7347369ded0c8a764eb27ed3f024172260a10fed0381bea6c1675e526db776d20df9b3115b783bf968
7
+ data.tar.gz: 48f50ca2cad671d5861114faa61f8c3d67758c6fa646bf415bab9dd6168acac0ed3447eda81dc0995bcf6a23e44ba4c0727fc5d03d713f5032b221c5331d2c5a
checksums.yaml.gz.sig CHANGED
Binary file
data/Rakefile CHANGED
@@ -4,8 +4,13 @@ require "bundler"
4
4
  require "bundler/gem_tasks"
5
5
  Bundler.setup
6
6
 
7
+ ROOT = File.expand_path(File.join(File.dirname(__FILE__)))
8
+
9
+ $: << File.join(ROOT, 'spec/shared/lib')
10
+
7
11
  require "rake"
8
12
  require "rspec/core/rake_task"
13
+ require 'mrss/spec_organizer'
9
14
 
10
15
  $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
11
16
  require "mongoid/version"
@@ -35,6 +40,32 @@ RSpec::Core::RakeTask.new('spec:progress') do |spec|
35
40
  spec.pattern = "spec/**/*_spec.rb"
36
41
  end
37
42
 
43
+ CLASSIFIERS = [
44
+ [%r,^mongoid/attribute,, :attributes],
45
+ [%r,^mongoid/association/[or],, :associations_referenced],
46
+ [%r,^mongoid/association,, :associations],
47
+ [%r,^mongoid,, :unit],
48
+ [%r,^integration,, :integration],
49
+ [%r,^rails,, :rails],
50
+ ]
51
+
52
+ RUN_PRIORITY = %i(
53
+ unit attributes associations_referenced associations
54
+ integration rails
55
+ )
56
+
57
+ def spec_organizer
58
+ Mrss::SpecOrganizer.new(
59
+ root: ROOT,
60
+ classifiers: CLASSIFIERS,
61
+ priority_order: RUN_PRIORITY,
62
+ )
63
+ end
64
+
65
+ task :ci do
66
+ spec_organizer.run
67
+ end
68
+
38
69
  task :default => :spec
39
70
 
40
71
  desc "Generate all documentation"
@@ -160,6 +160,11 @@ module Mongoid
160
160
  # @since 1.0.0
161
161
  def write_attribute(name, value)
162
162
  field_name = database_field_name(name)
163
+
164
+ if attribute_missing?(field_name)
165
+ raise ActiveModel::MissingAttributeError, "Missing attribute: '#{name}'"
166
+ end
167
+
163
168
  if attribute_writable?(field_name)
164
169
  _assigning do
165
170
  validate_attribute_value(field_name, value)
@@ -177,6 +182,8 @@ module Mongoid
177
182
  end
178
183
  typed_value
179
184
  end
185
+ else
186
+ # TODO: MONGOID-5072
180
187
  end
181
188
  end
182
189
  alias :[]= :write_attribute
@@ -294,7 +301,7 @@ module Mongoid
294
301
  def read_raw_attribute(name)
295
302
  normalized = database_field_name(name.to_s)
296
303
  if attribute_missing?(normalized)
297
- raise ActiveModel::MissingAttributeError, "Missing attribute: '#{name}'."
304
+ raise ActiveModel::MissingAttributeError, "Missing attribute: '#{name}'"
298
305
  end
299
306
  if hash_dot_syntax?(normalized)
300
307
  attributes.__nested__(normalized)
@@ -21,6 +21,11 @@ module Mongoid
21
21
  #
22
22
  # @since 1.0.0
23
23
  def reload
24
+ if @atomic_selector
25
+ # Clear atomic_selector cache for sharded clusters. MONGOID-5076
26
+ remove_instance_variable('@atomic_selector')
27
+ end
28
+
24
29
  reloaded = _reload
25
30
  if Mongoid.raise_not_found_error && reloaded.empty?
26
31
  raise Errors::DocumentNotFound.new(self.class, _id, _id)
@@ -2,5 +2,5 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  module Mongoid
5
- VERSION = "7.1.7"
5
+ VERSION = "7.1.8"
6
6
  end
@@ -15,7 +15,14 @@ module Mongoid
15
15
  end
16
16
 
17
17
  def app_name
18
- Rails::Application.subclasses.first.parent.to_s.underscore
18
+ app_cls = Rails.application.class
19
+ parent = begin
20
+ # Rails 6.1+
21
+ app_cls.module_parent_name
22
+ rescue NoMethodError
23
+ app_cls.parent.to_s
24
+ end
25
+ parent.underscore
19
26
  end
20
27
 
21
28
  def create_config_file
@@ -13,109 +13,131 @@ describe 'Mongoid application tests' do
13
13
  end
14
14
 
15
15
  require 'fileutils'
16
- require 'support/child_process_helper'
16
+ require 'mrss/child_process_helper'
17
17
  require 'open-uri'
18
18
 
19
19
  FileUtils.mkdir_p(TMP_BASE)
20
20
  end
21
21
 
22
- context 'demo application - sinatra' do
23
- it 'runs' do
24
- clone_application(
25
- 'https://github.com/mongoid/mongoid-demo',
26
- subdir: 'sinatra-minimal',
27
- ) do
22
+ context 'demo application' do
23
+ context 'sinatra' do
24
+ it 'runs' do
25
+ clone_application(
26
+ 'https://github.com/mongoid/mongoid-demo',
27
+ subdir: 'sinatra-minimal',
28
+ ) do
28
29
 
29
- process = ChildProcess.build(*%w(bundle exec ruby app.rb))
30
- process.environment.update(clean_env)
31
- process.io.inherit!
32
- process.start
33
-
34
- begin
35
30
  # JRuby needs a long timeout
36
- wait_for_port(4567, 20)
37
- sleep 1
38
-
39
- uri = URI.parse('http://localhost:4567/posts')
40
- resp = JSON.parse(uri.open.read)
41
- ensure
42
- Process.kill('TERM', process.pid)
43
- status = process.wait
44
- end
31
+ start_app(%w(bundle exec ruby app.rb), 4567, 40) do |port|
32
+ uri = URI.parse('http://localhost:4567/posts')
33
+ resp = JSON.parse(uri.open.read)
45
34
 
46
- resp.should == []
35
+ resp.should == []
47
36
 
48
- status.should == 0
37
+ end
38
+ end
49
39
  end
50
40
  end
51
- end
52
41
 
53
- context 'demo application - rails-api' do
54
- ['~> 6.0.0'].each do |rails_version|
55
- context "with rails #{rails_version}" do
56
- it 'runs' do
57
- clone_application(
58
- 'https://github.com/mongoid/mongoid-demo',
59
- subdir: 'rails-api',
60
- rails_version: rails_version,
61
- ) do
62
-
63
- process = ChildProcess.build(*%w(bundle exec rails s))
64
- process.environment.update(clean_env)
65
- process.io.inherit!
66
- process.start
67
-
68
- begin
69
- # JRuby needs a long timeout
70
- wait_for_port(3000, 30)
71
- sleep 1
72
-
73
- uri = URI.parse('http://localhost:3000/posts')
74
- resp = JSON.parse(uri.open.read)
75
- ensure
76
- Process.kill('TERM', process.pid)
77
- status = process.wait
78
- end
42
+ context 'rails-api' do
43
+ it 'runs' do
44
+ clone_application(
45
+ 'https://github.com/mongoid/mongoid-demo',
46
+ subdir: 'rails-api',
47
+ ) do
79
48
 
80
- resp.should == []
49
+ # JRuby needs a long timeout
50
+ start_app(%w(bundle exec rails s), 3000, 50) do |port|
51
+ uri = URI.parse('http://localhost:3000/posts')
52
+ resp = JSON.parse(uri.open.read)
81
53
 
82
- # 143 = 128 + 15
83
- [0, 15, 143].should include(status)
54
+ resp.should == []
84
55
  end
85
56
  end
86
57
  end
87
58
  end
88
59
  end
89
60
 
61
+ def start_app(cmd, port, timeout)
62
+ process = ChildProcess.build(*cmd)
63
+ process.environment.update(clean_env)
64
+ process.io.inherit!
65
+ process.start
66
+
67
+ begin
68
+ wait_for_port(port, timeout, process)
69
+ sleep 1
70
+
71
+ rv = yield port
72
+ ensure
73
+ # The process may have already died (due to an error exit) -
74
+ # in this case killing it will raise an exception.
75
+ Process.kill('TERM', process.pid) rescue nil
76
+ status = process.wait
77
+ end
78
+
79
+ # Exit should be either success or SIGTERM
80
+ [0, 15, 128 + 15].should include(status)
81
+
82
+ rv
83
+ end
84
+
90
85
  context 'new application - rails' do
91
- ['~> 5.1.0', '~> 5.2.0', '~> 6.0.0'].each do |rails_version|
92
- context "with rails #{rails_version}" do
93
- it 'creates' do
94
- ChildProcessHelper.check_call(%w(gem uni rails -a))
95
- ChildProcessHelper.check_call(%w(gem install rails --no-document -v) + [rails_version])
96
-
97
- Dir.chdir(TMP_BASE) do
98
- FileUtils.rm_rf('mongoid-test')
99
- ChildProcessHelper.check_call(%w(rails new mongoid-test --skip-spring --skip-active-record), env: clean_env)
100
-
101
- Dir.chdir('mongoid-test') do
102
- adjust_app_gemfile
103
- ChildProcessHelper.check_call(%w(bundle install), env: clean_env)
104
-
105
- ChildProcessHelper.check_call(%w(rails g model post), env: clean_env)
106
- ChildProcessHelper.check_call(%w(rails g model comment post:belongs_to), env: clean_env)
107
-
108
- # https://jira.mongodb.org/browse/MONGOID-4885
109
- comment_text = File.read('app/models/comment.rb')
110
- comment_text.should =~ /belongs_to :post/
111
- comment_text.should_not =~ /embedded_in :post/
112
- end
113
- end
86
+ it 'creates' do
87
+ install_rails
88
+
89
+ Dir.chdir(TMP_BASE) do
90
+ FileUtils.rm_rf('mongoid-test')
91
+ Mrss::ChildProcessHelper.check_call(%w(rails new mongoid-test --skip-spring --skip-active-record), env: clean_env)
92
+
93
+ Dir.chdir('mongoid-test') do
94
+ adjust_app_gemfile
95
+ Mrss::ChildProcessHelper.check_call(%w(bundle install), env: clean_env)
96
+
97
+ Mrss::ChildProcessHelper.check_call(%w(rails g model post), env: clean_env)
98
+ Mrss::ChildProcessHelper.check_call(%w(rails g model comment post:belongs_to), env: clean_env)
99
+
100
+ # https://jira.mongodb.org/browse/MONGOID-4885
101
+ comment_text = File.read('app/models/comment.rb')
102
+ comment_text.should =~ /belongs_to :post/
103
+ comment_text.should_not =~ /embedded_in :post/
104
+ end
105
+ end
106
+ end
107
+
108
+ it 'generates Mongoid config' do
109
+ install_rails
110
+
111
+ Dir.chdir(TMP_BASE) do
112
+ FileUtils.rm_rf('mongoid-test-config')
113
+ Mrss::ChildProcessHelper.check_call(%w(rails new mongoid-test-config --skip-spring --skip-active-record), env: clean_env)
114
+
115
+ Dir.chdir('mongoid-test-config') do
116
+ adjust_app_gemfile
117
+ Mrss::ChildProcessHelper.check_call(%w(bundle install), env: clean_env)
118
+
119
+ mongoid_config_file = File.join(TMP_BASE,'mongoid-test-config/config/mongoid.yml')
120
+
121
+ File.exist?(mongoid_config_file).should be false
122
+ Mrss::ChildProcessHelper.check_call(%w(rails g mongoid:config), env: clean_env)
123
+ File.exist?(mongoid_config_file).should be true
124
+
125
+ config_text = File.read(mongoid_config_file)
126
+ config_text.should =~ /mongoid_test_config_development/
127
+ config_text.should =~ /mongoid_test_config_test/
114
128
  end
115
129
  end
116
130
  end
117
131
  end
118
132
 
133
+ def install_rails
134
+ Mrss::ChildProcessHelper.check_call(%w(gem uni rails -a))
135
+ if (rails_version = SpecConfig.instance.rails_version) == 'master'
136
+ else
137
+ Mrss::ChildProcessHelper.check_call(%w(gem install rails --no-document -v) + [rails_version])
138
+ end
139
+ end
140
+
119
141
  context 'local test applications' do
120
142
  let(:client) { Mongoid.default_client }
121
143
 
@@ -136,7 +158,7 @@ describe 'Mongoid application tests' do
136
158
  before do
137
159
  Dir.chdir(APP_PATH) do
138
160
  remove_bundler_req
139
- ChildProcessHelper.check_call(%w(bundle install), env: env)
161
+ Mrss::ChildProcessHelper.check_call(%w(bundle install), env: env)
140
162
  write_mongoid_yml
141
163
  end
142
164
 
@@ -150,7 +172,7 @@ describe 'Mongoid application tests' do
150
172
  end
151
173
  index.should be nil
152
174
 
153
- ChildProcessHelper.check_call(%w(bundle exec rake db:mongoid:create_indexes),
175
+ Mrss::ChildProcessHelper.check_call(%w(bundle exec rake db:mongoid:create_indexes),
154
176
  cwd: APP_PATH, env: env)
155
177
 
156
178
  index = client['posts'].indexes.detect do |index|
@@ -165,13 +187,14 @@ describe 'Mongoid application tests' do
165
187
  end
166
188
  end
167
189
 
168
- def clone_application(repo_url, subdir: nil, rails_version: nil)
190
+ def clone_application(repo_url, subdir: nil)
169
191
  Dir.chdir(TMP_BASE) do
170
192
  FileUtils.rm_rf(File.basename(repo_url))
171
- ChildProcessHelper.check_call(%w(git clone) + [repo_url])
193
+ Mrss::ChildProcessHelper.check_call(%w(git clone) + [repo_url])
172
194
  Dir.chdir(File.join(*[File.basename(repo_url), subdir].compact)) do
173
- adjust_app_gemfile(rails_version: rails_version)
174
- ChildProcessHelper.check_call(%w(bundle install), env: clean_env)
195
+ adjust_app_gemfile
196
+ adjust_rails_defaults
197
+ Mrss::ChildProcessHelper.check_call(%w(bundle install), env: clean_env)
175
198
  puts `git diff`
176
199
 
177
200
  write_mongoid_yml
@@ -226,7 +249,7 @@ describe 'Mongoid application tests' do
226
249
  end
227
250
  end
228
251
 
229
- def adjust_app_gemfile(rails_version: nil)
252
+ def adjust_app_gemfile(rails_version: SpecConfig.instance.rails_version)
230
253
  remove_bundler_req
231
254
 
232
255
  gemfile_lines = IO.readlines('Gemfile')
@@ -238,13 +261,41 @@ describe 'Mongoid application tests' do
238
261
  gemfile_lines.delete_if do |line|
239
262
  line =~ /rails/
240
263
  end
241
- gemfile_lines << "gem 'rails', '#{rails_version}'\n"
264
+ if rails_version == 'master'
265
+ gemfile_lines << "gem 'rails', git: 'https://github.com/rails/rails'\n"
266
+ else
267
+ gemfile_lines << "gem 'rails', '~> #{rails_version}.0'\n"
268
+ end
242
269
  end
243
270
  File.open('Gemfile', 'w') do |f|
244
271
  f << gemfile_lines.join
245
272
  end
246
273
  end
247
274
 
275
+ def adjust_rails_defaults(rails_version: SpecConfig.instance.rails_version)
276
+ if File.exist?('config/application.rb')
277
+ lines = IO.readlines('config/application.rb')
278
+ lines.each do |line|
279
+ line.gsub!(/config.load_defaults \d\.\d/, "config.load_defaults #{rails_version}")
280
+ end
281
+ File.open('config/application.rb', 'w') do |f|
282
+ f << lines.join
283
+ end
284
+ end
285
+
286
+ if rails_version == '5.1'
287
+ secrets = {
288
+ 'development' => {
289
+ 'secret_key_base' => 'abracadabra',
290
+ 'my_secret_token' => 'very_secret',
291
+ },
292
+ }
293
+ File.open('config/secrets.yml', 'w') do |f|
294
+ f << YAML.dump(secrets)
295
+ end
296
+ end
297
+ end
298
+
248
299
  def remove_bundler_req
249
300
  lock_lines = IO.readlines('Gemfile.lock')
250
301
  # Get rid of the bundled with line so that whatever bundler is installed
@@ -263,14 +314,14 @@ describe 'Mongoid application tests' do
263
314
  # in `initialize': too long unix socket path (126bytes given but 108bytes max) (ArgumentError)
264
315
  # Is it trying to create unix sockets in current directory?
265
316
  # https://stackoverflow.com/questions/30302021/rails-runner-without-spring
266
- ChildProcessHelper.check_call(%w(bin/spring binstub --remove --all), env: clean_env)
317
+ Mrss::ChildProcessHelper.check_call(%w(bin/spring binstub --remove --all), env: clean_env)
267
318
  end
268
319
 
269
320
  def clean_env
270
321
  @clean_env ||= Hash[ENV.keys.grep(/BUNDLE|RUBYOPT/).map { |k| [k, nil ] }]
271
322
  end
272
323
 
273
- def wait_for_port(port, timeout)
324
+ def wait_for_port(port, timeout, process)
274
325
  deadline = Time.now + timeout
275
326
  loop do
276
327
  begin
@@ -278,6 +329,9 @@ describe 'Mongoid application tests' do
278
329
  return
279
330
  end
280
331
  rescue IOError, SystemCallError
332
+ unless process.alive?
333
+ raise "Process #{process} died while waiting for port #{port}"
334
+ end
281
335
  if Time.now > deadline
282
336
  raise
283
337
  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?
@@ -52,9 +53,8 @@ RSpec.configure do |config|
52
53
 
53
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