mongoid 7.1.2 → 7.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +14 -0
  5. data/lib/config/locales/en.yml +1 -1
  6. data/lib/mongoid/association/accessors.rb +37 -2
  7. data/lib/mongoid/association/referenced/belongs_to/binding.rb +1 -1
  8. data/lib/mongoid/clients/factory.rb +2 -2
  9. data/lib/mongoid/clients/options.rb +8 -8
  10. data/lib/mongoid/clients/sessions.rb +20 -4
  11. data/lib/mongoid/clients/storage_options.rb +5 -5
  12. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +3 -3
  13. data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +12 -0
  14. data/lib/mongoid/errors/no_client_config.rb +2 -2
  15. data/lib/mongoid/errors/no_default_client.rb +1 -1
  16. data/lib/mongoid/fields/validators/macro.rb +4 -1
  17. data/lib/mongoid/query_cache.rb +21 -9
  18. data/lib/mongoid/tasks/database.rb +38 -3
  19. data/lib/mongoid/version.rb +1 -1
  20. data/spec/app/models/passport.rb +1 -0
  21. data/spec/app/models/phone.rb +1 -0
  22. data/spec/integration/app_spec.rb +76 -14
  23. data/spec/integration/associations/has_many_spec.rb +34 -0
  24. data/spec/integration/associations/has_one_spec.rb +34 -0
  25. data/spec/integration/bson_regexp_raw_spec.rb +20 -0
  26. data/spec/integration/criteria/date_field_spec.rb +41 -0
  27. data/spec/integration/shardable_spec.rb +20 -4
  28. data/spec/mongoid/association/accessors_spec.rb +238 -63
  29. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +138 -0
  30. data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +105 -0
  31. data/spec/mongoid/clients/factory_spec.rb +8 -8
  32. data/spec/mongoid/clients/options_spec.rb +9 -9
  33. data/spec/mongoid/contextual/geo_near_spec.rb +11 -2
  34. data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +1 -1
  35. data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +19 -7
  36. data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +28 -1
  37. data/spec/mongoid/errors/no_client_config_spec.rb +2 -2
  38. data/spec/mongoid/errors/no_client_database_spec.rb +3 -3
  39. data/spec/mongoid/errors/no_client_hosts_spec.rb +3 -3
  40. data/spec/mongoid/fields_spec.rb +24 -1
  41. data/spec/mongoid/query_cache_spec.rb +60 -7
  42. metadata +487 -479
  43. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd29f8f1d696ba937654fcd72eb3669ac9ba501465828b7eba0f7b707e606f5b
4
- data.tar.gz: c9f4a8dbb8a105a7e596019760d100913ddd008972b34f7595674ad7c49d4159
3
+ metadata.gz: 16518b942d2280aa5a81476d27709c2242f98ad559a2cea776c23369f9951d58
4
+ data.tar.gz: 243b7a7b9e0991f5feb7c3e8ae514e650915052c93b78c31fcbe8d8308e7743a
5
5
  SHA512:
6
- metadata.gz: 0e00e8d47e7af2fec23380035bcdbd0badc438552aed52aa0f462e246274e7f77220190d99bb6a83a1a90b8e0a41d19103c94fa454382635a2c193d52260c322
7
- data.tar.gz: 709300f2570059e460cd341cbaffe7da6328df142825bb726b65cbc377d6ba5129cf7fc973a40fc2de10a50307f49ac0f71db98b0edbb8a65c9cb33910e9d66f
6
+ metadata.gz: '07539688736c17c7d33b8dfea04e7c5d9d8295b176358be200fd5cc0793c40902e54704697c75a6bf08930f418891b032ae0f0f0dbb090635590c277ca2aabce'
7
+ data.tar.gz: ed2a4140a29a5dfd12328a34363af63280661048c15c7b34b32905bdec493822e7377cb206407a7ba99298b27ef158785ba5ec92b5ef93641a95de923c539022
Binary file
data.tar.gz.sig CHANGED
Binary file
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler"
4
+ require "bundler/gem_tasks"
4
5
  Bundler.setup
5
6
 
6
7
  require "rake"
@@ -9,6 +10,9 @@ require "rspec/core/rake_task"
9
10
  $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
10
11
  require "mongoid/version"
11
12
 
13
+ tasks = Rake.application.instance_variable_get('@tasks')
14
+ tasks['release:do'] = tasks.delete('release')
15
+
12
16
  task :gem => :build
13
17
  task :build do
14
18
  system "gem build mongoid.gemspec"
@@ -47,3 +51,13 @@ namespace :docs do
47
51
  system "yardoc -o #{out} --title mongoid-#{Mongoid::VERSION}"
48
52
  end
49
53
  end
54
+
55
+ namespace :release do
56
+ task :check_private_key do
57
+ unless File.exist?('gem-private_key.pem')
58
+ raise "No private key present, cannot release"
59
+ end
60
+ end
61
+ end
62
+
63
+ task :release => ['release:check_private_key', 'release:do']
@@ -249,7 +249,7 @@ en:
249
249
  Example:\n
250
250
  \_\_class Band\n
251
251
  \_\_\_\_include Mongoid::Document\n
252
- \_\_\_\_store_in collection: 'artists', database: 'secondary'\n
252
+ \_\_\_\_store_in collection: 'artists', database: 'music'\n
253
253
  \_\_end\n\n"
254
254
  invalid_storage_parent:
255
255
  message: "Invalid store_in call on class %{klass}."
@@ -131,15 +131,50 @@ module Mongoid
131
131
  # @api private
132
132
  def _mongoid_filter_selected_fields(assoc_key)
133
133
  return nil unless __selected_fields
134
+
135
+ projecting_assoc = false
136
+
134
137
  filtered = {}
135
138
  __selected_fields.each do |k, v|
136
139
  bits = k.split('.')
140
+
141
+ # If we are asked to project an association, we need all of that
142
+ # association's fields. However, we may be asked to project
143
+ # an association *and* its fields in the same query. In this case
144
+ # behavior differs according to server version:
145
+ #
146
+ # 4.2 and lower take the most recent projection specification, meaning
147
+ # projecting foo followed by foo.bar effectively projects foo.bar and
148
+ # projecting foo.bar followed by foo effectively projects foo.
149
+ # To match this behavior we need to track when we are being asked
150
+ # to project the association and when we are asked to project a field,
151
+ # and if we are asked to project the association last we need to
152
+ # remove any field projections.
153
+ #
154
+ # 4.4 (and presumably higher) do not allow projection to be on an
155
+ # association and its field, so it doesn't matter what we do. Hence
156
+ # we just need to handle the 4.2 and lower case correctly.
137
157
  if bits.first == assoc_key
138
- bits.shift
139
- filtered[bits.join('.')] = v
158
+ # Projecting the entire association OR some of its fields
159
+ if bits.length > 1
160
+ # Projecting a field
161
+ bits.shift
162
+ filtered[bits.join('.')] = v
163
+ projecting_assoc = false
164
+ else
165
+ # Projecting the entire association
166
+ projecting_assoc = true
167
+ end
140
168
  end
141
169
  end
142
170
 
171
+ if projecting_assoc
172
+ # The last projection was of the entire association; we may have
173
+ # also been projecting fields, but discard the field projections
174
+ # and return nil indicating we want the entire association.
175
+ return nil
176
+ end
177
+
143
178
  # Positional projection is specified as "foo.$". In this case the
144
179
  # document that the $ is referring to should be retrieved with all
145
180
  # fields. See https://docs.mongodb.com/manual/reference/operator/projection/positional/
@@ -76,7 +76,7 @@ module Mongoid
76
76
  # @since 3.0.0
77
77
  def check_polymorphic_inverses!(doc)
78
78
  inverses = _association.inverses(doc)
79
- if inverses.count > 1 && _base.send(_association.foreign_key).nil?
79
+ if inverses.length > 1 && _base.send(_association.foreign_key).nil?
80
80
  raise Errors::InvalidSetPolymorphicRelation.new(
81
81
  _association.name, _base.class.name, _target.class.name
82
82
  )
@@ -12,9 +12,9 @@ module Mongoid
12
12
  # raised.
13
13
  #
14
14
  # @example Create the client.
15
- # Factory.create(:secondary)
15
+ # Factory.create(:analytics)
16
16
  #
17
- # @param [ String, Symbol ] name The named client configuration.
17
+ # @param [ String | Symbol ] name The named client configuration.
18
18
  #
19
19
  # @raise [ Errors::NoClientConfig ] If no config could be found.
20
20
  #
@@ -9,16 +9,16 @@ module Mongoid
9
9
  # Change the persistence context for this object during the block.
10
10
  #
11
11
  # @example Save the current document to a different collection.
12
- # model.with(collection: "secondary") do |m|
12
+ # model.with(collection: "bands") do |m|
13
13
  # m.save
14
14
  # end
15
15
  #
16
16
  # @param [ Hash, Mongoid::PersistenceContext ] options_or_context
17
17
  # The storage options or a persistence context.
18
18
  #
19
- # @option options [ String, Symbol ] :collection The collection name.
20
- # @option options [ String, Symbol ] :database The database name.
21
- # @option options [ String, Symbol ] :client The client name.
19
+ # @option options [ String | Symbol ] :collection The collection name.
20
+ # @option options [ String | Symbol ] :database The database name.
21
+ # @option options [ String | Symbol ] :client The client name.
22
22
  #
23
23
  # @since 6.0.0
24
24
  def with(options_or_context, &block)
@@ -83,15 +83,15 @@ module Mongoid
83
83
  # Change the persistence context for this class during the block.
84
84
  #
85
85
  # @example Save the current document to a different collection.
86
- # Model.with(collection: "secondary") do |m|
86
+ # Model.with(collection: "bands") do |m|
87
87
  # m.create
88
88
  # end
89
89
  #
90
90
  # @param [ Hash ] options The storage options.
91
91
  #
92
- # @option options [ String, Symbol ] :collection The collection name.
93
- # @option options [ String, Symbol ] :database The database name.
94
- # @option options [ String, Symbol ] :client The client name.
92
+ # @option options [ String | Symbol ] :collection The collection name.
93
+ # @option options [ String | Symbol ] :database The database name.
94
+ # @option options [ String | Symbol ] :client The client name.
95
95
  #
96
96
  # @since 6.0.0
97
97
  def with(options, &block)
@@ -41,12 +41,20 @@ module Mongoid
41
41
  #
42
42
  # @since 6.4.0
43
43
  def with_session(options = {})
44
- raise Mongoid::Errors::InvalidSessionUse.new(:invalid_session_nesting) if Threaded.get_session
44
+ if Threaded.get_session
45
+ raise Mongoid::Errors::InvalidSessionUse.new(:invalid_session_nesting)
46
+ end
45
47
  session = persistence_context.client.start_session(options)
46
48
  Threaded.set_session(session)
47
49
  yield(session)
48
50
  rescue Mongo::Error::InvalidSession => ex
49
- if ex.message == Mongo::Session::SESSIONS_NOT_SUPPORTED
51
+ if
52
+ # Driver 2.13.0+
53
+ defined?(Mongo::Error::SessionsNotSupported) &&
54
+ Mongo::Error::SessionsNotSupported === ex ||
55
+ # Legacy drivers
56
+ ex.message == Mongo::Session::SESSIONS_NOT_SUPPORTED
57
+ then
50
58
  raise Mongoid::Errors::InvalidSessionUse.new(:sessions_not_supported)
51
59
  end
52
60
  raise Mongoid::Errors::InvalidSessionUse.new(:invalid_session_use)
@@ -92,12 +100,20 @@ module Mongoid
92
100
  #
93
101
  # @since 6.4.0
94
102
  def with_session(options = {})
95
- raise Mongoid::Errors::InvalidSessionUse.new(:invalid_session_nesting) if Threaded.get_session
103
+ if Threaded.get_session
104
+ raise Mongoid::Errors::InvalidSessionUse.new(:invalid_session_nesting)
105
+ end
96
106
  session = persistence_context.client.start_session(options)
97
107
  Threaded.set_session(session)
98
108
  yield(session)
99
109
  rescue Mongo::Error::InvalidSession => ex
100
- if ex.message == Mongo::Session::SESSIONS_NOT_SUPPORTED
110
+ if
111
+ # Driver 2.13.0+
112
+ defined?(Mongo::Error::SessionsNotSupported) &&
113
+ Mongo::Error::SessionsNotSupported === ex ||
114
+ # Legacy drivers
115
+ ex.message == Mongo::Session::SESSIONS_NOT_SUPPORTED
116
+ then
101
117
  raise Mongoid::Errors::InvalidSessionUse.new(:sessions_not_supported)
102
118
  end
103
119
  raise Mongoid::Errors::InvalidSessionUse.new(:invalid_session_use)
@@ -32,20 +32,20 @@ module Mongoid
32
32
  # @example Store this model by default in a different client.
33
33
  # class Band
34
34
  # include Mongoid::Document
35
- # store_in client: "secondary"
35
+ # store_in client: "analytics"
36
36
  # end
37
37
  #
38
38
  # @example Store this model with a combination of options.
39
39
  # class Band
40
40
  # include Mongoid::Document
41
- # store_in collection: "artists", database: "secondary"
41
+ # store_in collection: "artists", database: "music"
42
42
  # end
43
43
  #
44
44
  # @param [ Hash ] options The storage options.
45
45
  #
46
- # @option options [ String, Symbol ] :collection The collection name.
47
- # @option options [ String, Symbol ] :database The database name.
48
- # @option options [ String, Symbol ] :client The client name.
46
+ # @option options [ String | Symbol ] :collection The collection name.
47
+ # @option options [ String | Symbol ] :database The database name.
48
+ # @option options [ String | Symbol ] :client The client name.
49
49
  #
50
50
  # @return [ Class ] The model class.
51
51
  #
@@ -38,7 +38,7 @@ module Mongoid
38
38
  end
39
39
  end
40
40
 
41
- module Raw
41
+ module Raw_
42
42
 
43
43
  # Is the object a regexp?
44
44
  #
@@ -77,5 +77,5 @@ end
77
77
 
78
78
  ::Regexp.__send__(:include,Mongoid::Criteria::Queryable::Extensions::Regexp)
79
79
  ::Regexp.__send__(:extend, Mongoid::Criteria::Queryable::Extensions::Regexp::ClassMethods)
80
- BSON::Regexp::Raw.__send__(:include,Mongoid::Criteria::Queryable::Extensions::Regexp::Raw)
81
- BSON::Regexp::Raw.__send__(:extend, Mongoid::Criteria::Queryable::Extensions::Regexp::Raw::ClassMethods)
80
+ BSON::Regexp::Raw.__send__(:include,Mongoid::Criteria::Queryable::Extensions::Regexp::Raw_)
81
+ BSON::Regexp::Raw.__send__(:extend, Mongoid::Criteria::Queryable::Extensions::Regexp::Raw_::ClassMethods)
@@ -9,6 +9,18 @@ module Mongoid
9
9
  # This module contains additional time with zone behavior.
10
10
  module TimeWithZone
11
11
 
12
+ # Evolve the time as a date, UTC midnight.
13
+ #
14
+ # @example Evolve the time to a date query format.
15
+ # time.__evolve_date__
16
+ #
17
+ # @return [ Time ] The date at midnight UTC.
18
+ #
19
+ # @since 1.0.0
20
+ def __evolve_date__
21
+ ::Time.utc(year, month, day, 0, 0, 0, 0)
22
+ end
23
+
12
24
  # Evolve the time into a utc time.
13
25
  #
14
26
  # @example Evolve the time.
@@ -11,9 +11,9 @@ module Mongoid
11
11
  # Create the new error.
12
12
  #
13
13
  # @example Create the error.
14
- # NoClientConfig.new(:secondary)
14
+ # NoClientConfig.new(:analytics)
15
15
  #
16
- # @param [ String, Symbol ] name The name of the client.
16
+ # @param [ String | Symbol ] name The name of the client.
17
17
  #
18
18
  # @since 3.0.0
19
19
  def initialize(name)
@@ -10,7 +10,7 @@ module Mongoid
10
10
  # Create the new error with the defined client names.
11
11
  #
12
12
  # @example Create the new error.
13
- # NoDefaultClient.new([ :secondary ])
13
+ # NoDefaultClient.new([ :analytics ])
14
14
  #
15
15
  # @param [ Array<Symbol> ] keys The defined clients.
16
16
  #
@@ -113,7 +113,10 @@ module Mongoid
113
113
  end
114
114
 
115
115
  if option == :type && options[option] == Symbol
116
- Mongoid.logger.warn(FIELD_TYPE_IS_SYMBOL)
116
+ @field_type_is_symbol_warned ||= begin
117
+ Mongoid.logger.warn(FIELD_TYPE_IS_SYMBOL)
118
+ true
119
+ end
117
120
  end
118
121
  end
119
122
  end
@@ -230,14 +230,29 @@ module Mongoid
230
230
  unless cursor = cached_cursor
231
231
  read_with_retry do
232
232
  server = server_selector.select_server(cluster)
233
- cursor = CachedCursor.new(view, send_initial_query(server), server)
234
- QueryCache.cache_table[cache_key] = cursor
233
+ result = send_initial_query(server)
234
+ if result.cursor_id == 0 || result.cursor_id.nil?
235
+ cursor = CachedCursor.new(view, result, server)
236
+ QueryCache.cache_table[cache_key] = cursor
237
+ else
238
+ cursor = Mongo::Cursor.new(view, result, server)
239
+ end
235
240
  end
236
241
  end
237
- cursor.each do |doc|
238
- yield doc
239
- end if block_given?
240
- cursor
242
+
243
+ if block_given?
244
+ if limit && limit != -1
245
+ cursor.to_a[0...limit].each do |doc|
246
+ yield doc
247
+ end
248
+ else
249
+ cursor.each do |doc|
250
+ yield doc
251
+ end
252
+ end
253
+ else
254
+ cursor
255
+ end
241
256
  end
242
257
  end
243
258
 
@@ -247,9 +262,6 @@ module Mongoid
247
262
  if limit
248
263
  key = [ collection.namespace, selector, nil, skip, sort, projection, collation ]
249
264
  cursor = QueryCache.cache_table[key]
250
- if cursor
251
- cursor.to_a[0...limit.abs]
252
- end
253
265
  end
254
266
  cursor || QueryCache.cache_table[cache_key]
255
267
  end
@@ -132,8 +132,32 @@ module Mongoid
132
132
  next
133
133
  end
134
134
 
135
- # Database must exist in order to run collStats
136
- model.collection.create
135
+ # Database of the collection must exist in order to run collStats.
136
+ # Depending on server version, the collection itself must also
137
+ # exist.
138
+ # MongoDB does not have a command to create the database; the best
139
+ # approximation of it is to create the collection we want.
140
+ # On older servers, creating a collection that already exists is
141
+ # an error.
142
+ # Additionally, 3.6 and potentially older servers do not provide
143
+ # the error code when they are asked to collStats a non-existent
144
+ # collection (https://jira.mongodb.org/browse/SERVER-50070).
145
+ begin
146
+ stats = model.collection.database.command(collStats: model.collection.name).first
147
+ rescue Mongo::Error::OperationFailure => exc
148
+ # Code 26 is database does not exist.
149
+ # Code 8 is collection does not exist, as of 4.0.
150
+ # On 3.6 and earlier match the text of exception message.
151
+ if exc.code == 26 || exc.code == 8 ||
152
+ exc.code.nil? && exc.message =~ /not found/
153
+ then
154
+ model.collection.create
155
+
156
+ stats = model.collection.database.command(collStats: model.collection.name).first
157
+ else
158
+ raise
159
+ end
160
+ end
137
161
 
138
162
  stats = model.collection.database.command(collStats: model.collection.name).first
139
163
  if stats[:sharded]
@@ -142,7 +166,18 @@ module Mongoid
142
166
  end
143
167
 
144
168
  admin_db = model.collection.client.use(:admin).database
145
- admin_db.command(enableSharding: model.collection.database.name)
169
+
170
+ begin
171
+ admin_db.command(enableSharding: model.collection.database.name)
172
+ rescue Mongo::Error::OperationFailure => exc
173
+ # Server 2.6 fails if sharding is already enabled
174
+ if exc.code == 23 || exc.code.nil? && exc.message =~ /already enabled/
175
+ # Nothing
176
+ else
177
+ raise
178
+ end
179
+ end
180
+
146
181
  begin
147
182
  admin_db.command(shardCollection: model.collection.namespace, **model.shard_config)
148
183
  rescue Mongo::Error::OperationFailure => e
@@ -2,5 +2,5 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  module Mongoid
5
- VERSION = "7.1.2"
5
+ VERSION = "7.1.4"
6
6
  end
@@ -4,5 +4,6 @@
4
4
  class Passport
5
5
  include Mongoid::Document
6
6
  field :number, type: String
7
+ field :country, type: String
7
8
  embedded_in :person, autobuild: true
8
9
  end
@@ -7,6 +7,7 @@ class Phone
7
7
  field :_id, type: String, overwrite: true, default: ->{ number }
8
8
 
9
9
  field :number
10
+ field :landline, type: Boolean
10
11
  embeds_one :country_code
11
12
  embedded_in :person
12
13
  end
@@ -96,7 +96,7 @@ describe 'Mongoid application tests' do
96
96
 
97
97
  Dir.chdir(TMP_BASE) do
98
98
  FileUtils.rm_rf('mongoid-test')
99
- ChildProcessHelper.check_call(%w(rails new mongoid-test --skip-spring), env: clean_env)
99
+ ChildProcessHelper.check_call(%w(rails new mongoid-test --skip-spring --skip-active-record), env: clean_env)
100
100
 
101
101
  Dir.chdir('mongoid-test') do
102
102
  adjust_app_gemfile
@@ -116,6 +116,55 @@ describe 'Mongoid application tests' do
116
116
  end
117
117
  end
118
118
 
119
+ context 'local test applications' do
120
+ let(:client) { Mongoid.default_client }
121
+
122
+ describe 'create_indexes rake task' do
123
+
124
+ APP_PATH = File.join(File.dirname(__FILE__), '../../test-apps/rails-api')
125
+
126
+ %w(development production).each do |rails_env|
127
+ context "in #{rails_env}" do
128
+
129
+ %w(classic zeitwerk).each do |autoloader|
130
+ context "with #{autoloader} autoloader" do
131
+
132
+ let(:env) do
133
+ clean_env.merge(RAILS_ENV: rails_env, AUTOLOADER: autoloader)
134
+ end
135
+
136
+ before do
137
+ Dir.chdir(APP_PATH) do
138
+ remove_bundler_req
139
+ ChildProcessHelper.check_call(%w(bundle install), env: env)
140
+ write_mongoid_yml
141
+ end
142
+
143
+ client['posts'].drop
144
+ client['posts'].create
145
+ end
146
+
147
+ it 'creates an index' do
148
+ index = client['posts'].indexes.detect do |index|
149
+ index['key'] == {'subject' => 1}
150
+ end
151
+ index.should be nil
152
+
153
+ ChildProcessHelper.check_call(%w(rake db:mongoid:create_indexes),
154
+ cwd: APP_PATH, env: env)
155
+
156
+ index = client['posts'].indexes.detect do |index|
157
+ index['key'] == {'subject' => 1}
158
+ end
159
+ index.should be_a(Hash)
160
+ end
161
+ end
162
+ end
163
+ end
164
+ end
165
+ end
166
+ end
167
+
119
168
  def clone_application(repo_url, subdir: nil, rails_version: nil)
120
169
  Dir.chdir(TMP_BASE) do
121
170
  FileUtils.rm_rf(File.basename(repo_url))
@@ -125,26 +174,27 @@ describe 'Mongoid application tests' do
125
174
  ChildProcessHelper.check_call(%w(bundle install), env: clean_env)
126
175
  puts `git diff`
127
176
 
128
- config = {'development' => {'clients' => {'default' => {'uri' => SpecConfig.instance.uri_str}}}}
129
- File.open('config/mongoid.yml', 'w') do |f|
130
- f << YAML.dump(config)
131
- end
177
+ write_mongoid_yml
132
178
 
133
179
  yield
134
180
  end
135
181
  end
136
182
  end
137
183
 
138
- def adjust_app_gemfile(rails_version: nil)
139
- lock_lines = IO.readlines('Gemfile.lock')
140
- # Get rid of the bundled with line so that whatever bundler is installed
141
- # on the system is usable with the application.
142
- if i = lock_lines.index("BUNDLED WITH\n")
143
- lock_lines.slice!(i, 2)
144
- File.open('Gemfile.lock', 'w') do |f|
145
- f << lock_lines.join
146
- end
184
+ def write_mongoid_yml
185
+ env_config = {'clients' => {'default' => {
186
+ # TODO massive hack, will fail if uri specifies a database name or
187
+ # any uri options
188
+ 'uri' => "#{SpecConfig.instance.uri_str}/mongoid_test",
189
+ }}}
190
+ config = {'development' => env_config, 'production' => env_config}
191
+ File.open('config/mongoid.yml', 'w') do |f|
192
+ f << YAML.dump(config)
147
193
  end
194
+ end
195
+
196
+ def adjust_app_gemfile(rails_version: nil)
197
+ remove_bundler_req
148
198
 
149
199
  gemfile_lines = IO.readlines('Gemfile')
150
200
  gemfile_lines.delete_if do |line|
@@ -162,6 +212,18 @@ describe 'Mongoid application tests' do
162
212
  end
163
213
  end
164
214
 
215
+ def remove_bundler_req
216
+ lock_lines = IO.readlines('Gemfile.lock')
217
+ # Get rid of the bundled with line so that whatever bundler is installed
218
+ # on the system is usable with the application.
219
+ if i = lock_lines.index("BUNDLED WITH\n")
220
+ lock_lines.slice!(i, 2)
221
+ File.open('Gemfile.lock', 'w') do |f|
222
+ f << lock_lines.join
223
+ end
224
+ end
225
+ end
226
+
165
227
  def remove_spring
166
228
  # Spring produces this error in Evergreen:
167
229
  # /data/mci/280eb2ecf4fd69208e2106cd3af526f1/src/rubies/ruby-2.7.0/lib/ruby/gems/2.7.0/gems/spring-2.1.0/lib/spring/client/run.rb:26: