mongoid 7.2.1 → 7.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) 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 +13 -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 +32 -14
  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 +26 -43
  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/elem_match.rb +2 -1
  52. data/lib/mongoid/matcher/expression.rb +9 -14
  53. data/lib/mongoid/matcher/field_expression.rb +4 -5
  54. data/lib/mongoid/matcher/field_operator.rb +6 -0
  55. data/lib/mongoid/matcher/mod.rb +17 -0
  56. data/lib/mongoid/matcher/type.rb +99 -0
  57. data/lib/mongoid/persistable/deletable.rb +1 -2
  58. data/lib/mongoid/persistable/destroyable.rb +8 -2
  59. data/lib/mongoid/persistable/updatable.rb +27 -2
  60. data/lib/mongoid/query_cache.rb +35 -29
  61. data/lib/mongoid/reloadable.rb +5 -0
  62. data/lib/mongoid/selectable.rb +5 -7
  63. data/lib/mongoid/shardable.rb +21 -5
  64. data/lib/mongoid/touchable.rb +23 -4
  65. data/lib/mongoid/validatable/associated.rb +1 -1
  66. data/lib/mongoid/validatable/presence.rb +3 -3
  67. data/lib/mongoid/validatable/uniqueness.rb +1 -1
  68. data/lib/mongoid/version.rb +1 -1
  69. data/lib/rails/generators/mongoid/config/config_generator.rb +8 -1
  70. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +1 -1
  71. data/spec/integration/app_spec.rb +139 -82
  72. data/spec/integration/associations/embeds_many_spec.rb +44 -0
  73. data/spec/integration/associations/has_one_spec.rb +48 -0
  74. data/spec/integration/criteria/date_field_spec.rb +1 -1
  75. data/spec/integration/document_spec.rb +30 -0
  76. data/spec/integration/matcher_operator_data/bits_all_clear.yml +159 -0
  77. data/spec/integration/matcher_operator_data/bits_all_set.yml +159 -0
  78. data/spec/integration/matcher_operator_data/bits_any_clear.yml +159 -0
  79. data/spec/integration/matcher_operator_data/bits_any_set.yml +159 -0
  80. data/spec/integration/matcher_operator_data/comment.yml +22 -0
  81. data/spec/integration/matcher_operator_data/elem_match.yml +46 -0
  82. data/spec/integration/matcher_operator_data/implicit_traversal.yml +96 -0
  83. data/spec/integration/matcher_operator_data/in.yml +16 -0
  84. data/spec/integration/matcher_operator_data/mod.yml +55 -0
  85. data/spec/integration/matcher_operator_data/type.yml +70 -0
  86. data/spec/integration/matcher_operator_data/type_array.yml +16 -0
  87. data/spec/integration/matcher_operator_data/type_binary.yml +18 -0
  88. data/spec/integration/matcher_operator_data/type_boolean.yml +39 -0
  89. data/spec/integration/matcher_operator_data/type_code.yml +26 -0
  90. data/spec/integration/matcher_operator_data/type_code_with_scope.yml +26 -0
  91. data/spec/integration/matcher_operator_data/type_date.yml +39 -0
  92. data/spec/integration/matcher_operator_data/type_db_pointer.yml +19 -0
  93. data/spec/integration/matcher_operator_data/type_decimal.yml +40 -0
  94. data/spec/integration/matcher_operator_data/type_double.yml +15 -0
  95. data/spec/integration/matcher_operator_data/type_int32.yml +33 -0
  96. data/spec/integration/matcher_operator_data/type_int64.yml +33 -0
  97. data/spec/integration/matcher_operator_data/type_max_key.yml +17 -0
  98. data/spec/integration/matcher_operator_data/type_min_key.yml +17 -0
  99. data/spec/integration/matcher_operator_data/type_null.yml +23 -0
  100. data/spec/integration/matcher_operator_data/type_object.yml +23 -0
  101. data/spec/integration/matcher_operator_data/type_object_id.yml +25 -0
  102. data/spec/integration/matcher_operator_data/type_regex.yml +44 -0
  103. data/spec/integration/matcher_operator_data/type_string.yml +15 -0
  104. data/spec/integration/matcher_operator_data/type_symbol.yml +32 -0
  105. data/spec/integration/matcher_operator_data/type_timestamp.yml +25 -0
  106. data/spec/integration/matcher_operator_data/type_undefined.yml +17 -0
  107. data/spec/lite_spec_helper.rb +4 -3
  108. data/spec/mongoid/association/depending_spec.rb +391 -352
  109. data/spec/mongoid/association/nested/one_spec.rb +18 -14
  110. data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +25 -8
  111. data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +1 -1
  112. data/spec/mongoid/association/referenced/has_many/binding_spec.rb +1 -1
  113. data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +1 -1
  114. data/spec/mongoid/association/referenced/has_one_models.rb +8 -0
  115. data/spec/mongoid/atomic/paths_spec.rb +64 -12
  116. data/spec/mongoid/attributes/projector_data/embedded.yml +105 -0
  117. data/spec/mongoid/attributes/projector_data/fields.yml +93 -0
  118. data/spec/mongoid/attributes/projector_spec.rb +41 -0
  119. data/spec/mongoid/attributes_spec.rb +333 -0
  120. data/spec/mongoid/clients/factory_spec.rb +48 -0
  121. data/spec/mongoid/config_spec.rb +32 -0
  122. data/spec/mongoid/contextual/atomic_spec.rb +17 -4
  123. data/spec/mongoid/contextual/mongo_spec.rb +2 -2
  124. data/spec/mongoid/criteria/modifiable_spec.rb +1 -1
  125. data/spec/mongoid/criteria/queryable/expandable_spec.rb +0 -73
  126. data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +1 -1
  127. data/spec/mongoid/criteria/queryable/mergeable_spec.rb +105 -7
  128. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +229 -24
  129. data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +39 -0
  130. data/spec/mongoid/criteria/queryable/selectable_spec.rb +1 -565
  131. data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +590 -0
  132. data/spec/mongoid/criteria_projection_spec.rb +411 -0
  133. data/spec/mongoid/criteria_spec.rb +0 -275
  134. data/spec/mongoid/document_fields_spec.rb +26 -0
  135. data/spec/mongoid/document_query_spec.rb +51 -0
  136. data/spec/mongoid/document_spec.rb +13 -13
  137. data/spec/mongoid/errors/delete_restriction_spec.rb +1 -1
  138. data/spec/mongoid/errors/mongoid_error_spec.rb +20 -8
  139. data/spec/mongoid/extensions/false_class_spec.rb +1 -1
  140. data/spec/mongoid/extensions/string_spec.rb +5 -5
  141. data/spec/mongoid/extensions/true_class_spec.rb +1 -1
  142. data/spec/mongoid/fields/localized_spec.rb +4 -4
  143. data/spec/mongoid/fields_spec.rb +4 -4
  144. data/spec/mongoid/inspectable_spec.rb +12 -4
  145. data/spec/mongoid/matcher/extract_attribute_data/numeric_keys.yml +104 -0
  146. data/spec/mongoid/matcher/extract_attribute_data/traversal.yml +68 -88
  147. data/spec/mongoid/matcher/extract_attribute_spec.rb +3 -13
  148. data/spec/mongoid/persistable/deletable_spec.rb +175 -1
  149. data/spec/mongoid/persistable/destroyable_spec.rb +191 -3
  150. data/spec/mongoid/persistable/savable_spec.rb +3 -5
  151. data/spec/mongoid/persistable/settable_spec.rb +30 -0
  152. data/spec/mongoid/persistable/upsertable_spec.rb +1 -1
  153. data/spec/mongoid/persistable_spec.rb +2 -2
  154. data/spec/mongoid/query_cache_middleware_spec.rb +8 -0
  155. data/spec/mongoid/reloadable_spec.rb +18 -1
  156. data/spec/mongoid/shardable_spec.rb +44 -0
  157. data/spec/mongoid/touchable_spec.rb +104 -16
  158. data/spec/mongoid/touchable_spec_models.rb +52 -0
  159. data/spec/mongoid/validatable_spec.rb +1 -1
  160. data/spec/shared/bin/get-mongodb-download-url +17 -0
  161. data/spec/shared/bin/s3-copy +45 -0
  162. data/spec/shared/bin/s3-upload +69 -0
  163. data/spec/shared/lib/mrss/cluster_config.rb +19 -4
  164. data/spec/shared/lib/mrss/constraints.rb +46 -8
  165. data/spec/shared/lib/mrss/docker_runner.rb +10 -1
  166. data/spec/shared/lib/mrss/lite_constraints.rb +16 -0
  167. data/spec/shared/lib/mrss/server_version_registry.rb +79 -33
  168. data/spec/shared/lib/mrss/spec_organizer.rb +32 -2
  169. data/spec/shared/lib/mrss/utils.rb +15 -0
  170. data/spec/shared/share/Dockerfile.erb +122 -29
  171. data/spec/shared/share/haproxy-1.conf +16 -0
  172. data/spec/shared/share/haproxy-2.conf +17 -0
  173. data/spec/shared/shlib/server.sh +58 -11
  174. data/spec/shared/shlib/set_env.sh +4 -1
  175. data/spec/spec_helper.rb +7 -3
  176. data/spec/support/client_registry.rb +9 -0
  177. data/spec/support/models/bolt.rb +8 -0
  178. data/spec/support/models/hole.rb +13 -0
  179. data/spec/support/models/mop.rb +9 -0
  180. data/spec/support/models/nut.rb +8 -0
  181. data/spec/support/models/person.rb +6 -0
  182. data/spec/support/models/sealer.rb +8 -0
  183. data/spec/support/models/shirt.rb +12 -0
  184. data/spec/support/models/spacer.rb +8 -0
  185. data/spec/support/models/threadlocker.rb +8 -0
  186. data/spec/support/models/washer.rb +8 -0
  187. data/spec/support/spec_config.rb +8 -0
  188. metadata +636 -528
  189. metadata.gz.sig +0 -0
  190. data/spec/support/cluster_config.rb +0 -158
@@ -85,4 +85,30 @@ describe Mongoid::Document do
85
85
  end
86
86
  end
87
87
  end
88
+
89
+ context 'Regexp field' do
90
+ shared_examples "persists strings as regexp" do |type|
91
+ it 'persists strings as regexp' do
92
+ mop = Mop.create!(regexp_field: 'foo')
93
+ expect(mop.regexp_field).to be_a Regexp
94
+ expect(Mop.find(mop.id).regexp_field).to be_a BSON::Regexp::Raw
95
+ expect(
96
+ Mop.collection.find(
97
+ "_id" => mop.id,
98
+ "regexp_field" => { "$type" => type }
99
+ ).count
100
+ ).to be == 1
101
+ end
102
+ end
103
+
104
+ context "< 3.2" do
105
+ max_server_version("3.1")
106
+ include_examples "persists strings as regexp", 11
107
+ end
108
+
109
+ context ">= 3.2" do
110
+ min_server_version("3.2")
111
+ it_behaves_like "persists strings as regexp", "regex"
112
+ end
113
+ end
88
114
  end
@@ -36,4 +36,55 @@ describe Mongoid::Document do
36
36
  expect(_person.age).to be 42
37
37
  end
38
38
  end
39
+
40
+ context 'when projecting with #without' do
41
+ before do
42
+ duck = Pet.new(name: 'Duck')
43
+ Person.create!(username: 'Dev', title: 'CEO', pet: duck)
44
+ end
45
+
46
+ let(:person) { Person.where(username: 'Dev').without(:title).first }
47
+
48
+ it 'allows access to attribute of embedded document' do
49
+ expect(person.pet.name).to eq 'Duck'
50
+ end
51
+
52
+ context 'when exclusion starts with association name but is not the association' do
53
+
54
+ let(:person) { Person.where(username: 'Dev').without(:pet_).first }
55
+
56
+ it 'allows access to attribute of embedded document' do
57
+ expect(person.pet.name).to eq 'Duck'
58
+ end
59
+ end
60
+
61
+ context 'when exclusion starts with prefix of association name' do
62
+
63
+ let(:person) { Person.where(username: 'Dev').without(:pe).first }
64
+
65
+ it 'allows access to attribute of embedded document' do
66
+ expect(person.pet.name).to eq 'Duck'
67
+ end
68
+ end
69
+
70
+ context 'when another attribute of the association is excluded' do
71
+
72
+ let(:person) { Person.where(username: 'Dev').without('pet.weight').first }
73
+
74
+ it 'allows access to non-excluded attribute of embedded document' do
75
+ expect(person.pet.name).to eq 'Duck'
76
+ end
77
+ end
78
+
79
+ context 'when the excluded attribute of the association is retrieved' do
80
+
81
+ let(:person) { Person.where(username: 'Dev').without('pet.name').first }
82
+
83
+ it 'prohibits the retrieval' do
84
+ lambda do
85
+ person.pet.name
86
+ end.should raise_error(ActiveModel::MissingAttributeError)
87
+ end
88
+ end
89
+ end
39
90
  end
@@ -124,13 +124,13 @@ describe Mongoid::Document do
124
124
  describe "._mongoid_clear_types" do
125
125
 
126
126
  context "when changing the discriminator_value" do
127
-
128
- before do
127
+
128
+ before do
129
129
  Kangaroo._types
130
130
  Kangaroo.discriminator_value = "dvalue"
131
131
  end
132
132
 
133
- after do
133
+ after do
134
134
  Kangaroo.discriminator_value = nil
135
135
  end
136
136
 
@@ -140,13 +140,13 @@ describe Mongoid::Document do
140
140
  end
141
141
 
142
142
  context "when changing the discriminator_value in child" do
143
-
144
- before do
143
+
144
+ before do
145
145
  Shape._types
146
146
  Circle.discriminator_value = "dvalue"
147
147
  end
148
148
 
149
- after do
149
+ after do
150
150
  Circle.discriminator_value = nil
151
151
  end
152
152
 
@@ -924,7 +924,7 @@ describe Mongoid::Document do
924
924
  end
925
925
 
926
926
  context "when no embedded documents are present" do
927
- context "when using the default discriminator key" do
927
+ context "when using the default discriminator key" do
928
928
  let(:person) do
929
929
  manager.becomes(Person)
930
930
  end
@@ -948,12 +948,12 @@ describe Mongoid::Document do
948
948
  end
949
949
  end
950
950
 
951
- context "when using a custom discriminator key" do
952
- before do
951
+ context "when using a custom discriminator key" do
952
+ before do
953
953
  Person.discriminator_key = "dkey"
954
954
  end
955
955
 
956
- after do
956
+ after do
957
957
  Person.discriminator_key = nil
958
958
  end
959
959
 
@@ -962,13 +962,13 @@ describe Mongoid::Document do
962
962
  end
963
963
  end
964
964
 
965
- context "when using a custom discriminator key and discriminator value" do
966
- before do
965
+ context "when using a custom discriminator key and discriminator value" do
966
+ before do
967
967
  Person.discriminator_key = "dkey"
968
968
  Person.discriminator_value = "dvalue"
969
969
  end
970
970
 
971
- after do
971
+ after do
972
972
  Person.discriminator_key = nil
973
973
  Person.discriminator_value = nil
974
974
  end
@@ -13,7 +13,7 @@ describe Mongoid::Errors::DeleteRestriction do
13
13
 
14
14
  it "contains the problem in the message" do
15
15
  expect(error.message).to include(
16
- "Cannot delete Person because of dependent 'drugs'."
16
+ "Cannot destroy Person because of dependent 'drugs'."
17
17
  )
18
18
  end
19
19
 
@@ -10,14 +10,26 @@ describe Mongoid::Errors::MongoidError do
10
10
  let(:options) { {} }
11
11
 
12
12
  before do
13
- {"message_title" => "message", "summary_title" => "summary", "resolution_title" => "resolution"}.each do |key, name|
14
- expect(::I18n).to receive(:translate).with("mongoid.errors.messages.#{key}", {}).and_return(name)
15
- end
16
-
17
- ["message", "summary", "resolution"].each do |name|
18
- expect(::I18n).to receive(:translate).
19
- with("mongoid.errors.messages.#{key}.#{name}", {}).
20
- and_return(name)
13
+ if RUBY_VERSION.start_with?('3.', '2.7')
14
+ {"message_title" => "message", "summary_title" => "summary", "resolution_title" => "resolution"}.each do |key, name|
15
+ expect(::I18n).to receive(:translate).with("mongoid.errors.messages.#{key}", **{}).and_return(name)
16
+ end
17
+
18
+ ["message", "summary", "resolution"].each do |name|
19
+ expect(::I18n).to receive(:translate).
20
+ with("mongoid.errors.messages.#{key}.#{name}", **{}).
21
+ and_return(name)
22
+ end
23
+ else
24
+ {"message_title" => "message", "summary_title" => "summary", "resolution_title" => "resolution"}.each do |key, name|
25
+ expect(::I18n).to receive(:translate).with("mongoid.errors.messages.#{key}", {}).and_return(name)
26
+ end
27
+
28
+ ["message", "summary", "resolution"].each do |name|
29
+ expect(::I18n).to receive(:translate).
30
+ with("mongoid.errors.messages.#{key}.#{name}", {}).
31
+ and_return(name)
32
+ end
21
33
  end
22
34
 
23
35
  error.compose_message(key, options)
@@ -17,7 +17,7 @@ describe Mongoid::Extensions::FalseClass do
17
17
  context "when provided a Boolean" do
18
18
 
19
19
  it "returns true" do
20
- expect(false.is_a?(Boolean)).to be true
20
+ expect(false.is_a?(Mongoid::Boolean)).to be true
21
21
  end
22
22
  end
23
23
 
@@ -158,16 +158,16 @@ describe Mongoid::Extensions::String do
158
158
  Time.now.utc_offset
159
159
  end
160
160
 
161
- before do
162
- expect(utc_offset).not_to eq(Time.zone.now.utc_offset)
163
- end
164
-
165
- let(:expected_time) { Time.parse("2010-11-19 00:24:49.123457 +0000").in_time_zone - utc_offset }
161
+ let(:expected_time) { Time.parse("2010-11-19 00:24:49.123457 +0000") - Time.parse(string).utc_offset }
166
162
 
167
163
  let(:mongoized) do
168
164
  string.__mongoize_time__
169
165
  end
170
166
 
167
+ it 'test operates in multiple time zones' do
168
+ expect(utc_offset).not_to eq(Time.zone.now.utc_offset)
169
+ end
170
+
171
171
  it_behaves_like 'mongoizes to Time'
172
172
  it_behaves_like 'maintains precision when mongoized'
173
173
  end
@@ -17,7 +17,7 @@ describe Mongoid::Extensions::TrueClass do
17
17
  context "when provided a Boolean" do
18
18
 
19
19
  it "returns true" do
20
- expect(true.is_a?(Boolean)).to be true
20
+ expect(true.is_a?(Mongoid::Boolean)).to be true
21
21
  end
22
22
  end
23
23
 
@@ -448,7 +448,7 @@ describe Mongoid::Fields::Localized do
448
448
  context "when the value is false" do
449
449
 
450
450
  let(:field) do
451
- described_class.new(:boolean_value, localize: true, type: Boolean)
451
+ described_class.new(:boolean_value, localize: true, type: Mongoid::Boolean)
452
452
  end
453
453
 
454
454
  let(:value) do
@@ -463,7 +463,7 @@ describe Mongoid::Fields::Localized do
463
463
  context "when the value is true" do
464
464
 
465
465
  let(:field) do
466
- described_class.new(:boolean_value, localize: true, type: Boolean)
466
+ described_class.new(:boolean_value, localize: true, type: Mongoid::Boolean)
467
467
  end
468
468
 
469
469
  let(:value) do
@@ -491,7 +491,7 @@ describe Mongoid::Fields::Localized do
491
491
  end
492
492
 
493
493
  let(:field) do
494
- described_class.new(:boolean_value, localize: true, type: Boolean)
494
+ described_class.new(:boolean_value, localize: true, type: Mongoid::Boolean)
495
495
  end
496
496
 
497
497
  let(:value) do
@@ -510,7 +510,7 @@ describe Mongoid::Fields::Localized do
510
510
  end
511
511
 
512
512
  let(:field) do
513
- described_class.new(:boolean_value, localize: true, type: Boolean)
513
+ described_class.new(:boolean_value, localize: true, type: Mongoid::Boolean)
514
514
  end
515
515
 
516
516
  let(:value) do
@@ -322,7 +322,7 @@ describe Mongoid::Fields do
322
322
  end
323
323
 
324
324
  it "converts to Mongoid::Boolean" do
325
- expect(klass.field(:test, type: Boolean).type).to be(Mongoid::Boolean)
325
+ expect(klass.field(:test, type: Mongoid::Boolean).type).to be(Mongoid::Boolean)
326
326
  end
327
327
  end
328
328
 
@@ -404,7 +404,7 @@ describe Mongoid::Fields do
404
404
  context "when the options are all standard" do
405
405
 
406
406
  before do
407
- Band.field :acceptable, type: Boolean
407
+ Band.field :acceptable, type: Mongoid::Boolean
408
408
  end
409
409
 
410
410
  after do
@@ -419,7 +419,7 @@ describe Mongoid::Fields do
419
419
  context "when a custom option is provided" do
420
420
 
421
421
  before do
422
- Band.field :acceptable, type: Boolean, custom: true
422
+ Band.field :acceptable, type: Mongoid::Boolean, custom: true
423
423
  end
424
424
 
425
425
  it "adds the field to the model" do
@@ -990,7 +990,7 @@ describe Mongoid::Fields do
990
990
  end
991
991
 
992
992
  before do
993
- Person.field :aliased, as: :alias, type: Boolean, overwrite: true
993
+ Person.field :aliased, as: :alias, type: Mongoid::Boolean, overwrite: true
994
994
  end
995
995
 
996
996
  it "uses the alias to write the attribute" do
@@ -33,18 +33,18 @@ describe Mongoid::Inspectable do
33
33
  expect(inspected).to include("t(test):")
34
34
  end
35
35
 
36
- it "displays the default discriminator key" do
36
+ it "displays the default discriminator key" do
37
37
  expect(inspected).to include(%q,_type: "Person",)
38
38
  end
39
39
  end
40
40
 
41
41
  context "when using a custom discriminator key" do
42
42
 
43
- before do
43
+ before do
44
44
  Person.discriminator_key = "dkey"
45
45
  end
46
46
 
47
- after do
47
+ after do
48
48
  Person.discriminator_key = nil
49
49
  end
50
50
 
@@ -56,7 +56,7 @@ describe Mongoid::Inspectable do
56
56
  person.inspect
57
57
  end
58
58
 
59
- it "displays the new discriminator key" do
59
+ it "displays the new discriminator key" do
60
60
  expect(inspected).to include(%q,dkey: "Person",)
61
61
  end
62
62
  end
@@ -75,5 +75,13 @@ describe Mongoid::Inspectable do
75
75
  expect(inspected).to include(%q,some_attribute: "foo",)
76
76
  end
77
77
  end
78
+
79
+ context 'when id is unaliased' do
80
+ let(:shirt) { Shirt.new(id: 1, _id: 2) }
81
+
82
+ it 'shows the correct _id and id values' do
83
+ shirt.inspect.should == "#<Shirt _id: 2, color: nil, id: \"1\">"
84
+ end
85
+ end
78
86
  end
79
87
  end
@@ -0,0 +1,104 @@
1
+ - name: string key - matches
2
+ document:
3
+ # Document field names in MongoDB are always strings.
4
+ '42': foo
5
+ # The paths are also always strings.
6
+ key: '42'
7
+
8
+ result:
9
+ - foo
10
+
11
+ - name: string key - does not match
12
+ document:
13
+ # Document field names in MongoDB are always strings.
14
+ '42': foo
15
+ # The paths are also always strings.
16
+ key: '4'
17
+
18
+ result: []
19
+
20
+ - name: array value - matches
21
+ document:
22
+ '42':
23
+ - foo
24
+ key: '42'
25
+
26
+ result:
27
+ - ['foo']
28
+
29
+ - name: subfield of numeric key - matches
30
+ document:
31
+ '42':
32
+ foo: bar
33
+ key: 42.foo
34
+
35
+ result:
36
+ - bar
37
+
38
+ - name: numeric key under array
39
+ document:
40
+ a:
41
+ -
42
+ '42': bar
43
+
44
+ key: a.42
45
+
46
+ result:
47
+ - bar
48
+
49
+ - name: multiple values under numeric key under array
50
+ document: &numeric-key-under-array
51
+ a:
52
+ -
53
+ '42': bar
54
+ -
55
+ '42': foo
56
+
57
+ key: a.42
58
+
59
+ result:
60
+ - bar
61
+ - foo
62
+
63
+ - name: array indexing with values under numeric key under array
64
+ document: *numeric-key-under-array
65
+
66
+ key: a.1
67
+
68
+ result:
69
+ -
70
+ '42': foo
71
+
72
+ - name: multiple values under array under numeric key
73
+ document:
74
+ a:
75
+ '42':
76
+ -
77
+ foo: bar
78
+ -
79
+ foo: baq
80
+
81
+ key: a.42.foo
82
+
83
+ result:
84
+ - bar
85
+ - baq
86
+
87
+ - name: path component interpretable as both array index and hash key
88
+ document:
89
+ a:
90
+ -
91
+ '1': bar
92
+ -
93
+ '1': foo
94
+
95
+ key: a.1
96
+
97
+ result:
98
+ # The order of these results isn't guaranteed:
99
+ # 1 interpreted as the array index:
100
+ -
101
+ '1': foo
102
+ # 1 interpreted as hash key:
103
+ - bar
104
+ - foo