mongoid 7.2.4 → 7.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) 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 +16 -0
  6. data/lib/config/locales/en.yml +2 -2
  7. data/lib/mongoid/association/accessors.rb +1 -1
  8. data/lib/mongoid/association/constrainable.rb +1 -1
  9. data/lib/mongoid/association/depending.rb +4 -4
  10. data/lib/mongoid/association/embedded/batchable.rb +1 -1
  11. data/lib/mongoid/association/embedded/embedded_in.rb +1 -1
  12. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +10 -3
  13. data/lib/mongoid/association/nested/many.rb +1 -1
  14. data/lib/mongoid/association/nested/one.rb +4 -2
  15. data/lib/mongoid/association/proxy.rb +6 -1
  16. data/lib/mongoid/association/referenced/auto_save.rb +2 -2
  17. data/lib/mongoid/association/referenced/has_many/enumerable.rb +493 -495
  18. data/lib/mongoid/association/referenced/has_many/proxy.rb +2 -2
  19. data/lib/mongoid/association/referenced/has_one/nested_builder.rb +2 -2
  20. data/lib/mongoid/attributes.rb +24 -13
  21. data/lib/mongoid/attributes/projector.rb +120 -0
  22. data/lib/mongoid/cacheable.rb +2 -2
  23. data/lib/mongoid/clients.rb +1 -1
  24. data/lib/mongoid/clients/factory.rb +22 -8
  25. data/lib/mongoid/config.rb +19 -2
  26. data/lib/mongoid/contextual/aggregable/mongo.rb +10 -8
  27. data/lib/mongoid/copyable.rb +1 -1
  28. data/lib/mongoid/criteria.rb +4 -5
  29. data/lib/mongoid/criteria/findable.rb +1 -1
  30. data/lib/mongoid/criteria/queryable/expandable.rb +0 -24
  31. data/lib/mongoid/criteria/queryable/extensions.rb +0 -4
  32. data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
  33. data/lib/mongoid/criteria/queryable/mergeable.rb +46 -20
  34. data/lib/mongoid/criteria/queryable/selectable.rb +8 -8
  35. data/lib/mongoid/document.rb +1 -15
  36. data/lib/mongoid/errors/delete_restriction.rb +8 -9
  37. data/lib/mongoid/errors/mongoid_error.rb +1 -1
  38. data/lib/mongoid/evolvable.rb +1 -1
  39. data/lib/mongoid/extensions/boolean.rb +1 -2
  40. data/lib/mongoid/extensions/false_class.rb +1 -1
  41. data/lib/mongoid/extensions/hash.rb +2 -2
  42. data/lib/mongoid/extensions/true_class.rb +1 -1
  43. data/lib/mongoid/fields.rb +43 -5
  44. data/lib/mongoid/inspectable.rb +1 -1
  45. data/lib/mongoid/matcher.rb +7 -0
  46. data/lib/mongoid/matcher/bits.rb +41 -0
  47. data/lib/mongoid/matcher/bits_all_clear.rb +20 -0
  48. data/lib/mongoid/matcher/bits_all_set.rb +20 -0
  49. data/lib/mongoid/matcher/bits_any_clear.rb +20 -0
  50. data/lib/mongoid/matcher/bits_any_set.rb +20 -0
  51. data/lib/mongoid/matcher/expression.rb +4 -0
  52. data/lib/mongoid/matcher/field_operator.rb +6 -0
  53. data/lib/mongoid/matcher/mod.rb +17 -0
  54. data/lib/mongoid/matcher/type.rb +99 -0
  55. data/lib/mongoid/persistable/deletable.rb +1 -2
  56. data/lib/mongoid/persistable/destroyable.rb +8 -2
  57. data/lib/mongoid/persistable/updatable.rb +27 -2
  58. data/lib/mongoid/query_cache.rb +35 -29
  59. data/lib/mongoid/selectable.rb +5 -7
  60. data/lib/mongoid/shardable.rb +21 -5
  61. data/lib/mongoid/touchable.rb +23 -4
  62. data/lib/mongoid/validatable/associated.rb +1 -1
  63. data/lib/mongoid/validatable/presence.rb +3 -3
  64. data/lib/mongoid/validatable/uniqueness.rb +1 -1
  65. data/lib/mongoid/version.rb +1 -1
  66. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +1 -1
  67. data/spec/integration/app_spec.rb +0 -3
  68. data/spec/integration/associations/embeds_many_spec.rb +44 -0
  69. data/spec/integration/associations/has_one_spec.rb +48 -0
  70. data/spec/integration/criteria/date_field_spec.rb +1 -1
  71. data/spec/integration/document_spec.rb +9 -0
  72. data/spec/integration/matcher_operator_data/bits_all_clear.yml +159 -0
  73. data/spec/integration/matcher_operator_data/bits_all_set.yml +159 -0
  74. data/spec/integration/matcher_operator_data/bits_any_clear.yml +159 -0
  75. data/spec/integration/matcher_operator_data/bits_any_set.yml +159 -0
  76. data/spec/integration/matcher_operator_data/comment.yml +22 -0
  77. data/spec/integration/matcher_operator_data/in.yml +16 -0
  78. data/spec/integration/matcher_operator_data/mod.yml +55 -0
  79. data/spec/integration/matcher_operator_data/type.yml +70 -0
  80. data/spec/integration/matcher_operator_data/type_array.yml +16 -0
  81. data/spec/integration/matcher_operator_data/type_binary.yml +18 -0
  82. data/spec/integration/matcher_operator_data/type_boolean.yml +39 -0
  83. data/spec/integration/matcher_operator_data/type_code.yml +26 -0
  84. data/spec/integration/matcher_operator_data/type_code_with_scope.yml +26 -0
  85. data/spec/integration/matcher_operator_data/type_date.yml +39 -0
  86. data/spec/integration/matcher_operator_data/type_db_pointer.yml +19 -0
  87. data/spec/integration/matcher_operator_data/type_decimal.yml +40 -0
  88. data/spec/integration/matcher_operator_data/type_double.yml +15 -0
  89. data/spec/integration/matcher_operator_data/type_int32.yml +33 -0
  90. data/spec/integration/matcher_operator_data/type_int64.yml +33 -0
  91. data/spec/integration/matcher_operator_data/type_max_key.yml +17 -0
  92. data/spec/integration/matcher_operator_data/type_min_key.yml +17 -0
  93. data/spec/integration/matcher_operator_data/type_null.yml +23 -0
  94. data/spec/integration/matcher_operator_data/type_object.yml +23 -0
  95. data/spec/integration/matcher_operator_data/type_object_id.yml +25 -0
  96. data/spec/integration/matcher_operator_data/type_regex.yml +44 -0
  97. data/spec/integration/matcher_operator_data/type_string.yml +15 -0
  98. data/spec/integration/matcher_operator_data/type_symbol.yml +32 -0
  99. data/spec/integration/matcher_operator_data/type_timestamp.yml +25 -0
  100. data/spec/integration/matcher_operator_data/type_undefined.yml +17 -0
  101. data/spec/lite_spec_helper.rb +2 -0
  102. data/spec/mongoid/association/depending_spec.rb +391 -352
  103. data/spec/mongoid/association/nested/one_spec.rb +18 -14
  104. data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +25 -8
  105. data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +1 -1
  106. data/spec/mongoid/association/referenced/has_many/binding_spec.rb +1 -1
  107. data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +1 -1
  108. data/spec/mongoid/association/referenced/has_one_models.rb +8 -0
  109. data/spec/mongoid/atomic/paths_spec.rb +64 -12
  110. data/spec/mongoid/attributes/projector_data/embedded.yml +105 -0
  111. data/spec/mongoid/attributes/projector_data/fields.yml +93 -0
  112. data/spec/mongoid/attributes/projector_spec.rb +41 -0
  113. data/spec/mongoid/attributes_spec.rb +98 -6
  114. data/spec/mongoid/clients/factory_spec.rb +48 -0
  115. data/spec/mongoid/config_spec.rb +32 -0
  116. data/spec/mongoid/contextual/mongo_spec.rb +2 -2
  117. data/spec/mongoid/criteria/modifiable_spec.rb +1 -1
  118. data/spec/mongoid/criteria/queryable/expandable_spec.rb +0 -73
  119. data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +1 -1
  120. data/spec/mongoid/criteria/queryable/mergeable_spec.rb +105 -7
  121. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +229 -24
  122. data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +39 -0
  123. data/spec/mongoid/criteria/queryable/selectable_spec.rb +1 -565
  124. data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +590 -0
  125. data/spec/mongoid/criteria_projection_spec.rb +411 -0
  126. data/spec/mongoid/criteria_spec.rb +0 -275
  127. data/spec/mongoid/document_query_spec.rb +0 -51
  128. data/spec/mongoid/document_spec.rb +13 -13
  129. data/spec/mongoid/errors/delete_restriction_spec.rb +1 -1
  130. data/spec/mongoid/errors/mongoid_error_spec.rb +8 -20
  131. data/spec/mongoid/extensions/false_class_spec.rb +1 -1
  132. data/spec/mongoid/extensions/string_spec.rb +5 -5
  133. data/spec/mongoid/extensions/true_class_spec.rb +1 -1
  134. data/spec/mongoid/fields/localized_spec.rb +4 -4
  135. data/spec/mongoid/fields_spec.rb +4 -4
  136. data/spec/mongoid/inspectable_spec.rb +12 -4
  137. data/spec/mongoid/persistable/deletable_spec.rb +175 -1
  138. data/spec/mongoid/persistable/destroyable_spec.rb +191 -3
  139. data/spec/mongoid/persistable/savable_spec.rb +3 -5
  140. data/spec/mongoid/persistable/upsertable_spec.rb +1 -1
  141. data/spec/mongoid/persistable_spec.rb +2 -2
  142. data/spec/mongoid/query_cache_middleware_spec.rb +8 -0
  143. data/spec/mongoid/reloadable_spec.rb +18 -1
  144. data/spec/mongoid/shardable_spec.rb +44 -0
  145. data/spec/mongoid/touchable_spec.rb +104 -16
  146. data/spec/mongoid/touchable_spec_models.rb +52 -0
  147. data/spec/mongoid/validatable_spec.rb +1 -1
  148. data/spec/shared/lib/mrss/cluster_config.rb +3 -8
  149. data/spec/shared/lib/mrss/constraints.rb +6 -20
  150. data/spec/shared/lib/mrss/docker_runner.rb +1 -7
  151. data/spec/shared/lib/mrss/spec_organizer.rb +1 -18
  152. data/spec/shared/share/Dockerfile.erb +30 -121
  153. data/spec/shared/shlib/server.sh +4 -31
  154. data/spec/shared/shlib/set_env.sh +1 -4
  155. data/spec/spec_helper.rb +7 -3
  156. data/spec/support/client_registry.rb +9 -0
  157. data/spec/support/models/bolt.rb +8 -0
  158. data/spec/support/models/hole.rb +13 -0
  159. data/spec/support/models/mop.rb +0 -1
  160. data/spec/support/models/nut.rb +8 -0
  161. data/spec/support/models/person.rb +6 -0
  162. data/spec/support/models/sealer.rb +8 -0
  163. data/spec/support/models/shirt.rb +12 -0
  164. data/spec/support/models/spacer.rb +8 -0
  165. data/spec/support/models/threadlocker.rb +8 -0
  166. data/spec/support/models/washer.rb +8 -0
  167. metadata +620 -534
  168. metadata.gz.sig +5 -3
  169. data/spec/shared/bin/s3-copy +0 -45
  170. data/spec/shared/bin/s3-upload +0 -69
  171. data/spec/shared/share/haproxy-1.conf +0 -16
  172. data/spec/shared/share/haproxy-2.conf +0 -17
  173. data/spec/support/cluster_config.rb +0 -158
metadata.gz.sig CHANGED
@@ -1,3 +1,5 @@
1
- q�7��JR�
2
- Ha'��-��'?�R�]���A�R�!�V/�E5�8�ITb��F�ީ$v"8�{\C�|����!�$���c�!N`%��貅�{���2>�-�,����r��6�#E���j��m��!B�c���
3
- TrY�����WF�Y��xxS�![X�Ѕ`K.�P�<ơTΥ����LU�b��aJFc�[��캏�
1
+ 6�}X��j0�wE��?B�&��v�3�ϳl��DK��(�)�H�$vୁ`U�
2
+ ��^&h�>�Ĭ��ی,��}
3
+ ,UM;Y䆝�݉�"���IS�%
4
+ ���h6��{&���U`�Va�A��?��(?��9��i��,}{���)� t����"
5
+ ����?
@@ -1,45 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'optparse'
4
- require 'aws-sdk-s3'
5
-
6
- options = {}
7
- OptionParser.new do |opts|
8
- opts.banner = "Usage: s3-copy options"
9
-
10
- opts.on("-r", "--region=REGION", "AWS region to use (default us-east-1)") do |v|
11
- options[:region] = v
12
- end
13
-
14
- opts.on("-p", "--param=KEY=VALUE", "Specify parameter for new files") do |v|
15
- options[:params] ||= {}
16
- k, v = v.split('=', 2)
17
- options[:params][k.to_sym] = v
18
- end
19
-
20
- opts.on("-f", "--from=BUCKET:PATH", "Bucket name and key (or path) to copy from") do |v|
21
- options[:from] = v
22
- end
23
-
24
- opts.on("-t", "--to=BUCKET:PATH", "Bucket name and key (or path) to write to (may be specified more than once)") do |v|
25
- options[:to] ||= []
26
- options[:to] << v
27
- end
28
- end.parse!
29
-
30
- ENV['AWS_REGION'] ||= options[:region] || 'us-east-1'
31
-
32
- bucket, key = options.fetch(:from).split(':', 2)
33
-
34
- s3 = Aws::S3::Client.new
35
-
36
- options.fetch(:to).each do |dest|
37
- STDERR.puts "Copying to #{dest}"
38
- dbucket, dkey = dest.split(':', 2)
39
- s3.copy_object(
40
- bucket: dbucket,
41
- key: dkey,
42
- copy_source: "/#{bucket}/#{key}",
43
- **options[:params] || {},
44
- )
45
- end
@@ -1,69 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'optparse'
4
- require 'aws-sdk-s3'
5
-
6
- options = {}
7
- OptionParser.new do |opts|
8
- opts.banner = "Usage: s3-upload options"
9
-
10
- opts.on("-r", "--region=REGION", "AWS region to use (default us-east-1)") do |v|
11
- options[:region] = v
12
- end
13
-
14
- opts.on("-p", "--param=KEY=VALUE", "Specify parameter for S3 upload") do |v|
15
- options[:params] ||= {}
16
- k, v = v.split('=', 2)
17
- options[:params][k.to_sym] = v
18
- end
19
-
20
- opts.on("-f", "--file=PATH", "Path to the file to upload, - to upload standard input") do |v|
21
- options[:file] = v
22
- end
23
-
24
- opts.on("-w", "--write=BUCKET:PATH", "Bucket name and key (or path) to upload to") do |v|
25
- options[:write] = v
26
- end
27
-
28
- opts.on("-c", "--copy=BUCKET:PATH", "Bucket name and key (or path) to copy to (may be specified more than once)") do |v|
29
- options[:copy] ||= []
30
- options[:copy] << v
31
- end
32
- end.parse!
33
-
34
- ENV['AWS_REGION'] ||= options[:region] || 'us-east-1'
35
-
36
- def upload(f, options)
37
- s3 = Aws::S3::Client.new
38
- write = options.fetch(:write)
39
- STDERR.puts "Writing #{write}"
40
- bucket, key = write.split(':', 2)
41
- s3.put_object(
42
- body: f.read,
43
- bucket: bucket,
44
- key: key,
45
- **options[:params] || {},
46
- )
47
- if copy = options[:copy]
48
- copy.each do |dest|
49
- STDERR.puts "Copying to #{dest}"
50
- dbucket, dkey = dest.split(':', 2)
51
- s3.copy_object(
52
- bucket: dbucket,
53
- key: dkey,
54
- copy_source: "/#{bucket}/#{key}",
55
- **options[:params] || {},
56
- )
57
- end
58
- end
59
- end
60
-
61
- if options[:file] == '-'
62
- upload(STDIN, options)
63
- elsif options[:file]
64
- File.open(options[:file]) do |f|
65
- upload(f, options)
66
- end
67
- else
68
- upload(STDIN, options)
69
- end
@@ -1,16 +0,0 @@
1
- # Modeled after
2
- # https://github.com/mongodb-labs/drivers-evergreen-tools/blob/master/.evergreen/run-load-balancer.sh
3
-
4
- defaults
5
- mode tcp
6
- timeout connect 7s
7
- timeout client 55s
8
- timeout server 55s
9
-
10
- frontend mongos_frontend
11
- bind *:27017
12
- use_backend mongos_backend
13
-
14
- backend mongos_backend
15
- mode tcp
16
- server mongos_one 127.0.0.1:27117 check
@@ -1,17 +0,0 @@
1
- # Modeled after
2
- # https://github.com/mongodb-labs/drivers-evergreen-tools/blob/master/.evergreen/run-load-balancer.sh
3
-
4
- defaults
5
- mode tcp
6
- timeout connect 7s
7
- timeout client 55s
8
- timeout server 55s
9
-
10
- frontend mongos_frontend
11
- bind *:27017
12
- use_backend mongos_backend
13
-
14
- backend mongos_backend
15
- mode tcp
16
- server mongos_one 127.0.0.1:27117 check
17
- server mongos_two 127.0.0.1:27118 check
@@ -1,158 +0,0 @@
1
- # frozen_string_literal: true
2
- # encoding: utf-8
3
-
4
- require 'singleton'
5
-
6
- class ClusterConfig
7
- include Singleton
8
-
9
- def single_server?
10
- determine_cluster_config
11
- @single_server
12
- end
13
-
14
- def replica_set_name
15
- determine_cluster_config
16
- @replica_set_name
17
- end
18
-
19
- def server_version
20
- determine_cluster_config
21
- @server_version
22
- end
23
-
24
- def short_server_version
25
- server_version.split('.')[0..1].join('.')
26
- end
27
-
28
- def fcv
29
- determine_cluster_config
30
- @fcv
31
- end
32
-
33
- # Per https://jira.mongodb.org/browse/SERVER-39052, working with FCV
34
- # in sharded topologies is annoying. Also, FCV doesn't exist in servers
35
- # less than 3.4. This method returns FCV on 3.4+ servers when in single
36
- # or RS topologies, and otherwise returns the major.minor server version.
37
- def fcv_ish
38
- if server_version >= '3.4' && topology != :sharded
39
- fcv
40
- else
41
- if short_server_version == '4.1'
42
- '4.2'
43
- else
44
- short_server_version
45
- end
46
- end
47
- end
48
-
49
- def primary_address
50
- determine_cluster_config
51
- @primary_address
52
- end
53
-
54
- def primary_address_str
55
- determine_cluster_config
56
- @primary_address.seed
57
- end
58
-
59
- def primary_address_host
60
- both = primary_address_str
61
- both.split(':').first
62
- end
63
-
64
- def primary_address_port
65
- both = primary_address_str
66
- both.split(':')[1] || 27017
67
- end
68
-
69
- def primary_description
70
- determine_cluster_config
71
- @primary_description
72
- end
73
-
74
- # Try running a command on the admin database to see if the mongod was
75
- # started with auth.
76
- def auth_enabled?
77
- if @auth_enabled.nil?
78
- @auth_enabled = begin
79
- basic_client.use(:admin).command(getCmdLineOpts: 1).first["argv"].include?("--auth")
80
- rescue => e
81
- e.message =~ /(not authorized)|(unauthorized)|(no users authenticated)|(requires authentication)/
82
- end
83
- end
84
- @auth_enabled
85
- end
86
-
87
- def topology
88
- determine_cluster_config
89
- @topology
90
- end
91
-
92
- def storage_engine
93
- @storage_engine ||= begin
94
- # 2.6 does not have wired tiger
95
- if short_server_version == '2.6'
96
- :mmapv1
97
- else
98
- client = ClientRegistry.instance.global_client('root_authorized')
99
- if topology == :sharded
100
- shards = client.use(:admin).command(listShards: 1).first
101
- shard = shards['shards'].first
102
- address_str = shard['host'].sub(/\A.*\//, '').sub(/,.*/, '')
103
- client = ClusterTools.instance.direct_client(address_str,
104
- SpecConfig.instance.test_options.merge(SpecConfig.instance.auth_options).merge(connect: :direct))
105
- end
106
- rv = client.use(:admin).command(serverStatus: 1).first
107
- rv = rv['storageEngine']['name']
108
- rv_map = {
109
- 'wiredTiger' => :wired_tiger,
110
- 'mmapv1' => :mmapv1,
111
- }
112
- rv_map[rv] || rv
113
- end
114
- end
115
- end
116
-
117
- private
118
-
119
- def determine_cluster_config
120
- return if @primary_address
121
-
122
- # Run all commands to figure out the cluster configuration from the same
123
- # client. This is somewhat wasteful when running a single test, but reduces
124
- # test runtime for the suite overall because all commands are sent on the
125
- # same connection rather than each command connecting to the cluster by
126
- # itself.
127
- client = Mongoid::Clients.default
128
-
129
- primary = client.cluster.next_primary
130
- @primary_address = primary.address
131
- @primary_description = primary.description
132
- @replica_set_name = client.cluster.topology.replica_set_name
133
-
134
- @topology ||= begin
135
- topology = client.cluster.topology.class.name.sub(/.*::/, '')
136
- topology = topology.gsub(/([A-Z])/) { |match| '_' + match.downcase }.sub(/\A_/, '')
137
- if topology =~ /\Areplica_set/
138
- topology = 'replica_set'
139
- end
140
- topology.to_sym
141
- end
142
-
143
- @single_server = client.cluster.send(:servers_list).length == 1
144
-
145
- @server_version = client.database.command(buildInfo: 1).first['version']
146
-
147
- if @topology != :sharded && short_server_version >= '3.4'
148
- rv = client.use(:admin).command(getParameter: 1, featureCompatibilityVersion: 1).first['featureCompatibilityVersion']
149
- @fcv = rv['version'] || rv
150
- end
151
- end
152
-
153
- def basic_client
154
- # Do not cache the result here so that if the client gets closed,
155
- # client registry reconnects it in subsequent tests
156
- ClientRegistry.instance.global_client('basic')
157
- end
158
- end