mongoid 4.0.2 → 5.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +66 -1
  3. data/README.md +14 -13
  4. data/lib/config/locales/en.yml +28 -28
  5. data/lib/mongoid.rb +28 -21
  6. data/lib/mongoid/atomic.rb +2 -4
  7. data/lib/mongoid/attributes.rb +7 -7
  8. data/lib/mongoid/attributes/processing.rb +4 -1
  9. data/lib/mongoid/attributes/readonly.rb +2 -2
  10. data/lib/mongoid/changeable.rb +4 -6
  11. data/lib/mongoid/clients.rb +142 -0
  12. data/lib/mongoid/clients/factory.rb +78 -0
  13. data/lib/mongoid/{sessions → clients}/options.rb +30 -19
  14. data/lib/mongoid/{sessions → clients}/storage_options.rb +27 -13
  15. data/lib/mongoid/{sessions → clients}/thread_options.rb +6 -3
  16. data/lib/mongoid/clients/validators.rb +2 -0
  17. data/lib/mongoid/{sessions → clients}/validators/storage.rb +5 -2
  18. data/lib/mongoid/composable.rb +3 -3
  19. data/lib/mongoid/config.rb +39 -41
  20. data/lib/mongoid/config/environment.rb +1 -1
  21. data/lib/mongoid/config/validators.rb +1 -1
  22. data/lib/mongoid/config/validators/{session.rb → client.rb} +31 -28
  23. data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
  24. data/lib/mongoid/contextual/atomic.rb +11 -11
  25. data/lib/mongoid/contextual/command.rb +9 -6
  26. data/lib/mongoid/contextual/geo_near.rb +17 -1
  27. data/lib/mongoid/contextual/map_reduce.rb +12 -11
  28. data/lib/mongoid/contextual/memory.rb +2 -5
  29. data/lib/mongoid/contextual/mongo.rb +92 -82
  30. data/lib/mongoid/contextual/none.rb +13 -0
  31. data/lib/mongoid/copyable.rb +6 -1
  32. data/lib/mongoid/criteria.rb +36 -3
  33. data/lib/mongoid/document.rb +3 -4
  34. data/lib/mongoid/errors.rb +6 -6
  35. data/lib/mongoid/errors/{mixed_session_configuration.rb → mixed_client_configuration.rb} +5 -5
  36. data/lib/mongoid/errors/no_client_config.rb +22 -0
  37. data/lib/mongoid/errors/{no_session_database.rb → no_client_database.rb} +4 -4
  38. data/lib/mongoid/errors/{no_session_hosts.rb → no_client_hosts.rb} +4 -4
  39. data/lib/mongoid/errors/{no_sessions_config.rb → no_clients_config.rb} +4 -4
  40. data/lib/mongoid/errors/no_default_client.rb +23 -0
  41. data/lib/mongoid/extensions/hash.rb +5 -1
  42. data/lib/mongoid/extensions/object.rb +3 -2
  43. data/lib/mongoid/extensions/set.rb +5 -5
  44. data/lib/mongoid/factory.rb +4 -2
  45. data/lib/mongoid/fields.rb +7 -2
  46. data/lib/mongoid/findable.rb +4 -1
  47. data/lib/mongoid/indexable.rb +15 -9
  48. data/lib/mongoid/persistable.rb +1 -2
  49. data/lib/mongoid/persistable/creatable.rb +2 -2
  50. data/lib/mongoid/persistable/deletable.rb +3 -3
  51. data/lib/mongoid/persistable/incrementable.rb +1 -1
  52. data/lib/mongoid/persistable/logical.rb +1 -1
  53. data/lib/mongoid/persistable/poppable.rb +1 -1
  54. data/lib/mongoid/persistable/pullable.rb +2 -2
  55. data/lib/mongoid/persistable/pushable.rb +2 -2
  56. data/lib/mongoid/persistable/renamable.rb +1 -1
  57. data/lib/mongoid/persistable/settable.rb +1 -1
  58. data/lib/mongoid/persistable/unsettable.rb +1 -1
  59. data/lib/mongoid/persistable/updatable.rb +2 -2
  60. data/lib/mongoid/persistable/upsertable.rb +1 -1
  61. data/lib/mongoid/query_cache.rb +98 -104
  62. data/lib/mongoid/railtie.rb +1 -21
  63. data/lib/mongoid/railties/database.rake +1 -1
  64. data/lib/mongoid/relations/builders.rb +3 -1
  65. data/lib/mongoid/relations/counter_cache.rb +1 -1
  66. data/lib/mongoid/relations/embedded/batchable.rb +3 -10
  67. data/lib/mongoid/relations/embedded/many.rb +4 -2
  68. data/lib/mongoid/relations/many.rb +1 -0
  69. data/lib/mongoid/relations/proxy.rb +6 -6
  70. data/lib/mongoid/relations/referenced/many.rb +2 -1
  71. data/lib/mongoid/relations/targets/enumerable.rb +11 -11
  72. data/lib/mongoid/relations/touchable.rb +1 -1
  73. data/lib/mongoid/reloadable.rb +2 -2
  74. data/lib/mongoid/scopable.rb +6 -17
  75. data/lib/mongoid/selectable.rb +1 -36
  76. data/lib/mongoid/serializable.rb +2 -2
  77. data/lib/mongoid/stateful.rb +0 -1
  78. data/lib/mongoid/tasks/database.rake +2 -2
  79. data/lib/mongoid/tasks/database.rb +23 -16
  80. data/lib/mongoid/threaded.rb +54 -33
  81. data/lib/mongoid/threaded/lifecycle.rb +21 -16
  82. data/lib/mongoid/traversable.rb +16 -1
  83. data/lib/mongoid/validatable.rb +1 -1
  84. data/lib/mongoid/validatable/queryable.rb +1 -1
  85. data/lib/mongoid/validatable/uniqueness.rb +3 -20
  86. data/lib/mongoid/version.rb +1 -1
  87. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +91 -57
  88. data/lib/rails/mongoid.rb +2 -2
  89. data/spec/app/models/audio.rb +1 -1
  90. data/spec/app/models/band.rb +1 -0
  91. data/spec/app/models/company.rb +5 -0
  92. data/spec/app/models/label.rb +7 -0
  93. data/spec/app/models/pub.rb +6 -0
  94. data/spec/app/models/staff.rb +7 -0
  95. data/spec/app/models/store_as_dup_test1.rb +5 -0
  96. data/spec/app/models/store_as_dup_test2.rb +5 -0
  97. data/spec/config/mongoid.yml +7 -25
  98. data/spec/mongoid/atomic/paths_spec.rb +3 -11
  99. data/spec/mongoid/attributes/nested_spec.rb +16 -16
  100. data/spec/mongoid/attributes/readonly_spec.rb +80 -18
  101. data/spec/mongoid/attributes_spec.rb +3 -3
  102. data/spec/mongoid/changeable_spec.rb +70 -0
  103. data/spec/mongoid/clients/factory_spec.rb +284 -0
  104. data/spec/mongoid/{sessions → clients}/options_spec.rb +4 -6
  105. data/spec/mongoid/clients_spec.rb +739 -0
  106. data/spec/mongoid/config/environment_spec.rb +14 -11
  107. data/spec/mongoid/config_spec.rb +33 -48
  108. data/spec/mongoid/contextual/atomic_spec.rb +1 -17
  109. data/spec/mongoid/contextual/geo_near_spec.rb +35 -0
  110. data/spec/mongoid/contextual/mongo_spec.rb +26 -83
  111. data/spec/mongoid/contextual/none_spec.rb +15 -0
  112. data/spec/mongoid/copyable_spec.rb +35 -1
  113. data/spec/mongoid/criteria/findable_spec.rb +197 -0
  114. data/spec/mongoid/criteria/modifiable_spec.rb +7 -29
  115. data/spec/mongoid/criteria_spec.rb +74 -91
  116. data/spec/mongoid/document_spec.rb +1 -1
  117. data/spec/mongoid/errors/{mixed_session_configuration_spec.rb → mixed_client_configuration_spec.rb} +1 -1
  118. data/spec/mongoid/errors/{no_session_config_spec.rb → no_client_config_spec.rb} +4 -4
  119. data/spec/mongoid/errors/{no_session_database_spec.rb → no_client_database_spec.rb} +4 -4
  120. data/spec/mongoid/errors/{no_session_hosts_spec.rb → no_client_hosts_spec.rb} +3 -3
  121. data/spec/mongoid/errors/{no_sessions_config_spec.rb → no_clients_config_spec.rb} +2 -2
  122. data/spec/mongoid/fields/localized_spec.rb +1 -0
  123. data/spec/mongoid/fields_spec.rb +1 -0
  124. data/spec/mongoid/findable_spec.rb +2 -23
  125. data/spec/mongoid/indexable_spec.rb +12 -8
  126. data/spec/mongoid/interceptable_spec.rb +15 -0
  127. data/spec/mongoid/persistable/settable_spec.rb +16 -0
  128. data/spec/mongoid/persistable/updatable_spec.rb +3 -2
  129. data/spec/mongoid/persistable_spec.rb +4 -4
  130. data/spec/mongoid/query_cache_spec.rb +13 -8
  131. data/spec/mongoid/relations/auto_save_spec.rb +1 -1
  132. data/spec/mongoid/relations/counter_cache_spec.rb +34 -0
  133. data/spec/mongoid/relations/eager/belongs_to_spec.rb +9 -0
  134. data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +3 -3
  135. data/spec/mongoid/relations/embedded/many_spec.rb +123 -1
  136. data/spec/mongoid/relations/embedded/one_spec.rb +3 -3
  137. data/spec/mongoid/relations/proxy_spec.rb +28 -0
  138. data/spec/mongoid/relations/referenced/in_spec.rb +1 -1
  139. data/spec/mongoid/relations/referenced/many_spec.rb +47 -23
  140. data/spec/mongoid/relations/referenced/many_to_many_spec.rb +1 -1
  141. data/spec/mongoid/relations/referenced/one_spec.rb +1 -1
  142. data/spec/mongoid/relations/targets/enumerable_spec.rb +9 -2
  143. data/spec/mongoid/reloadable_spec.rb +6 -6
  144. data/spec/mongoid/scopable_spec.rb +41 -28
  145. data/spec/mongoid/selectable_spec.rb +6 -16
  146. data/spec/mongoid/tasks/database_rake_spec.rb +13 -13
  147. data/spec/mongoid/tasks/database_spec.rb +2 -2
  148. data/spec/mongoid/threaded_spec.rb +0 -7
  149. data/spec/mongoid/traversable_spec.rb +2 -2
  150. data/spec/mongoid/validatable/uniqueness_spec.rb +30 -1
  151. data/spec/mongoid_spec.rb +13 -15
  152. data/spec/rails/mongoid_spec.rb +13 -4
  153. data/spec/spec_helper.rb +44 -27
  154. data/spec/support/authorization.rb +12 -0
  155. data/spec/support/expectations.rb +14 -0
  156. metadata +52 -59
  157. data/lib/mongoid/contextual/find_and_modify.rb +0 -69
  158. data/lib/mongoid/contextual/text_search.rb +0 -178
  159. data/lib/mongoid/criteria/#findable.rb# +0 -141
  160. data/lib/mongoid/errors/no_default_session.rb +0 -23
  161. data/lib/mongoid/errors/no_session_config.rb +0 -22
  162. data/lib/mongoid/log_subscriber.rb +0 -55
  163. data/lib/mongoid/positional.rb +0 -71
  164. data/lib/mongoid/sessions.rb +0 -125
  165. data/lib/mongoid/sessions/factory.rb +0 -131
  166. data/lib/mongoid/sessions/mongo_uri.rb +0 -93
  167. data/lib/mongoid/sessions/validators.rb +0 -2
  168. data/lib/mongoid/support/query_counter.rb +0 -23
  169. data/spec/helpers.rb +0 -18
  170. data/spec/mongoid/#atomic_spec.rb# +0 -365
  171. data/spec/mongoid/contextual/find_and_modify_spec.rb +0 -220
  172. data/spec/mongoid/contextual/text_search_spec.rb +0 -209
  173. data/spec/mongoid/log_subscriber_spec.rb +0 -75
  174. data/spec/mongoid/positional_spec.rb +0 -222
  175. data/spec/mongoid/sessions/factory_spec.rb +0 -333
  176. data/spec/mongoid/sessions/mongo_uri_spec.rb +0 -103
  177. data/spec/mongoid/sessions_spec.rb +0 -1252
@@ -144,11 +144,11 @@ describe Mongoid::Scopable do
144
144
  end
145
145
 
146
146
  before do
147
- Band.scope_stack.push(criteria)
147
+ Mongoid::Threaded.current_scope = criteria
148
148
  end
149
149
 
150
150
  after do
151
- Band.scope_stack.clear
151
+ Mongoid::Threaded.current_scope = nil
152
152
  end
153
153
 
154
154
  it "returns the criteria on the stack" do
@@ -567,13 +567,9 @@ describe Mongoid::Scopable do
567
567
 
568
568
  context "when both scopes are or queries" do
569
569
 
570
- let(:time) do
571
- Time.now
572
- end
573
-
574
570
  before do
575
571
  Band.scope(:xxx, ->{ Band.any_of({ :aaa.gt => 0 }, { :bbb.gt => 0 }) })
576
- Band.scope(:yyy, ->{ Band.any_of({ :ccc => nil }, { :ccc.gt => time }) })
572
+ Band.scope(:yyy, ->{ Band.any_of({ :ccc => nil }, { :ccc.gt => 1 }) })
577
573
  end
578
574
 
579
575
  after do
@@ -592,7 +588,7 @@ describe Mongoid::Scopable do
592
588
  expect(criteria.selector).to eq({
593
589
  "$or" => [
594
590
  { "ccc" => nil },
595
- { "ccc" => { "$gt" => time }},
591
+ { "ccc" => { "$gt" => 1.0 }},
596
592
  { "aaa" => { "$gt" => 0.0 }},
597
593
  { "bbb" => { "$gt" => 0.0 }}
598
594
  ]
@@ -644,33 +640,34 @@ describe Mongoid::Scopable do
644
640
  expect(circle_scope_keys).to match_array([:located_at, :with_radius])
645
641
  end
646
642
  end
647
- end
648
-
649
- describe ".scope_stack" do
650
-
651
- context "when the scope stack has not been accessed" do
652
-
653
- it "returns an empty array" do
654
- expect(Band.scope_stack).to eq([])
655
- end
656
- end
657
643
 
658
- context "when a criteria exists on the current thread" do
659
-
660
- let(:criteria) do
661
- Band.where(active: true)
662
- end
644
+ context "when calling a scope defined in a parent class" do
663
645
 
664
646
  before do
665
- Mongoid::Threaded.scope_stack[Band.object_id] = [ criteria ]
647
+ Shape.class_eval do
648
+ scope :visible, -> { large }
649
+ scope :large, -> { all }
650
+ end
651
+ Circle.class_eval do
652
+ scope :large, -> { where(radius: 5) }
653
+ end
666
654
  end
667
655
 
668
656
  after do
669
- Mongoid::Threaded.scope_stack[Band.object_id].clear
657
+ class << Shape
658
+ undef_method :visible
659
+ undef_method :large
660
+ end
661
+ Shape._declared_scopes.clear
662
+
663
+ class << Circle
664
+ undef_method :large
665
+ end
666
+ Circle._declared_scopes.clear
670
667
  end
671
668
 
672
- it "returns the criteria in the array" do
673
- expect(Band.scope_stack).to eq([ criteria ])
669
+ it "uses sublcass context for all the other used scopes" do
670
+ expect(Circle.visible.selector).to eq("radius" => 5)
674
671
  end
675
672
  end
676
673
  end
@@ -784,6 +781,22 @@ describe Mongoid::Scopable do
784
781
  expect(unscoped.selector).to be_empty
785
782
  end
786
783
  end
784
+
785
+ context "when default scope is in a super class" do
786
+
787
+ before do
788
+ Band.scope(:active, ->{ Band.where(active: true) })
789
+ end
790
+
791
+ let(:unscoped) do
792
+ class U2 < Band; end
793
+ U2.unscoped.active
794
+ end
795
+
796
+ it "clears default scope" do
797
+ expect(unscoped.selector).to eq({ "active" => true })
798
+ end
799
+ end
787
800
  end
788
801
 
789
802
  context "when used with a block" do
@@ -888,7 +901,7 @@ describe Mongoid::Scopable do
888
901
 
889
902
  it "pops the criteria off the stack" do
890
903
  Band.with_scope(criteria) {}
891
- expect(Band.scope_stack).to be_empty
904
+ expect(Mongoid::Threaded.current_scope).to be_nil
892
905
  end
893
906
  end
894
907
 
@@ -82,10 +82,8 @@ describe Mongoid::Selectable do
82
82
  person.create_name(first_name: "test", last_name: "user")
83
83
  end
84
84
 
85
- it "returns the hash with the selector" do
86
- expect(name.atomic_selector).to eq(
87
- { "_id" => person.id, "name._id" => name.id }
88
- )
85
+ it "returns the hash with the root selector" do
86
+ expect(name.atomic_selector).to eq({ "_id" => person.id })
89
87
  end
90
88
  end
91
89
 
@@ -95,10 +93,8 @@ describe Mongoid::Selectable do
95
93
  person.addresses.create(street: "kreuzbergstr")
96
94
  end
97
95
 
98
- it "returns the hash with the selector" do
99
- expect(address.atomic_selector).to eq(
100
- { "_id" => person.id, "addresses._id" => address.id }
101
- )
96
+ it "returns the hash with the root selector" do
97
+ expect(address.atomic_selector).to eq({ "_id" => person.id })
102
98
  end
103
99
 
104
100
  context "when the document's id changes" do
@@ -118,14 +114,8 @@ describe Mongoid::Selectable do
118
114
  address.locations.create
119
115
  end
120
116
 
121
- it "returns a hash with the selector" do
122
- expect(location.atomic_selector).to eq(
123
- {
124
- "_id" => person.id,
125
- "addresses._id" => address.id,
126
- "addresses.0.locations._id" => location.id
127
- }
128
- )
117
+ it "returns a hash with the root selector" do
118
+ expect(location.atomic_selector).to eq({ "_id" => person.id })
129
119
  end
130
120
  end
131
121
  end
@@ -45,7 +45,7 @@ shared_context "rails rake task" do
45
45
  end
46
46
  end
47
47
 
48
- describe "db:drop" do
48
+ describe "db:drop", if: non_legacy_server? do
49
49
  include_context "rake task"
50
50
  include_context "rails rake task"
51
51
 
@@ -58,7 +58,7 @@ describe "db:drop" do
58
58
  end
59
59
  end
60
60
 
61
- describe "db:purge" do
61
+ describe "db:purge", if: non_legacy_server? do
62
62
  include_context "rake task"
63
63
  include_context "rails rake task"
64
64
 
@@ -71,7 +71,7 @@ describe "db:purge" do
71
71
  end
72
72
  end
73
73
 
74
- describe "db:seed" do
74
+ describe "db:seed", if: non_legacy_server? do
75
75
  include_context "rake task"
76
76
  include_context "rails rake task"
77
77
 
@@ -85,7 +85,7 @@ describe "db:seed" do
85
85
  end
86
86
  end
87
87
 
88
- describe "db:setup" do
88
+ describe "db:setup", if: non_legacy_server? do
89
89
  include_context "rake task"
90
90
  include_context "rails rake task"
91
91
 
@@ -117,7 +117,7 @@ describe "db:setup" do
117
117
  end
118
118
  end
119
119
 
120
- describe "db:reset" do
120
+ describe "db:reset", if: non_legacy_server? do
121
121
  include_context "rake task"
122
122
  include_context "rails rake task"
123
123
 
@@ -135,7 +135,7 @@ describe "db:reset" do
135
135
  end
136
136
  end
137
137
 
138
- describe "db:create" do
138
+ describe "db:create", if: non_legacy_server? do
139
139
  include_context "rake task"
140
140
  include_context "rails rake task"
141
141
 
@@ -144,7 +144,7 @@ describe "db:create" do
144
144
  end
145
145
  end
146
146
 
147
- describe "db:migrate" do
147
+ describe "db:migrate", if: non_legacy_server? do
148
148
  include_context "rake task"
149
149
  include_context "rails rake task"
150
150
 
@@ -153,7 +153,7 @@ describe "db:migrate" do
153
153
  end
154
154
  end
155
155
 
156
- describe "db:test:prepare" do
156
+ describe "db:test:prepare", if: non_legacy_server? do
157
157
  include_context "rake task"
158
158
  include_context "rails rake task"
159
159
 
@@ -174,7 +174,7 @@ describe "db:test:prepare" do
174
174
  end
175
175
  end
176
176
 
177
- describe "db:mongoid:create_indexes" do
177
+ describe "db:mongoid:create_indexes", if: non_legacy_server? do
178
178
  include_context "rake task"
179
179
 
180
180
  it_behaves_like "create_indexes"
@@ -198,7 +198,7 @@ describe "db:mongoid:create_indexes" do
198
198
  end
199
199
  end
200
200
 
201
- describe "db:mongoid:remove_undefined_indexes" do
201
+ describe "db:mongoid:remove_undefined_indexes", if: non_legacy_server? do
202
202
  include_context "rake task"
203
203
 
204
204
  it "receives remove_undefined_indexes" do
@@ -224,7 +224,7 @@ describe "db:mongoid:remove_undefined_indexes" do
224
224
  end
225
225
  end
226
226
 
227
- describe "db:mongoid:remove_indexes" do
227
+ describe "db:mongoid:remove_indexes", if: non_legacy_server? do
228
228
  include_context "rake task"
229
229
 
230
230
  it "receives remove_indexes" do
@@ -250,7 +250,7 @@ describe "db:mongoid:remove_indexes" do
250
250
  end
251
251
  end
252
252
 
253
- describe "db:mongoid:drop" do
253
+ describe "db:mongoid:drop", if: non_legacy_server? do
254
254
  include_context "rake task"
255
255
 
256
256
  it "works" do
@@ -266,7 +266,7 @@ describe "db:mongoid:drop" do
266
266
  end
267
267
  end
268
268
 
269
- describe "db:mongoid:purge" do
269
+ describe "db:mongoid:purge", if: non_legacy_server? do
270
270
  include_context "rake task"
271
271
 
272
272
  it "receives a purge" do
@@ -100,7 +100,7 @@ describe "Mongoid::Tasks::Database" do
100
100
  context "with extra index on model collection" do
101
101
 
102
102
  before(:each) do
103
- User.collection.indexes.create(account_expires: 1)
103
+ User.collection.indexes.create_one(account_expires: 1)
104
104
  end
105
105
 
106
106
  let(:names) do
@@ -121,7 +121,7 @@ describe "Mongoid::Tasks::Database" do
121
121
 
122
122
  before(:each) do
123
123
  Mongoid::Tasks::Database.create_indexes(models)
124
- indexes.create(account_expires: 1)
124
+ indexes.create_one(account_expires: 1)
125
125
  Mongoid::Tasks::Database.remove_undefined_indexes(models)
126
126
  end
127
127
 
@@ -106,13 +106,6 @@ describe Mongoid::Threaded do
106
106
  end
107
107
  end
108
108
 
109
- describe "#scope_stack" do
110
-
111
- it "returns the default with the scope stack key" do
112
- expect(described_class.scope_stack).to be_a(Hash)
113
- end
114
- end
115
-
116
109
  describe "#begin_validate" do
117
110
 
118
111
  let(:person) do
@@ -71,14 +71,14 @@ describe Mongoid::Traversable do
71
71
  context "when the document is a subclass" do
72
72
 
73
73
  it "returns true" do
74
- expect(Circle).to be_hereditary
74
+ expect(Circle.hereditary?).to be true
75
75
  end
76
76
  end
77
77
 
78
78
  context "when the document is not a subclass" do
79
79
 
80
80
  it "returns false" do
81
- expect(Shape).to_not be_hereditary
81
+ expect(Shape.hereditary?).to be false
82
82
  end
83
83
  end
84
84
  end
@@ -147,6 +147,35 @@ describe Mongoid::Validatable::UniquenessValidator do
147
147
  Dictionary.reset_callbacks(:validate)
148
148
  end
149
149
 
150
+ context "when no attribute is set" do
151
+
152
+ context "when no document with no value exists in the database" do
153
+
154
+ let(:dictionary) do
155
+ Dictionary.new
156
+ end
157
+
158
+ it "returns true" do
159
+ expect(dictionary).to be_valid
160
+ end
161
+ end
162
+
163
+ context "when a document with no value exists in the database" do
164
+
165
+ before do
166
+ Dictionary.create
167
+ end
168
+
169
+ let(:dictionary) do
170
+ Dictionary.new
171
+ end
172
+
173
+ it "returns false" do
174
+ expect(dictionary).to_not be_valid
175
+ end
176
+ end
177
+ end
178
+
150
179
  context "when the attribute is unique" do
151
180
 
152
181
  context "when single localization" do
@@ -2382,7 +2411,7 @@ describe Mongoid::Validatable::UniquenessValidator do
2382
2411
  Person.reset_callbacks(:validate)
2383
2412
  end
2384
2413
 
2385
- it "transfers the options to the cloned session" do
2414
+ it "transfers the options to the cloned client" do
2386
2415
  expect {
2387
2416
  Person.create!(ssn: "132-11-1111", username: "asdfsdfA")
2388
2417
  }.to raise_error
@@ -31,37 +31,35 @@ describe Mongoid do
31
31
  end
32
32
  end
33
33
 
34
- describe ".default_session" do
34
+ describe ".default_client" do
35
35
 
36
- it "returns the default session" do
37
- expect(Mongoid.default_session).to eq(Mongoid::Sessions.default)
36
+ it "returns the default client" do
37
+ expect(Mongoid.default_client).to eq(Mongoid::Clients.default)
38
38
  end
39
39
  end
40
40
 
41
- describe ".disconnect_sessions" do
41
+ describe ".disconnect_clients" do
42
42
 
43
- let(:sessions) do
44
- Mongoid::Threaded.sessions.values
43
+ let(:clients) do
44
+ Mongoid::Clients.clients.values
45
45
  end
46
46
 
47
47
  before do
48
48
  Band.all.entries
49
- Mongoid.disconnect_sessions
50
49
  end
51
50
 
52
- it "disconnects from all active sessions" do
53
- sessions.each do |session|
54
- session.cluster.nodes.each do |node|
55
- expect(node.send(:connected?)).to be false
56
- end
51
+ it "disconnects from all active clients" do
52
+ clients.each do |client|
53
+ expect(client.cluster).to receive(:disconnect!).and_call_original
57
54
  end
55
+ Mongoid.disconnect_clients
58
56
  end
59
57
  end
60
58
 
61
- describe ".session" do
59
+ describe ".client" do
62
60
 
63
- it "returns the named session" do
64
- expect(Mongoid.session(:default)).to eq(Mongoid::Sessions.default)
61
+ it "returns the named client" do
62
+ expect(Mongoid.client(:default)).to eq(Mongoid::Clients.default)
65
63
  end
66
64
  end
67
65
 
@@ -5,7 +5,7 @@ describe "Rails::Mongoid" do
5
5
  before(:all) do
6
6
  require "rails/mongoid"
7
7
  ::Mongoid.models.delete_if do |model|
8
- ![ User, Account, Address ].include?(model)
8
+ ![ User, Account, Address, AddressNumber ].include?(model)
9
9
  end
10
10
  end
11
11
 
@@ -20,7 +20,11 @@ describe "Rails::Mongoid" do
20
20
  end
21
21
 
22
22
  let(:paths) do
23
- { "app/models" => [ "/rails/root/app/models" ] }
23
+ double('[]' => path)
24
+ end
25
+
26
+ let(:path) do
27
+ double(expanded: [ "/rails/root/app/models" ])
24
28
  end
25
29
 
26
30
  context "when preload models config is false" do
@@ -98,7 +102,11 @@ describe "Rails::Mongoid" do
98
102
  end
99
103
 
100
104
  let(:paths) do
101
- { "app/models" => [ "/rails/root/app/models" ] }
105
+ double('[]' => path)
106
+ end
107
+
108
+ let(:path) do
109
+ double(expanded: [ "/rails/root/app/models" ])
102
110
  end
103
111
 
104
112
  context "even when preload models config is false" do
@@ -132,12 +140,13 @@ describe "Rails::Mongoid" do
132
140
  end
133
141
 
134
142
  before(:all) do
135
- Mongoid.preload_models = ["user"]
143
+ Mongoid.preload_models = ["user", "AddressNumber"]
136
144
  end
137
145
 
138
146
  it "loads selected models only" do
139
147
  allow(Dir).to receive(:glob).with("/rails/root/app/models/**/*.rb").and_return(files)
140
148
  expect(Rails::Mongoid).to receive(:load_model).with("user")
149
+ expect(Rails::Mongoid).to receive(:load_model).with("address_number")
141
150
  expect(Rails::Mongoid).to receive(:load_model).with("address").never
142
151
  Rails::Mongoid.load_models(app)
143
152
  end