mongoid 7.4.0 → 8.0.1

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.
Files changed (315) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +3 -3
  4. data/lib/config/locales/en.yml +51 -28
  5. data/lib/mongoid/association/accessors.rb +32 -3
  6. data/lib/mongoid/association/bindable.rb +48 -0
  7. data/lib/mongoid/association/builders.rb +4 -2
  8. data/lib/mongoid/association/eager_loadable.rb +29 -7
  9. data/lib/mongoid/association/embedded/batchable.rb +48 -8
  10. data/lib/mongoid/association/embedded/embedded_in/binding.rb +24 -2
  11. data/lib/mongoid/association/embedded/embedded_in.rb +2 -1
  12. data/lib/mongoid/association/embedded/embeds_many/binding.rb +1 -0
  13. data/lib/mongoid/association/embedded/embeds_many/buildable.rb +1 -1
  14. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +40 -18
  15. data/lib/mongoid/association/embedded/embeds_one/buildable.rb +18 -4
  16. data/lib/mongoid/association/embedded/embeds_one/proxy.rb +21 -2
  17. data/lib/mongoid/association/macros.rb +22 -1
  18. data/lib/mongoid/association/many.rb +5 -0
  19. data/lib/mongoid/association/nested/many.rb +2 -1
  20. data/lib/mongoid/association/proxy.rb +12 -0
  21. data/lib/mongoid/association/referenced/auto_save.rb +3 -2
  22. data/lib/mongoid/association/referenced/belongs_to/binding.rb +1 -0
  23. data/lib/mongoid/association/referenced/belongs_to/buildable.rb +1 -1
  24. data/lib/mongoid/association/referenced/belongs_to.rb +1 -1
  25. data/lib/mongoid/association/referenced/counter_cache.rb +8 -8
  26. data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +64 -11
  27. data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +4 -1
  28. data/lib/mongoid/association/referenced/has_many/enumerable.rb +10 -14
  29. data/lib/mongoid/association/referenced/has_many/proxy.rb +12 -9
  30. data/lib/mongoid/association/referenced/has_one/buildable.rb +1 -1
  31. data/lib/mongoid/association/referenced/has_one/proxy.rb +8 -11
  32. data/lib/mongoid/association/referenced/syncable.rb +2 -2
  33. data/lib/mongoid/association/relatable.rb +38 -4
  34. data/lib/mongoid/atomic/paths/embedded/many.rb +19 -0
  35. data/lib/mongoid/attributes/processing.rb +9 -2
  36. data/lib/mongoid/attributes.rb +30 -27
  37. data/lib/mongoid/changeable.rb +37 -2
  38. data/lib/mongoid/clients/options.rb +4 -0
  39. data/lib/mongoid/clients/sessions.rb +2 -14
  40. data/lib/mongoid/config/environment.rb +20 -4
  41. data/lib/mongoid/config.rb +25 -10
  42. data/lib/mongoid/contextual/aggregable/memory.rb +23 -15
  43. data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
  44. data/lib/mongoid/contextual/map_reduce.rb +2 -2
  45. data/lib/mongoid/contextual/memory.rb +176 -17
  46. data/lib/mongoid/contextual/mongo.rb +226 -206
  47. data/lib/mongoid/contextual/none.rb +66 -4
  48. data/lib/mongoid/copyable.rb +32 -8
  49. data/lib/mongoid/criteria/includable.rb +24 -20
  50. data/lib/mongoid/criteria/marshalable.rb +10 -2
  51. data/lib/mongoid/criteria/queryable/extensions/array.rb +2 -13
  52. data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +25 -4
  53. data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
  54. data/lib/mongoid/criteria/queryable/extensions/date.rb +6 -1
  55. data/lib/mongoid/criteria/queryable/extensions/date_time.rb +6 -1
  56. data/lib/mongoid/criteria/queryable/extensions/hash.rb +0 -14
  57. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -1
  58. data/lib/mongoid/criteria/queryable/extensions/object.rb +2 -1
  59. data/lib/mongoid/criteria/queryable/extensions/range.rb +13 -5
  60. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +1 -1
  61. data/lib/mongoid/criteria/queryable/extensions/symbol.rb +3 -1
  62. data/lib/mongoid/criteria/queryable/extensions/time.rb +6 -1
  63. data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +6 -1
  64. data/lib/mongoid/criteria/queryable/mergeable.rb +21 -0
  65. data/lib/mongoid/criteria/queryable/optional.rb +3 -9
  66. data/lib/mongoid/criteria/queryable/options.rb +1 -1
  67. data/lib/mongoid/criteria/queryable/selectable.rb +28 -34
  68. data/lib/mongoid/criteria/queryable/selector.rb +89 -4
  69. data/lib/mongoid/criteria/queryable/smash.rb +39 -6
  70. data/lib/mongoid/criteria/queryable.rb +11 -6
  71. data/lib/mongoid/criteria.rb +1 -26
  72. data/lib/mongoid/deprecable.rb +36 -0
  73. data/lib/mongoid/deprecation.rb +25 -0
  74. data/lib/mongoid/document.rb +96 -32
  75. data/lib/mongoid/errors/document_not_found.rb +29 -8
  76. data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +23 -0
  77. data/lib/mongoid/errors/invalid_field.rb +5 -1
  78. data/lib/mongoid/errors/invalid_field_type.rb +26 -0
  79. data/lib/mongoid/errors/too_many_nested_attribute_records.rb +1 -1
  80. data/lib/mongoid/errors.rb +2 -2
  81. data/lib/mongoid/extensions/array.rb +8 -6
  82. data/lib/mongoid/extensions/big_decimal.rb +29 -10
  83. data/lib/mongoid/extensions/binary.rb +42 -0
  84. data/lib/mongoid/extensions/boolean.rb +8 -2
  85. data/lib/mongoid/extensions/date.rb +26 -20
  86. data/lib/mongoid/extensions/date_time.rb +1 -1
  87. data/lib/mongoid/extensions/float.rb +4 -5
  88. data/lib/mongoid/extensions/hash.rb +12 -5
  89. data/lib/mongoid/extensions/integer.rb +4 -5
  90. data/lib/mongoid/extensions/object.rb +2 -0
  91. data/lib/mongoid/extensions/range.rb +41 -10
  92. data/lib/mongoid/extensions/regexp.rb +11 -4
  93. data/lib/mongoid/extensions/set.rb +11 -4
  94. data/lib/mongoid/extensions/string.rb +2 -13
  95. data/lib/mongoid/extensions/symbol.rb +3 -14
  96. data/lib/mongoid/extensions/time.rb +27 -16
  97. data/lib/mongoid/extensions/time_with_zone.rb +1 -2
  98. data/lib/mongoid/extensions.rb +1 -0
  99. data/lib/mongoid/factory.rb +42 -7
  100. data/lib/mongoid/fields/foreign_key.rb +7 -0
  101. data/lib/mongoid/fields/validators/macro.rb +3 -9
  102. data/lib/mongoid/fields.rb +194 -28
  103. data/lib/mongoid/findable.rb +27 -7
  104. data/lib/mongoid/indexable/specification.rb +1 -1
  105. data/lib/mongoid/indexable/validators/options.rb +4 -1
  106. data/lib/mongoid/interceptable.rb +69 -9
  107. data/lib/mongoid/persistable/creatable.rb +14 -5
  108. data/lib/mongoid/persistable/updatable.rb +12 -5
  109. data/lib/mongoid/persistable/upsertable.rb +1 -1
  110. data/lib/mongoid/persistence_context.rb +19 -2
  111. data/lib/mongoid/query_cache.rb +6 -258
  112. data/lib/mongoid/railties/controller_runtime.rb +1 -1
  113. data/lib/mongoid/reloadable.rb +7 -3
  114. data/lib/mongoid/selectable.rb +1 -2
  115. data/lib/mongoid/stateful.rb +27 -1
  116. data/lib/mongoid/timestamps/created.rb +1 -1
  117. data/lib/mongoid/timestamps/updated.rb +1 -1
  118. data/lib/mongoid/touchable.rb +2 -3
  119. data/lib/mongoid/traversable.rb +5 -1
  120. data/lib/mongoid/validatable/uniqueness.rb +2 -1
  121. data/lib/mongoid/version.rb +1 -1
  122. data/lib/mongoid/warnings.rb +28 -0
  123. data/lib/mongoid.rb +2 -0
  124. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +11 -5
  125. data/spec/config/mongoid.yml +16 -0
  126. data/spec/config/mongoid_with_schema_map_uuid.yml +27 -0
  127. data/spec/integration/app_spec.rb +28 -26
  128. data/spec/integration/associations/belongs_to_spec.rb +18 -0
  129. data/spec/integration/associations/embedded_dirty_spec.rb +28 -0
  130. data/spec/integration/associations/embedded_spec.rb +15 -0
  131. data/spec/integration/associations/embeds_many_spec.rb +15 -2
  132. data/spec/integration/associations/embeds_one_spec.rb +18 -0
  133. data/spec/integration/associations/foreign_key_spec.rb +9 -0
  134. data/spec/integration/associations/has_and_belongs_to_many_spec.rb +21 -0
  135. data/spec/integration/associations/has_one_spec.rb +97 -1
  136. data/spec/integration/associations/scope_option_spec.rb +1 -1
  137. data/spec/integration/callbacks_models.rb +95 -1
  138. data/spec/integration/callbacks_spec.rb +226 -4
  139. data/spec/integration/criteria/range_spec.rb +95 -1
  140. data/spec/integration/discriminator_key_spec.rb +115 -76
  141. data/spec/integration/dots_and_dollars_spec.rb +277 -0
  142. data/spec/integration/matcher_examples_spec.rb +20 -13
  143. data/spec/integration/matcher_operator_data/type_decimal.yml +3 -2
  144. data/spec/integration/matcher_operator_spec.rb +3 -5
  145. data/spec/integration/persistence/range_field_spec.rb +350 -0
  146. data/spec/lite_spec_helper.rb +1 -1
  147. data/spec/mongoid/association/counter_cache_spec.rb +1 -1
  148. data/spec/mongoid/association/depending_spec.rb +9 -9
  149. data/spec/mongoid/association/eager_spec.rb +2 -1
  150. data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +2 -1
  151. data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +54 -0
  152. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +69 -9
  153. data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +112 -0
  154. data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +219 -8
  155. data/spec/mongoid/association/embedded/embeds_many_models.rb +157 -0
  156. data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +12 -0
  157. data/spec/mongoid/association/embedded/embeds_many_spec.rb +68 -0
  158. data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +25 -0
  159. data/spec/mongoid/association/embedded/embeds_one_models.rb +19 -0
  160. data/spec/mongoid/association/embedded/embeds_one_spec.rb +28 -0
  161. data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +2 -1
  162. data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +54 -0
  163. data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +15 -0
  164. data/spec/mongoid/association/referenced/belongs_to_models.rb +11 -0
  165. data/spec/mongoid/association/referenced/belongs_to_spec.rb +2 -2
  166. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +67 -4
  167. data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +25 -0
  168. data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +35 -2
  169. data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +109 -0
  170. data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +8 -8
  171. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +82 -13
  172. data/spec/mongoid/association/referenced/has_many_models.rb +3 -1
  173. data/spec/mongoid/association/referenced/has_many_spec.rb +25 -0
  174. data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +2 -2
  175. data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +107 -1
  176. data/spec/mongoid/association/referenced/has_one_models.rb +16 -0
  177. data/spec/mongoid/association/syncable_spec.rb +14 -0
  178. data/spec/mongoid/atomic/paths_spec.rb +0 -14
  179. data/spec/mongoid/atomic_spec.rb +22 -0
  180. data/spec/mongoid/attributes/nested_spec.rb +80 -11
  181. data/spec/mongoid/attributes/nested_spec_models.rb +48 -0
  182. data/spec/mongoid/attributes/projector_spec.rb +1 -5
  183. data/spec/mongoid/attributes_spec.rb +524 -27
  184. data/spec/mongoid/changeable_spec.rb +130 -13
  185. data/spec/mongoid/clients/factory_spec.rb +34 -42
  186. data/spec/mongoid/clients/options_spec.rb +1 -0
  187. data/spec/mongoid/clients/sessions_spec.rb +0 -38
  188. data/spec/mongoid/clients_spec.rb +32 -2
  189. data/spec/mongoid/config/environment_spec.rb +39 -1
  190. data/spec/mongoid/config_spec.rb +104 -13
  191. data/spec/mongoid/contextual/aggregable/memory_spec.rb +396 -158
  192. data/spec/mongoid/contextual/aggregable/memory_table.yml +88 -0
  193. data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +62 -0
  194. data/spec/mongoid/contextual/map_reduce_spec.rb +2 -16
  195. data/spec/mongoid/contextual/memory_spec.rb +1337 -69
  196. data/spec/mongoid/contextual/mongo_spec.rb +1105 -172
  197. data/spec/mongoid/contextual/none_spec.rb +38 -0
  198. data/spec/mongoid/copyable_spec.rb +451 -1
  199. data/spec/mongoid/criteria/findable_spec.rb +86 -210
  200. data/spec/mongoid/criteria/includable_spec.rb +1492 -0
  201. data/spec/mongoid/criteria/includable_spec_models.rb +54 -0
  202. data/spec/mongoid/criteria/marshalable_spec.rb +18 -1
  203. data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +7 -19
  204. data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +134 -26
  205. data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +11 -0
  206. data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +11 -0
  207. data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +0 -15
  208. data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +73 -7
  209. data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +11 -0
  210. data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +11 -0
  211. data/spec/mongoid/criteria/queryable/optional_spec.rb +0 -484
  212. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +50 -0
  213. data/spec/mongoid/criteria/queryable/selectable_spec.rb +289 -124
  214. data/spec/mongoid/criteria/queryable/selector_spec.rb +14 -2
  215. data/spec/mongoid/criteria_spec.rb +474 -1198
  216. data/spec/mongoid/document_fields_spec.rb +173 -24
  217. data/spec/mongoid/document_spec.rb +32 -41
  218. data/spec/mongoid/errors/document_not_found_spec.rb +76 -0
  219. data/spec/mongoid/errors/invalid_field_spec.rb +1 -1
  220. data/spec/mongoid/errors/invalid_field_type_spec.rb +55 -0
  221. data/spec/mongoid/errors/mongoid_error_spec.rb +3 -1
  222. data/spec/mongoid/errors/no_environment_spec.rb +3 -3
  223. data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +1 -1
  224. data/spec/mongoid/extensions/array_spec.rb +16 -2
  225. data/spec/mongoid/extensions/big_decimal_spec.rb +697 -212
  226. data/spec/mongoid/extensions/binary_spec.rb +44 -9
  227. data/spec/mongoid/extensions/boolean_spec.rb +68 -82
  228. data/spec/mongoid/extensions/date_class_mongoize_spec.rb +7 -3
  229. data/spec/mongoid/extensions/date_spec.rb +71 -1
  230. data/spec/mongoid/extensions/date_time_spec.rb +15 -9
  231. data/spec/mongoid/extensions/float_spec.rb +48 -76
  232. data/spec/mongoid/extensions/hash_spec.rb +30 -0
  233. data/spec/mongoid/extensions/integer_spec.rb +45 -66
  234. data/spec/mongoid/extensions/range_spec.rb +255 -54
  235. data/spec/mongoid/extensions/regexp_spec.rb +58 -33
  236. data/spec/mongoid/extensions/set_spec.rb +106 -0
  237. data/spec/mongoid/extensions/string_spec.rb +53 -25
  238. data/spec/mongoid/extensions/symbol_spec.rb +18 -25
  239. data/spec/mongoid/extensions/time_spec.rb +634 -66
  240. data/spec/mongoid/extensions/time_with_zone_spec.rb +17 -31
  241. data/spec/mongoid/factory_spec.rb +61 -1
  242. data/spec/mongoid/fields_spec.rb +321 -50
  243. data/spec/mongoid/findable_spec.rb +80 -15
  244. data/spec/mongoid/indexable/specification_spec.rb +2 -2
  245. data/spec/mongoid/indexable_spec.rb +16 -19
  246. data/spec/mongoid/interceptable_spec.rb +584 -5
  247. data/spec/mongoid/interceptable_spec_models.rb +235 -4
  248. data/spec/mongoid/matcher/extract_attribute_spec.rb +1 -5
  249. data/spec/mongoid/mongoizable_spec.rb +285 -0
  250. data/spec/mongoid/persistable/creatable_spec.rb +2 -2
  251. data/spec/mongoid/persistable/deletable_spec.rb +2 -2
  252. data/spec/mongoid/persistable/destroyable_spec.rb +2 -2
  253. data/spec/mongoid/persistable/upsertable_spec.rb +14 -0
  254. data/spec/mongoid/persistence_context_spec.rb +50 -1
  255. data/spec/mongoid/query_cache_middleware_spec.rb +0 -18
  256. data/spec/mongoid/query_cache_spec.rb +0 -154
  257. data/spec/mongoid/reloadable_spec.rb +35 -2
  258. data/spec/mongoid/scopable_spec.rb +21 -1
  259. data/spec/mongoid/shardable_spec.rb +14 -0
  260. data/spec/mongoid/stateful_spec.rb +28 -0
  261. data/spec/mongoid/timestamps_spec.rb +390 -0
  262. data/spec/mongoid/timestamps_spec_models.rb +67 -0
  263. data/spec/mongoid/touchable_spec.rb +116 -0
  264. data/spec/mongoid/touchable_spec_models.rb +12 -8
  265. data/spec/mongoid/traversable_spec.rb +4 -11
  266. data/spec/mongoid/validatable/presence_spec.rb +1 -1
  267. data/spec/mongoid/validatable/uniqueness_spec.rb +60 -31
  268. data/spec/mongoid/warnings_spec.rb +35 -0
  269. data/spec/rails/controller_extension/controller_runtime_spec.rb +2 -2
  270. data/spec/rails/mongoid_spec.rb +4 -16
  271. data/spec/shared/lib/mrss/constraints.rb +8 -16
  272. data/spec/shared/lib/mrss/docker_runner.rb +23 -3
  273. data/spec/shared/lib/mrss/eg_config_utils.rb +51 -0
  274. data/spec/shared/lib/mrss/lite_constraints.rb +32 -1
  275. data/spec/shared/share/Dockerfile.erb +34 -48
  276. data/spec/shared/shlib/config.sh +27 -0
  277. data/spec/shared/shlib/server.sh +32 -19
  278. data/spec/shared/shlib/set_env.sh +37 -0
  279. data/spec/support/constraints.rb +24 -0
  280. data/spec/support/macros.rb +39 -0
  281. data/spec/support/models/augmentation.rb +12 -0
  282. data/spec/support/models/band.rb +3 -0
  283. data/spec/support/models/catalog.rb +24 -0
  284. data/spec/support/models/circus.rb +3 -0
  285. data/spec/support/models/code.rb +2 -0
  286. data/spec/support/models/fanatic.rb +8 -0
  287. data/spec/support/models/implant.rb +9 -0
  288. data/spec/support/models/label.rb +2 -0
  289. data/spec/support/models/membership.rb +1 -0
  290. data/spec/support/models/passport.rb +9 -0
  291. data/spec/support/models/person.rb +1 -0
  292. data/spec/support/models/player.rb +2 -0
  293. data/spec/support/models/powerup.rb +12 -0
  294. data/spec/support/models/registry.rb +1 -0
  295. data/spec/support/models/school.rb +14 -0
  296. data/spec/support/models/shield.rb +18 -0
  297. data/spec/support/models/student.rb +14 -0
  298. data/spec/support/models/weapon.rb +12 -0
  299. data/spec/support/schema_maps/schema_map_aws.json +17 -0
  300. data/spec/support/schema_maps/schema_map_aws_key_alt_names.json +12 -0
  301. data/spec/support/schema_maps/schema_map_azure.json +17 -0
  302. data/spec/support/schema_maps/schema_map_azure_key_alt_names.json +12 -0
  303. data/spec/support/schema_maps/schema_map_gcp.json +17 -0
  304. data/spec/support/schema_maps/schema_map_gcp_key_alt_names.json +12 -0
  305. data/spec/support/schema_maps/schema_map_kmip.json +17 -0
  306. data/spec/support/schema_maps/schema_map_kmip_key_alt_names.json +12 -0
  307. data/spec/support/schema_maps/schema_map_local.json +18 -0
  308. data/spec/support/schema_maps/schema_map_local_key_alt_names.json +12 -0
  309. data/spec/support/spec_config.rb +4 -0
  310. data.tar.gz.sig +0 -0
  311. metadata +76 -13
  312. metadata.gz.sig +0 -0
  313. data/lib/mongoid/errors/eager_load.rb +0 -23
  314. data/lib/mongoid/errors/invalid_value.rb +0 -17
  315. data/spec/mongoid/errors/eager_load_spec.rb +0 -31
@@ -8,401 +8,886 @@ describe Mongoid::Extensions::BigDecimal do
8
8
  BigDecimal("123456.789")
9
9
  end
10
10
 
11
- describe ".demongoize" do
11
+ context 'when map_big_decimal_to_decimal128 is false' do
12
+ config_override :map_big_decimal_to_decimal128, false
12
13
 
13
- context "when the value is an empty String" do
14
+ describe ".demongoize" do
14
15
 
15
- let(:string) do
16
- ""
16
+ let(:demongoized) do
17
+ BigDecimal.demongoize(value)
17
18
  end
18
19
 
19
- it "returns nil" do
20
- expect(BigDecimal.demongoize(string)).to be_nil
20
+ context "when the value is an empty String" do
21
+
22
+ let(:value) do
23
+ ""
24
+ end
25
+
26
+ it "raises an error" do
27
+ expect(demongoized).to be_nil
28
+ end
21
29
  end
22
- end
23
30
 
24
- context "when the value is a numeric String" do
31
+ context "when the value is a numeric String" do
32
+
33
+ let(:value) do
34
+ "123456.789"
35
+ end
25
36
 
26
- let(:string) do
27
- "123456.789"
37
+ it "returns a BigDecimal" do
38
+ expect(demongoized).to eq(BigDecimal(value))
39
+ end
28
40
  end
29
41
 
30
- it "returns a BigDecimal" do
31
- expect(BigDecimal.demongoize(string)).to eq(BigDecimal(string))
42
+ context "when the value is the numeric String zero" do
43
+
44
+ let(:value) do
45
+ "0.0"
46
+ end
47
+
48
+ it "returns a BigDecimal" do
49
+ expect(demongoized).to eq(BigDecimal(value))
50
+ end
32
51
  end
33
- end
34
52
 
35
- context "when the value is the numeric String zero" do
53
+ context "when the value is the numeric String negative zero" do
54
+
55
+ let(:value) do
56
+ "-0.0"
57
+ end
36
58
 
37
- let(:string) do
38
- "0.0"
59
+ it "returns a BigDecimal" do
60
+ expect(demongoized).to eq(BigDecimal(value))
61
+ end
39
62
  end
40
63
 
41
- it "returns a BigDecimal" do
42
- expect(BigDecimal.demongoize(string)).to eq(BigDecimal(string))
64
+ context "when the value is a non-numeric String" do
65
+
66
+ let(:value) do
67
+ "1a2"
68
+ end
69
+
70
+ it "returns nil" do
71
+ expect(demongoized).to be_nil
72
+ end
43
73
  end
44
- end
45
74
 
46
- context "when the value is the numeric String negative zero" do
75
+ context "when the value is nil" do
47
76
 
48
- let(:string) do
49
- "-0.0"
77
+ let(:value) do
78
+ nil
79
+ end
80
+
81
+ it "returns nil" do
82
+ expect(demongoized).to be_nil
83
+ end
50
84
  end
51
85
 
52
- it "returns a BigDecimal" do
53
- expect(BigDecimal.demongoize(string)).to eq(BigDecimal(string))
86
+ context "when the value is true" do
87
+
88
+ let(:value) do
89
+ true
90
+ end
91
+
92
+ it "returns nil" do
93
+ expect(demongoized).to be_nil
94
+ end
54
95
  end
55
- end
56
96
 
57
- context "when the value is a non-numeric String" do
97
+ context "when the value is false" do
98
+
99
+ let(:value) do
100
+ false
101
+ end
58
102
 
59
- let(:string) do
60
- "1a2"
103
+ it "returns nil" do
104
+ expect(demongoized).to be_nil
105
+ end
61
106
  end
62
107
 
63
- it "returns nil" do
64
- expect(BigDecimal.demongoize(string)).to be_nil
108
+ context "when the value is an Integer" do
109
+
110
+ let(:value) do
111
+ 123456
112
+ end
113
+
114
+ it "returns an integer" do
115
+ expect(demongoized).to eq(value)
116
+ end
65
117
  end
66
- end
67
118
 
68
- context "when the value is nil" do
119
+ context "when the value is a Float" do
120
+
121
+ let(:value) do
122
+ 123456.789
123
+ end
69
124
 
70
- it "returns nil" do
71
- expect(BigDecimal.demongoize(nil)).to be_nil
125
+ it "returns a float" do
126
+ expect(demongoized).to eq(value)
127
+ end
72
128
  end
73
- end
74
129
 
75
- context "when the value is true" do
130
+ context "when the value is the String 'NaN'" do
131
+
132
+ let(:value) do
133
+ "NaN"
134
+ end
76
135
 
77
- let(:value) do
78
- true
136
+ it "returns a BigDecimal" do
137
+ expect(demongoized).to be_a(BigDecimal)
138
+ end
139
+
140
+ it "is a NaN BigDecimal" do
141
+ expect(demongoized).to be_nan
142
+ end
79
143
  end
80
144
 
81
- it "returns nil" do
82
- expect(BigDecimal.demongoize(value)).to be_nil
145
+ context "when the value is the String 'Infinity'" do
146
+
147
+ let(:value) do
148
+ "Infinity"
149
+ end
150
+
151
+ it "returns a BigDecimal" do
152
+ expect(demongoized).to be_a(BigDecimal)
153
+ end
154
+
155
+ it "is a infinity BigDecimal" do
156
+ expect(demongoized.infinite?).to eq 1
157
+ end
83
158
  end
84
- end
85
159
 
86
- context "when the value is false" do
160
+ context "when the value is the String '-Infinity'" do
161
+
162
+ let(:value) do
163
+ "-Infinity"
164
+ end
87
165
 
88
- let(:value) do
89
- false
166
+ it "returns a BigDecimal" do
167
+ expect(demongoized).to be_a(BigDecimal)
168
+ end
169
+
170
+ it "is a negative infinity BigDecimal" do
171
+ expect(demongoized.infinite?).to eq -1
172
+ end
90
173
  end
91
174
 
92
- it "returns nil" do
93
- expect(BigDecimal.demongoize(value)).to be_nil
175
+ context "when the value is a BSON::Decimal128" do
176
+
177
+ let(:value) do
178
+ BSON::Decimal128.new("1.2")
179
+ end
180
+
181
+ it "does not raise an error" do
182
+ expect do
183
+ demongoized
184
+ end.to_not raise_error
185
+ end
186
+
187
+ it "returns a big decimal" do
188
+ expect(demongoized).to eq(value.to_big_decimal)
189
+ end
94
190
  end
95
191
  end
96
192
 
97
- context "when the value is an Integer" do
193
+ describe ".mongoize" do
98
194
 
99
- let(:integer) do
100
- 123456
195
+ let(:mongoized) do
196
+ BigDecimal.mongoize(value)
101
197
  end
102
198
 
103
- it "returns an integer" do
104
- expect(BigDecimal.demongoize(integer)).to eq(integer)
199
+ context "when the value is a BigDecimal" do
200
+
201
+ let(:value) do
202
+ big_decimal
203
+ end
204
+
205
+ it "returns a string" do
206
+ expect(mongoized).to eq(value.to_s)
207
+ end
105
208
  end
106
- end
107
209
 
108
- context "when the value is a Float" do
210
+ context "when the value is the BigDecimal zero" do
211
+
212
+ let(:value) do
213
+ BigDecimal("0.0")
214
+ end
109
215
 
110
- let(:float) do
111
- 123456.789
216
+ it "returns a string" do
217
+ expect(mongoized).to eq(value.to_s)
218
+ end
112
219
  end
113
220
 
114
- it "returns a float" do
115
- expect(BigDecimal.demongoize(float)).to eq(float)
221
+ context "when the value is the BigDecimal negative zero" do
222
+
223
+ let(:value) do
224
+ BigDecimal("-0.0")
225
+ end
226
+
227
+ it "returns a string" do
228
+ expect(mongoized).to eq(value.to_s)
229
+ end
116
230
  end
117
- end
118
231
 
119
- context "when the value is the String 'NaN'" do
232
+ context "when the value is an empty String" do
233
+
234
+ let(:value) do
235
+ ""
236
+ end
120
237
 
121
- let(:nan) do
122
- "NaN"
238
+ it "returns nil" do
239
+ expect(mongoized).to be_nil
240
+ end
123
241
  end
124
242
 
125
- let(:demongoized) do
126
- BigDecimal.demongoize(nan)
243
+ context "when the value is an integer numeric String" do
244
+
245
+ let(:value) do
246
+ "123456"
247
+ end
248
+
249
+ it "returns the String" do
250
+ expect(mongoized).to eq(value)
251
+ end
127
252
  end
128
253
 
129
- it "returns a BigDecimal" do
130
- expect(demongoized).to be_a(BigDecimal)
254
+ context "when the value is a float numeric String" do
255
+
256
+ let(:value) do
257
+ "123456.789"
258
+ end
259
+
260
+ it "returns the String" do
261
+ expect(mongoized).to eq(value)
262
+ end
131
263
  end
132
264
 
133
- it "is a NaN BigDecimal" do
134
- expect(demongoized).to be_nan
265
+ context "when the value is a non-numeric String" do
266
+
267
+ let(:value) do
268
+ "1a2"
269
+ end
270
+
271
+ it "returns nil" do
272
+ expect(mongoized).to be_nil
273
+ end
135
274
  end
136
- end
137
275
 
138
- context "when the value is the String 'Infinity'" do
276
+ context "when the value is nil" do
139
277
 
140
- let(:infinity) do
141
- "Infinity"
278
+ let(:value) do
279
+ nil
280
+ end
281
+
282
+ it "returns nil" do
283
+ expect(mongoized).to be_nil
284
+ end
142
285
  end
143
286
 
144
- let(:demongoized) do
145
- BigDecimal.demongoize(infinity)
287
+ context "when the value is true" do
288
+
289
+ let(:value) do
290
+ true
291
+ end
292
+
293
+ it "returns nil" do
294
+ expect(mongoized).to be_nil
295
+ end
146
296
  end
147
297
 
148
- it "returns a BigDecimal" do
149
- expect(demongoized).to be_a(BigDecimal)
298
+ context "when the value is false" do
299
+
300
+ let(:value) do
301
+ false
302
+ end
303
+
304
+ it "returns nil" do
305
+ expect(mongoized).to be_nil
306
+ end
150
307
  end
151
308
 
152
- it "is a infinity BigDecimal" do
153
- expect(demongoized.infinite?).to eq 1
309
+ context "when the value is an Integer" do
310
+ let(:value) do
311
+ 123456
312
+ end
313
+
314
+ it "returns a string" do
315
+ expect(mongoized).to eq(value.to_s)
316
+ end
154
317
  end
155
- end
156
318
 
157
- context "when the value is the String '-Infinity'" do
319
+ context "when the value is a Float" do
320
+
321
+ let(:value) do
322
+ 123456.789
323
+ end
158
324
 
159
- let(:neg_infinity) do
160
- "-Infinity"
325
+ it "returns a string" do
326
+ expect(mongoized).to eq(value.to_s)
327
+ end
161
328
  end
162
329
 
163
- let(:demongoized) do
164
- BigDecimal.demongoize(neg_infinity)
330
+ context "when the value is String NaN" do
331
+
332
+ let(:value) do
333
+ "NaN"
334
+ end
335
+
336
+ it "returns a String" do
337
+ expect(mongoized).to eq("NaN")
338
+ end
165
339
  end
166
340
 
167
- it "returns a BigDecimal" do
168
- expect(demongoized).to be_a(BigDecimal)
341
+ context "when the value is String Infinity" do
342
+
343
+ let(:value) do
344
+ "Infinity"
345
+ end
346
+
347
+ it "returns a String" do
348
+ expect(mongoized).to eq("Infinity")
349
+ end
169
350
  end
170
351
 
171
- it "is a negative infinity BigDecimal" do
172
- expect(demongoized.infinite?).to eq -1
352
+ context "when the value is String negative Infinity" do
353
+
354
+ let(:value) do
355
+ "-Infinity"
356
+ end
357
+
358
+ it "returns a String" do
359
+ expect(mongoized).to eq("-Infinity")
360
+ end
173
361
  end
174
- end
175
- end
176
362
 
177
- describe ".mongoize" do
363
+ context "when the value is BigDecimal NaN" do
178
364
 
179
- context "when the value is a BigDecimal" do
365
+ let(:value) do
366
+ BigDecimal("NaN")
367
+ end
180
368
 
181
- it "returns a string" do
182
- expect(BigDecimal.mongoize(big_decimal)).to eq(big_decimal.to_s)
369
+ it "returns a String" do
370
+ expect(mongoized).to eq("NaN")
371
+ end
183
372
  end
184
- end
185
373
 
186
- context "when the value is the BigDecimal zero" do
374
+ context "when the value is BigDecimal Infinity" do
187
375
 
188
- let(:big_decimal) do
189
- BigDecimal("0.0")
376
+ let(:value) do
377
+ BigDecimal("Infinity")
378
+ end
379
+
380
+ it "returns a String" do
381
+ expect(mongoized).to eq("Infinity")
382
+ end
190
383
  end
191
384
 
192
- it "returns a BigDecimal" do
193
- expect(BigDecimal.mongoize(big_decimal)).to eq(big_decimal.to_s)
385
+ context "when the value is BigDecimal negative Infinity" do
386
+
387
+ let(:value) do
388
+ BigDecimal("-Infinity")
389
+ end
390
+
391
+ it "returns a String" do
392
+ expect(mongoized).to eq("-Infinity")
393
+ end
194
394
  end
195
- end
196
395
 
197
- context "when the value is the BigDecimal negative zero" do
396
+ context "when the value is the constant Float::NAN" do
397
+
398
+ let(:value) do
399
+ Float::NAN
400
+ end
198
401
 
199
- let(:big_decimal) do
200
- BigDecimal("-0.0")
402
+ it "returns a String" do
403
+ expect(mongoized).to eq("NaN")
404
+ end
201
405
  end
202
406
 
203
- it "returns a BigDecimal" do
204
- expect(BigDecimal.mongoize(big_decimal)).to eq(big_decimal.to_s)
407
+ context "when the value is constant Float::INFINITY" do
408
+
409
+ let(:value) do
410
+ Float::INFINITY
411
+ end
412
+
413
+ it "returns a String" do
414
+ expect(mongoized).to eq("Infinity")
415
+ end
205
416
  end
206
- end
207
417
 
208
- context "when the value is an empty String" do
418
+ context "when the value is constant Float::INFINITY * -1" do
419
+
420
+ let(:value) do
421
+ Float::INFINITY * -1
422
+ end
209
423
 
210
- let(:string) do
211
- ""
424
+ it "returns a String" do
425
+ expect(mongoized).to eq("-Infinity")
426
+ end
212
427
  end
213
428
 
214
- it "returns nil" do
215
- expect(BigDecimal.mongoize(string)).to be_nil
429
+ context "when the value is a decimal128" do
430
+ let(:value) do
431
+ BSON::Decimal128.new("42")
432
+ end
433
+
434
+ it "returns a String" do
435
+ expect(mongoized).to eq("42")
436
+ end
216
437
  end
217
438
  end
218
439
 
219
- context "when the value is an integer numeric String" do
440
+ describe "#mongoize" do
220
441
 
221
- let(:string) do
222
- "123456"
442
+ it "returns a string" do
443
+ expect(big_decimal.mongoize).to eq(big_decimal.to_s)
223
444
  end
445
+ end
224
446
 
225
- it "returns the String" do
226
- expect(BigDecimal.mongoize(string)).to eq string
447
+ describe "#numeric?" do
448
+
449
+ it "returns true" do
450
+ expect(big_decimal.numeric?).to eq(true)
227
451
  end
228
452
  end
453
+ end
454
+
455
+ context 'when map_big_decimal_to_decimal128 is true' do
456
+ config_override :map_big_decimal_to_decimal128, true
229
457
 
230
- context "when the value is a float numeric String" do
458
+ describe ".demongoize" do
231
459
 
232
- let(:string) do
233
- "123456.789"
460
+ let(:demongoized) do
461
+ BigDecimal.demongoize(value)
234
462
  end
235
463
 
236
- it "returns the String" do
237
- expect(BigDecimal.mongoize(string)).to eq string
464
+ context "when the value is an empty String" do
465
+
466
+ let(:value) do
467
+ ""
468
+ end
469
+
470
+ it "raises an error" do
471
+ expect(demongoized).to eq(nil)
472
+ end
238
473
  end
239
- end
240
474
 
241
- context "when the value is a non-numeric String" do
475
+ context "when the value is a numeric String" do
476
+
477
+ let(:value) do
478
+ "123456.789"
479
+ end
242
480
 
243
- let(:string) do
244
- "1a2"
481
+ it "returns a BigDecimal" do
482
+ expect(demongoized).to eq(BigDecimal(value))
483
+ end
245
484
  end
246
485
 
247
- it "returns nil" do
248
- expect(BigDecimal.mongoize(string)).to be_nil
486
+ context "when the value is the numeric String zero" do
487
+
488
+ let(:value) do
489
+ "0.0"
490
+ end
491
+
492
+ it "returns a BigDecimal" do
493
+ expect(demongoized).to eq(BigDecimal(value))
494
+ end
249
495
  end
250
- end
251
496
 
252
- context "when the value is nil" do
497
+ context "when the value is the numeric String negative zero" do
253
498
 
254
- it "returns nil" do
255
- expect(BigDecimal.mongoize(nil)).to be_nil
499
+ let(:value) do
500
+ "-0.0"
501
+ end
502
+
503
+ it "returns a BigDecimal" do
504
+ expect(demongoized).to eq(BigDecimal(value))
505
+ end
256
506
  end
257
- end
258
507
 
259
- context "when the value is true" do
508
+ context "when the value is a non-numeric String" do
509
+
510
+ let(:value) do
511
+ "1a2"
512
+ end
260
513
 
261
- let(:value) do
262
- true
514
+ it "returns nil" do
515
+ expect(demongoized).to be_nil
516
+ end
263
517
  end
264
518
 
265
- it "returns nil" do
266
- expect(BigDecimal.mongoize(value)).to be_nil
519
+ context "when the value is nil" do
520
+
521
+ let(:value) do
522
+ nil
523
+ end
524
+
525
+ it "returns nil" do
526
+ expect(demongoized).to be_nil
527
+ end
267
528
  end
268
- end
269
529
 
270
- context "when the value is false" do
530
+ context "when the value is an Integer" do
271
531
 
272
- let(:value) do
273
- false
532
+ let(:value) do
533
+ 123456
534
+ end
535
+
536
+ it "returns an integer" do
537
+ expect(demongoized).to eq(value)
538
+ end
274
539
  end
275
540
 
276
- it "returns nil" do
277
- expect(BigDecimal.mongoize(value)).to be_nil
541
+ context "when the value is a BSON::Decimal128 object" do
542
+
543
+ let(:value) do
544
+ BSON::Decimal128.new("123456")
545
+ end
546
+
547
+ it "returns a BigDecimal" do
548
+ expect(demongoized).to eq(value.to_big_decimal)
549
+ end
278
550
  end
279
- end
280
551
 
281
- context "when the value is an Integer" do
552
+ context "when the value is a Float" do
282
553
 
283
- it "returns a string" do
284
- expect(BigDecimal.mongoize(123456)).to eq("123456")
554
+ let(:value) do
555
+ 123456.789
556
+ end
557
+
558
+ it "returns a float" do
559
+ expect(demongoized).to eq(value)
560
+ end
285
561
  end
286
- end
287
562
 
288
- context "when the value is a Float" do
563
+ context "when the value is the String 'NaN'" do
289
564
 
290
- it "returns a string" do
291
- expect(BigDecimal.mongoize(123456.789)).to eq("123456.789")
565
+ let(:value) do
566
+ "NaN"
567
+ end
568
+
569
+ it "returns a BigDecimal" do
570
+ expect(demongoized).to be_a(BigDecimal)
571
+ end
572
+
573
+ it "is a NaN BigDecimal" do
574
+ expect(demongoized).to be_nan
575
+ end
292
576
  end
293
- end
294
577
 
295
- context "when the value is String NaN" do
578
+ context "when the value is the String 'Infinity'" do
579
+
580
+ let(:value) do
581
+ "Infinity"
582
+ end
296
583
 
297
- let(:nan) do
298
- "NaN"
584
+ it "returns a BigDecimal" do
585
+ expect(demongoized).to be_a(BigDecimal)
586
+ end
587
+
588
+ it "is a infinity BigDecimal" do
589
+ expect(demongoized.infinite?).to eq 1
590
+ end
299
591
  end
300
592
 
301
- it "returns a String" do
302
- expect(BigDecimal.mongoize(nan)).to eq("NaN")
593
+ context "when the value is the String '-Infinity'" do
594
+
595
+ let(:value) do
596
+ "-Infinity"
597
+ end
598
+
599
+ it "returns a BigDecimal" do
600
+ expect(demongoized).to be_a(BigDecimal)
601
+ end
602
+
603
+ it "is a negative infinity BigDecimal" do
604
+ expect(demongoized.infinite?).to eq -1
605
+ end
303
606
  end
304
- end
305
607
 
306
- context "when the value is String Infinity" do
608
+ context "when the value is true" do
307
609
 
308
- let(:infinity) do
309
- "Infinity"
610
+ let(:value) do
611
+ true
612
+ end
613
+
614
+ it "returns nil" do
615
+ expect(demongoized).to be_nil
616
+ end
310
617
  end
311
618
 
312
- it "returns a String" do
313
- expect(BigDecimal.mongoize(infinity)).to eq("Infinity")
619
+ context "when the value is false" do
620
+
621
+ let(:value) do
622
+ false
623
+ end
624
+
625
+ it "returns nil" do
626
+ expect(demongoized).to be_nil
627
+ end
314
628
  end
315
629
  end
316
630
 
317
- context "when the value is String negative Infinity" do
631
+ describe ".mongoize" do
318
632
 
319
- let(:neg_infinity) do
320
- "-Infinity"
633
+ let(:mongoized) do
634
+ BigDecimal.mongoize(value)
321
635
  end
322
636
 
323
- it "returns a String" do
324
- expect(BigDecimal.mongoize(neg_infinity)).to eq("-Infinity")
637
+ context "when the value is a BigDecimal" do
638
+
639
+ let(:value) do
640
+ big_decimal
641
+ end
642
+
643
+ it "returns a BSON::Decimal128" do
644
+ expect(mongoized).to eq(BSON::Decimal128.new(value))
645
+ end
325
646
  end
326
- end
327
647
 
328
- context "when the value is BigDecimal NaN" do
648
+ context "when the value is the BigDecimal zero" do
329
649
 
330
- let(:nan) do
331
- BigDecimal("NaN")
650
+ let(:value) do
651
+ BigDecimal("0.0")
652
+ end
653
+
654
+ it "returns a BSON::Decimal128" do
655
+ expect(mongoized).to eq(BSON::Decimal128.new(value))
656
+ end
332
657
  end
333
658
 
334
- it "returns a String" do
335
- expect(BigDecimal.mongoize(nan)).to eq("NaN")
659
+ context "when the value is the BigDecimal negative zero" do
660
+
661
+ let(:value) do
662
+ BigDecimal("-0.0")
663
+ end
664
+
665
+ it "returns a BSON::Decimal128" do
666
+ expect(mongoized).to eq(BSON::Decimal128.new(value))
667
+ end
336
668
  end
337
- end
338
669
 
339
- context "when the value is BigDecimal Infinity" do
670
+ context "when the value is an empty String" do
671
+
672
+ let(:value) do
673
+ ""
674
+ end
340
675
 
341
- let(:infinity) do
342
- BigDecimal("Infinity")
676
+ it "returns nil" do
677
+ expect(mongoized).to be_nil
678
+ end
343
679
  end
344
680
 
345
- it "returns a String" do
346
- expect(BigDecimal.mongoize(infinity)).to eq("Infinity")
681
+ context "when the value is an integer numeric String" do
682
+
683
+ let(:value) do
684
+ "123456"
685
+ end
686
+
687
+ it "returns the BSON::Decimal128" do
688
+ expect(mongoized).to eq(BSON::Decimal128.new(value))
689
+ end
347
690
  end
348
- end
349
691
 
350
- context "when the value is BigDecimal negative Infinity" do
692
+ context "when the value is a float numeric String" do
693
+
694
+ let(:value) do
695
+ "123456.789"
696
+ end
351
697
 
352
- let(:neg_infinity) do
353
- BigDecimal("-Infinity")
698
+ it "returns the BSON::Decimal128" do
699
+ expect(mongoized).to eq(BSON::Decimal128.new(value))
700
+ end
354
701
  end
355
702
 
356
- it "returns a String" do
357
- expect(BigDecimal.mongoize(neg_infinity)).to eq("-Infinity")
703
+ context "when the value is a non-numeric String" do
704
+
705
+ let(:value) do
706
+ "1a2"
707
+ end
708
+
709
+ it "returns nil" do
710
+ expect(mongoized).to be_nil
711
+ end
358
712
  end
359
- end
360
713
 
361
- context "when the value is the constant Float::NAN" do
714
+ context "when the value is nil" do
362
715
 
363
- let(:nan) do
364
- Float::NAN
716
+ let(:value) do
717
+ nil
718
+ end
719
+
720
+ it "returns nil" do
721
+ expect(mongoized).to be_nil
722
+ end
365
723
  end
366
724
 
367
- it "returns a String" do
368
- expect(BigDecimal.mongoize(nan)).to eq("NaN")
725
+ context "when the value is true" do
726
+
727
+ let(:value) do
728
+ true
729
+ end
730
+
731
+ it "returns nil" do
732
+ expect(mongoized).to be_nil
733
+ end
369
734
  end
370
- end
371
735
 
372
- context "when the value is constant Float::INFINITY" do
736
+ context "when the value is false" do
737
+
738
+ let(:value) do
739
+ false
740
+ end
373
741
 
374
- let(:infinity) do
375
- Float::INFINITY
742
+ it "returns nil" do
743
+ expect(mongoized).to be_nil
744
+ end
376
745
  end
377
746
 
378
- it "returns a String" do
379
- expect(BigDecimal.mongoize(infinity)).to eq("Infinity")
747
+ context "when the value is an Integer" do
748
+
749
+ let(:value) do
750
+ 123456
751
+ end
752
+
753
+ it "returns a BSON::Decimal128" do
754
+ expect(mongoized).to eq(BSON::Decimal128.new(value.to_s))
755
+ end
380
756
  end
381
- end
382
757
 
383
- context "when the value is constant Float::INFINITY * -1" do
758
+ context "when the value is a Float" do
759
+
760
+ let(:value) do
761
+ 123456.789
762
+ end
763
+
764
+ it "returns a BSON::Decimal128" do
765
+ expect(mongoized).to eq(BSON::Decimal128.new(value.to_s))
766
+ end
767
+ end
768
+
769
+ context "when the value is String NaN" do
770
+
771
+ let(:value) do
772
+ "NaN"
773
+ end
384
774
 
385
- let(:neg_infinity) do
386
- Float::INFINITY * -1
775
+ it "returns a BSON::Decimal128 representation of NaN" do
776
+ expect(mongoized).to eq(BSON::Decimal128.new(value))
777
+ end
387
778
  end
388
779
 
389
- it "returns a String" do
390
- expect(BigDecimal.mongoize(neg_infinity)).to eq("-Infinity")
780
+ context "when the value is String Infinity" do
781
+
782
+ let(:value) do
783
+ "Infinity"
784
+ end
785
+
786
+ it "returns a BSON::Decimal128 representation of Infinity" do
787
+ expect(mongoized).to eq(BSON::Decimal128.new(value))
788
+ end
789
+ end
790
+
791
+ context "when the value is String negative Infinity" do
792
+
793
+ let(:value) do
794
+ "-Infinity"
795
+ end
796
+
797
+ it "returns a BSON::Decimal128 representation of -Infinity" do
798
+ expect(mongoized).to eq(BSON::Decimal128.new(value))
799
+ end
800
+ end
801
+
802
+ context "when the value is BigDecimal NaN" do
803
+
804
+ let(:value) do
805
+ BigDecimal("NaN")
806
+ end
807
+
808
+ it "returns a BSON::Decimal128 representation of BigDecimal NaN" do
809
+ expect(mongoized).to eq(BSON::Decimal128.new("NaN"))
810
+ end
811
+ end
812
+
813
+ context "when the value is BigDecimal Infinity" do
814
+
815
+ let(:value) do
816
+ BigDecimal("Infinity")
817
+ end
818
+
819
+ it "returns a BSON::Decimal128 representation of BigDecimal Infinity" do
820
+ expect(mongoized).to eq(BSON::Decimal128.new("Infinity"))
821
+ end
822
+ end
823
+
824
+ context "when the value is BigDecimal negative Infinity" do
825
+
826
+ let(:value) do
827
+ BigDecimal("-Infinity")
828
+ end
829
+
830
+ it "returns a BSON::Decimal128 representation of BigDecimal negative Infinity" do
831
+ expect(mongoized).to eq(BSON::Decimal128.new("-Infinity"))
832
+ end
833
+ end
834
+
835
+ context "when the value is the constant Float::NAN" do
836
+
837
+ let(:value) do
838
+ Float::NAN
839
+ end
840
+
841
+ it "returns a BSON::Decimal128 representation of NaN" do
842
+ expect(mongoized).to eq(BSON::Decimal128.new("NaN"))
843
+ end
844
+ end
845
+
846
+ context "when the value is constant Float::INFINITY" do
847
+
848
+ let(:value) do
849
+ Float::INFINITY
850
+ end
851
+
852
+ it "returns a BSON::Decimal128 representation of Infinity" do
853
+ expect(mongoized).to eq(BSON::Decimal128.new("Infinity"))
854
+ end
855
+ end
856
+
857
+ context "when the value is constant Float::INFINITY * -1" do
858
+
859
+ let(:value) do
860
+ Float::INFINITY * -1
861
+ end
862
+
863
+ it "returns a BSON::Decimal128 representation of negative Infinity" do
864
+ expect(mongoized).to eq(BSON::Decimal128.new("-Infinity"))
865
+ end
866
+ end
867
+
868
+ context "when the value is a decimal128" do
869
+ let(:value) do
870
+ BSON::Decimal128.new("42")
871
+ end
872
+
873
+ it "returns a String" do
874
+ expect(mongoized).to eq(value)
875
+ end
391
876
  end
392
877
  end
393
- end
394
878
 
395
- describe "#mongoize" do
879
+ describe "#mongoize" do
396
880
 
397
- it "returns a string" do
398
- expect(big_decimal.mongoize).to eq(big_decimal.to_s)
881
+ it "returns a BSON::Decimal128 representation of the BigDecimal" do
882
+ expect(big_decimal.mongoize).to eq(BSON::Decimal128.new(big_decimal))
883
+ end
399
884
  end
400
- end
401
885
 
402
- describe "#numeric?" do
886
+ describe "#numeric?" do
403
887
 
404
- it "returns true" do
405
- expect(big_decimal.numeric?).to eq(true)
888
+ it "returns true" do
889
+ expect(big_decimal.numeric?).to eq(true)
890
+ end
406
891
  end
407
892
  end
408
893
  end