mongo_mapper 0.12.0 → 0.13.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +7 -0
  2. data/README.rdoc +35 -13
  3. data/bin/mmconsole +1 -1
  4. data/lib/mongo_mapper.rb +4 -0
  5. data/lib/mongo_mapper/connection.rb +17 -6
  6. data/lib/mongo_mapper/document.rb +1 -0
  7. data/lib/mongo_mapper/exceptions.rb +4 -1
  8. data/lib/mongo_mapper/extensions/binary.rb +1 -1
  9. data/lib/mongo_mapper/extensions/boolean.rb +20 -23
  10. data/lib/mongo_mapper/extensions/date.rb +3 -3
  11. data/lib/mongo_mapper/extensions/integer.rb +5 -1
  12. data/lib/mongo_mapper/extensions/kernel.rb +2 -0
  13. data/lib/mongo_mapper/extensions/ordered_hash.rb +23 -0
  14. data/lib/mongo_mapper/extensions/string.rb +2 -2
  15. data/lib/mongo_mapper/extensions/time.rb +7 -5
  16. data/lib/mongo_mapper/middleware/identity_map.rb +3 -4
  17. data/lib/mongo_mapper/plugins.rb +1 -1
  18. data/lib/mongo_mapper/plugins/associations.rb +11 -5
  19. data/lib/mongo_mapper/plugins/associations/base.rb +5 -3
  20. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +0 -0
  21. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +8 -8
  22. data/lib/mongo_mapper/plugins/associations/collection.rb +2 -0
  23. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +32 -7
  24. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +2 -2
  25. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +12 -12
  26. data/lib/mongo_mapper/plugins/associations/proxy.rb +5 -1
  27. data/lib/mongo_mapper/plugins/associations/single_association.rb +6 -6
  28. data/lib/mongo_mapper/plugins/clone.rb +4 -2
  29. data/lib/mongo_mapper/plugins/dirty.rb +22 -21
  30. data/lib/mongo_mapper/plugins/document.rb +4 -4
  31. data/lib/mongo_mapper/plugins/dumpable.rb +22 -0
  32. data/lib/mongo_mapper/plugins/embedded_callbacks.rb +58 -9
  33. data/lib/mongo_mapper/plugins/identity_map.rb +42 -32
  34. data/lib/mongo_mapper/plugins/keys.rb +133 -54
  35. data/lib/mongo_mapper/plugins/keys/key.rb +68 -22
  36. data/lib/mongo_mapper/plugins/modifiers.rb +26 -19
  37. data/lib/mongo_mapper/plugins/persistence.rb +15 -5
  38. data/lib/mongo_mapper/plugins/querying.rb +15 -40
  39. data/lib/mongo_mapper/plugins/querying/{decorator.rb → decorated_plucky_query.rb} +24 -4
  40. data/lib/mongo_mapper/plugins/rails.rb +22 -2
  41. data/lib/mongo_mapper/plugins/safe.rb +8 -5
  42. data/lib/mongo_mapper/plugins/sci.rb +26 -4
  43. data/lib/mongo_mapper/plugins/scopes.rb +5 -4
  44. data/lib/mongo_mapper/plugins/timestamps.rb +11 -4
  45. data/lib/mongo_mapper/plugins/validations.rb +1 -1
  46. data/lib/mongo_mapper/utils.rb +12 -0
  47. data/lib/mongo_mapper/version.rb +1 -1
  48. data/lib/rails/generators/mongo_mapper/config/config_generator.rb +20 -7
  49. data/lib/rails/generators/mongo_mapper/config/templates/mongo.yml +6 -0
  50. data/lib/rails/generators/mongo_mapper/model/model_generator.rb +18 -1
  51. data/lib/rails/generators/mongo_mapper/model/templates/model.rb +9 -5
  52. data/{test/functional/test_accessible.rb → spec/functional/accessible_spec.rb} +29 -29
  53. data/{test/functional/associations/test_belongs_to_polymorphic_proxy.rb → spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb} +10 -10
  54. data/{test/functional/associations/test_belongs_to_proxy.rb → spec/functional/associations/belongs_to_proxy_spec.rb} +82 -64
  55. data/{test/functional/associations/test_in_array_proxy.rb → spec/functional/associations/in_array_proxy_spec.rb} +68 -68
  56. data/{test/functional/associations/test_many_documents_as_proxy.rb → spec/functional/associations/many_documents_as_proxy_spec.rb} +37 -38
  57. data/{test/functional/associations/test_many_documents_proxy.rb → spec/functional/associations/many_documents_proxy_spec.rb} +233 -146
  58. data/{test/functional/associations/test_many_embedded_polymorphic_proxy.rb → spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb} +19 -20
  59. data/{test/functional/associations/test_many_embedded_proxy.rb → spec/functional/associations/many_embedded_proxy_spec.rb} +23 -24
  60. data/{test/functional/associations/test_many_polymorphic_proxy.rb → spec/functional/associations/many_polymorphic_proxy_spec.rb} +45 -46
  61. data/{test/functional/associations/test_one_as_proxy.rb → spec/functional/associations/one_as_proxy_spec.rb} +75 -77
  62. data/{test/functional/associations/test_one_embedded_polymorphic_proxy.rb → spec/functional/associations/one_embedded_polymorphic_proxy_spec.rb} +31 -32
  63. data/{test/functional/associations/test_one_embedded_proxy.rb → spec/functional/associations/one_embedded_proxy_spec.rb} +10 -10
  64. data/{test/functional/associations/test_one_proxy.rb → spec/functional/associations/one_proxy_spec.rb} +125 -102
  65. data/spec/functional/associations_spec.rb +48 -0
  66. data/{test/functional/test_binary.rb → spec/functional/binary_spec.rb} +6 -6
  67. data/spec/functional/caching_spec.rb +75 -0
  68. data/{test/functional/test_callbacks.rb → spec/functional/callbacks_spec.rb} +84 -26
  69. data/{test/functional/test_dirty.rb → spec/functional/dirty_spec.rb} +57 -42
  70. data/{test/functional/test_document.rb → spec/functional/document_spec.rb} +52 -52
  71. data/spec/functional/dumpable_spec.rb +24 -0
  72. data/{test/functional/test_dynamic_querying.rb → spec/functional/dynamic_querying_spec.rb} +14 -14
  73. data/{test/functional/test_embedded_document.rb → spec/functional/embedded_document_spec.rb} +51 -42
  74. data/{test/functional/test_equality.rb → spec/functional/equality_spec.rb} +4 -4
  75. data/spec/functional/extensions_spec.rb +16 -0
  76. data/{test/functional/test_identity_map.rb → spec/functional/identity_map_spec.rb} +73 -61
  77. data/spec/functional/indexes_spec.rb +48 -0
  78. data/spec/functional/keys_spec.rb +224 -0
  79. data/{test/functional/test_logger.rb → spec/functional/logger_spec.rb} +6 -6
  80. data/spec/functional/modifiers_spec.rb +550 -0
  81. data/spec/functional/pagination_spec.rb +89 -0
  82. data/spec/functional/protected_spec.rb +199 -0
  83. data/spec/functional/querying_spec.rb +1003 -0
  84. data/spec/functional/rails_spec.rb +55 -0
  85. data/spec/functional/safe_spec.rb +163 -0
  86. data/{test/functional/test_sci.rb → spec/functional/sci_spec.rb} +123 -34
  87. data/{test/functional/test_scopes.rb → spec/functional/scopes_spec.rb} +59 -26
  88. data/spec/functional/timestamps_spec.rb +97 -0
  89. data/{test/functional/test_touch.rb → spec/functional/touch_spec.rb} +13 -13
  90. data/spec/functional/userstamps_spec.rb +46 -0
  91. data/{test/functional/test_validations.rb → spec/functional/validations_spec.rb} +64 -64
  92. data/spec/spec_helper.rb +81 -0
  93. data/spec/support/matchers.rb +24 -0
  94. data/{test → spec/support}/models.rb +1 -6
  95. data/spec/unit/associations/base_spec.rb +146 -0
  96. data/spec/unit/associations/belongs_to_association_spec.rb +30 -0
  97. data/spec/unit/associations/many_association_spec.rb +64 -0
  98. data/spec/unit/associations/one_association_spec.rb +48 -0
  99. data/{test/unit/associations/test_proxy.rb → spec/unit/associations/proxy_spec.rb} +21 -21
  100. data/{test/unit/test_clone.rb → spec/unit/clone_spec.rb} +21 -11
  101. data/spec/unit/config_generator_spec.rb +24 -0
  102. data/{test/unit/test_document.rb → spec/unit/document_spec.rb} +42 -42
  103. data/{test/unit/test_dynamic_finder.rb → spec/unit/dynamic_finder_spec.rb} +28 -28
  104. data/{test/unit/test_embedded_document.rb → spec/unit/embedded_document_spec.rb} +102 -108
  105. data/{test/unit/test_equality.rb → spec/unit/equality_spec.rb} +7 -7
  106. data/{test/unit/test_exceptions.rb → spec/unit/exceptions_spec.rb} +3 -3
  107. data/{test/unit/test_extensions.rb → spec/unit/extensions_spec.rb} +85 -71
  108. data/spec/unit/identity_map_middleware_spec.rb +134 -0
  109. data/{test/unit/test_inspect.rb → spec/unit/inspect_spec.rb} +8 -8
  110. data/{test/unit/test_key.rb → spec/unit/key_spec.rb} +82 -52
  111. data/spec/unit/keys_spec.rb +155 -0
  112. data/spec/unit/model_generator_spec.rb +47 -0
  113. data/spec/unit/mongo_mapper_spec.rb +184 -0
  114. data/spec/unit/pagination_spec.rb +11 -0
  115. data/{test/unit/test_plugins.rb → spec/unit/plugins_spec.rb} +14 -14
  116. data/spec/unit/rails_compatibility_spec.rb +40 -0
  117. data/{test/unit/test_rails_reflect_on_association.rb → spec/unit/rails_reflect_on_association_spec.rb} +9 -9
  118. data/{test/unit/test_rails.rb → spec/unit/rails_spec.rb} +31 -31
  119. data/spec/unit/serialization_spec.rb +169 -0
  120. data/spec/unit/serializers/json_serializer_spec.rb +218 -0
  121. data/spec/unit/serializers/xml_serializer_spec.rb +198 -0
  122. data/{test/unit/test_time_zones.rb → spec/unit/time_zones_spec.rb} +8 -8
  123. data/{test/unit/test_translation.rb → spec/unit/translation_spec.rb} +6 -6
  124. data/{test/unit/test_validations.rb → spec/unit/validations_spec.rb} +72 -59
  125. metadata +199 -179
  126. data/test/_NOTE_ON_TESTING +0 -1
  127. data/test/functional/test_associations.rb +0 -46
  128. data/test/functional/test_caching.rb +0 -77
  129. data/test/functional/test_indexes.rb +0 -50
  130. data/test/functional/test_modifiers.rb +0 -537
  131. data/test/functional/test_pagination.rb +0 -91
  132. data/test/functional/test_protected.rb +0 -201
  133. data/test/functional/test_querying.rb +0 -935
  134. data/test/functional/test_safe.rb +0 -76
  135. data/test/functional/test_timestamps.rb +0 -62
  136. data/test/functional/test_userstamps.rb +0 -44
  137. data/test/support/railtie.rb +0 -4
  138. data/test/support/railtie/autoloaded.rb +0 -2
  139. data/test/support/railtie/not_autoloaded.rb +0 -3
  140. data/test/support/railtie/parent.rb +0 -3
  141. data/test/test_active_model_lint.rb +0 -18
  142. data/test/test_helper.rb +0 -93
  143. data/test/unit/associations/test_base.rb +0 -146
  144. data/test/unit/associations/test_belongs_to_association.rb +0 -29
  145. data/test/unit/associations/test_many_association.rb +0 -63
  146. data/test/unit/associations/test_one_association.rb +0 -47
  147. data/test/unit/serializers/test_json_serializer.rb +0 -216
  148. data/test/unit/serializers/test_xml_serializer.rb +0 -196
  149. data/test/unit/test_identity_map_middleware.rb +0 -132
  150. data/test/unit/test_keys.rb +0 -65
  151. data/test/unit/test_mongo_mapper.rb +0 -157
  152. data/test/unit/test_pagination.rb +0 -11
  153. data/test/unit/test_rails_compatibility.rb +0 -38
  154. data/test/unit/test_serialization.rb +0 -166
@@ -1,25 +1,24 @@
1
- require 'test_helper'
2
- require 'models'
1
+ require 'spec_helper'
3
2
 
4
- class ManyEmbeddedPolymorphicProxyTest < Test::Unit::TestCase
5
- def setup
3
+ describe "ManyEmbeddedPolymorphicProxy" do
4
+ before do
6
5
  Catalog.collection.remove
7
6
  TrModels::Fleet.collection.remove
8
7
  end
9
8
 
10
- should "default reader to empty array" do
9
+ it "should default reader to empty array" do
11
10
  catalog = Catalog.new
12
11
  catalog.medias.should == []
13
12
  end
14
13
 
15
- should "allow adding to association like it was an array" do
14
+ it "should allow adding to association like it was an array" do
16
15
  catalog = Catalog.new
17
16
  catalog.medias << Video.new
18
17
  catalog.medias.push Video.new
19
18
  catalog.medias.size.should == 2
20
19
  end
21
20
 
22
- should "be able to replace the association" do
21
+ it "should be able to replace the association" do
23
22
  catalog = Catalog.new
24
23
  catalog.medias = [Video.new('file' => 'video.mpg', 'length' => 3600)]
25
24
  catalog.save.should be_true
@@ -31,7 +30,7 @@ class ManyEmbeddedPolymorphicProxyTest < Test::Unit::TestCase
31
30
  end
32
31
 
33
32
  context "associating objects of non-SCI class" do
34
- should "work on replacement" do
33
+ it "should work on replacement" do
35
34
  catalog = Catalog.new
36
35
  catalog.medias = [Human.new(:name => 'Frank'), Robot.new(:serial_number => '1B')]
37
36
 
@@ -51,7 +50,7 @@ class ManyEmbeddedPolymorphicProxyTest < Test::Unit::TestCase
51
50
  catalog.medias[1].class.should == Robot
52
51
  end
53
52
 
54
- should "work on replacement with hashes" do
53
+ it "should work on replacement with hashes" do
55
54
  catalog = Catalog.new
56
55
  catalog.medias = [{:name => 'Frank', '_type' => 'Human'}, {:serial_number => '1B', '_type' => 'Robot'}]
57
56
 
@@ -71,7 +70,7 @@ class ManyEmbeddedPolymorphicProxyTest < Test::Unit::TestCase
71
70
  catalog.medias[1].class.should == Robot
72
71
  end
73
72
 
74
- should "work with concatination" do
73
+ it "should work with concatination" do
75
74
  catalog = Catalog.new
76
75
  catalog.medias << Human.new(:name => 'Frank')
77
76
  catalog.medias << Robot.new(:serial_number => '1B')
@@ -94,11 +93,11 @@ class ManyEmbeddedPolymorphicProxyTest < Test::Unit::TestCase
94
93
  end
95
94
 
96
95
  context "count" do
97
- should "default to 0" do
96
+ it "should default to 0" do
98
97
  Catalog.new.medias.count.should == 0
99
98
  end
100
99
 
101
- should 'return correct count if any are embedded' do
100
+ it 'should return correct count if any are embedded' do
102
101
  catalog = Catalog.new
103
102
  catalog.medias = [
104
103
  Video.new('file' => 'video.mpg', 'length' => 3600),
@@ -112,7 +111,7 @@ class ManyEmbeddedPolymorphicProxyTest < Test::Unit::TestCase
112
111
  end
113
112
  end
114
113
 
115
- should "store different associations" do
114
+ it "should store different associations" do
116
115
  catalog = Catalog.new
117
116
  catalog.medias = [
118
117
  Video.new('file' => 'video.mpg', 'length' => 3600),
@@ -133,7 +132,7 @@ class ManyEmbeddedPolymorphicProxyTest < Test::Unit::TestCase
133
132
  end
134
133
 
135
134
  context "With modularized models" do
136
- should "set associations correctly" do
135
+ it "should set associations correctly" do
137
136
  fleet_attributes = {
138
137
  'name' => 'My Fleet',
139
138
  'transports' => [
@@ -170,19 +169,19 @@ class ManyEmbeddedPolymorphicProxyTest < Test::Unit::TestCase
170
169
  fleet.transports[2].year.should == 2008
171
170
  end
172
171
 
173
- should "default reader to empty array" do
172
+ it "should default reader to empty array" do
174
173
  fleet = TrModels::Fleet.new
175
174
  fleet.transports.should == []
176
175
  end
177
176
 
178
- should "allow adding to association like it was an array" do
177
+ it "should allow adding to association like it was an array" do
179
178
  fleet = TrModels::Fleet.new
180
179
  fleet.transports << TrModels::Car.new
181
180
  fleet.transports.push TrModels::Bus.new
182
181
  fleet.transports.size.should == 2
183
182
  end
184
183
 
185
- should "be able to replace the association" do
184
+ it "should be able to replace the association" do
186
185
  fleet = TrModels::Fleet.new
187
186
  fleet.transports = [TrModels::Car.new('license_plate' => 'DCU2013', 'model' => 'Honda Civic')]
188
187
  fleet.save.should be_true
@@ -192,7 +191,7 @@ class ManyEmbeddedPolymorphicProxyTest < Test::Unit::TestCase
192
191
  fleet.transports[0].license_plate.should == 'DCU2013'
193
192
  end
194
193
 
195
- should "store different associations" do
194
+ it "should store different associations" do
196
195
  fleet = TrModels::Fleet.new
197
196
  fleet.transports = [
198
197
  TrModels::Car.new('license_plate' => 'ABC1223', 'model' => 'Honda Civic', 'year' => 2003),
@@ -214,7 +213,7 @@ class ManyEmbeddedPolymorphicProxyTest < Test::Unit::TestCase
214
213
  end
215
214
 
216
215
  context "extending the association" do
217
- should "work using a block passed to many" do
216
+ it "should work using a block passed to many" do
218
217
  catalog = Catalog.new
219
218
  medias = catalog.medias = [
220
219
  Video.new('file' => 'video.mpg', 'length' => 3600, :visible => true),
@@ -225,7 +224,7 @@ class ManyEmbeddedPolymorphicProxyTest < Test::Unit::TestCase
225
224
  catalog.medias.visible.should == [medias[0], medias[1]]
226
225
  end
227
226
 
228
- should "work using many's :extend option" do
227
+ it "should work using many's :extend option" do
229
228
  fleet = TrModels::Fleet.new
230
229
  transports = fleet.transports = [
231
230
  TrModels::Car.new('license_plate' => 'ABC1223', 'model' => 'Honda Civic', 'year' => 2003, :purchased_on => 2.years.ago.to_date),
@@ -1,8 +1,7 @@
1
- require 'test_helper'
2
- require 'models'
1
+ require 'spec_helper'
3
2
 
4
- class ManyEmbeddedProxyTest < Test::Unit::TestCase
5
- def setup
3
+ describe "ManyEmbeddedProxy" do
4
+ before do
6
5
  @comment_class = EDoc do
7
6
  key :name, String
8
7
  key :body, String
@@ -28,18 +27,18 @@ class ManyEmbeddedProxyTest < Test::Unit::TestCase
28
27
  @owner_class.many :pets, :class => @pet_class
29
28
  end
30
29
 
31
- should "default reader to empty array" do
30
+ it "should default reader to empty array" do
32
31
  @post_class.new.comments.should == []
33
32
  end
34
33
 
35
- should "allow adding to association like it was an array" do
34
+ it "should allow adding to association like it was an array" do
36
35
  post = @post_class.new
37
36
  post.comments << @comment_class.new
38
37
  post.comments.push @comment_class.new
39
38
  post.comments.size.should == 2
40
39
  end
41
40
 
42
- should "be embedded in document on save" do
41
+ it "should be embedded in document on save" do
43
42
  frank = @comment_class.new(:name => 'Frank', :body => 'Hi!')
44
43
  bill = @comment_class.new(:name => 'Bill', :body => 'Hi!')
45
44
  post = @post_class.new
@@ -55,7 +54,7 @@ class ManyEmbeddedProxyTest < Test::Unit::TestCase
55
54
  post.comments[1].new?.should == false
56
55
  end
57
56
 
58
- should "allow embedding arbitrarily deep" do
57
+ it "should allow embedding arbitrarily deep" do
59
58
  @klass = Doc()
60
59
  @klass.key :person, @person_class
61
60
 
@@ -72,7 +71,7 @@ class ManyEmbeddedProxyTest < Test::Unit::TestCase
72
71
  doc.person.child.child.name.should == 'Linda'
73
72
  end
74
73
 
75
- should "allow assignment of many embedded documents using a hash" do
74
+ it "should allow assignment of many embedded documents using a hash" do
76
75
  person_attributes = {
77
76
  'name' => 'Mr. Pet Lover',
78
77
  'pets' => [
@@ -103,7 +102,7 @@ class ManyEmbeddedProxyTest < Test::Unit::TestCase
103
102
  end
104
103
 
105
104
  context "passing documents between versions of code" do
106
- setup do
105
+ before do
107
106
  @old_klass = Doc do
108
107
  set_collection_name 'generic_parents'
109
108
  key :name, String
@@ -116,7 +115,7 @@ class ManyEmbeddedProxyTest < Test::Unit::TestCase
116
115
  @updated_klass.many :pets, :class => @pet_class
117
116
  end
118
117
 
119
- should "not break many embedded proxy" do
118
+ it "should not break many embedded proxy" do
120
119
  @old_klass.collection.drop
121
120
  created_by_new_code = @updated_klass.create!
122
121
  created_by_new_code.pets.should == []
@@ -132,12 +131,12 @@ class ManyEmbeddedProxyTest < Test::Unit::TestCase
132
131
  end
133
132
 
134
133
  context "embedding many embedded documents" do
135
- setup do
134
+ before do
136
135
  @klass = Doc()
137
136
  @klass.many :people, :class => @person_class
138
137
  end
139
138
 
140
- should "persist all embedded documents" do
139
+ it "should persist all embedded documents" do
141
140
  meg = @person_class.new(:name => 'Meg', :pets => [
142
141
  @pet_class.new(:name => 'Sparky', :species => 'Dog'),
143
142
  @pet_class.new(:name => 'Koda', :species => 'Dog')
@@ -156,7 +155,7 @@ class ManyEmbeddedProxyTest < Test::Unit::TestCase
156
155
  doc.people.first.pets[1].species.should == 'Dog'
157
156
  end
158
157
 
159
- should "create a reference to the root document for all embedded documents before save" do
158
+ it "should create a reference to the root document for all embedded documents before save" do
160
159
  doc = @klass.new
161
160
  meg = @person_class.new(:name => 'Meg')
162
161
  pet = @pet_class.new(:name => 'Sparky', :species => 'Dog')
@@ -167,7 +166,7 @@ class ManyEmbeddedProxyTest < Test::Unit::TestCase
167
166
  doc.people.first._root_document.should == doc
168
167
  doc.people.first.pets.first._root_document.should == doc
169
168
  end
170
- should "create a reference to the owning document for all embedded documents before save" do
169
+ it "should create a reference to the owning document for all embedded documents before save" do
171
170
  doc = @klass.new
172
171
  meg = @person_class.new(:name => 'Meg')
173
172
  pet = @pet_class.new(:name => 'Sparky', :species => 'Dog')
@@ -179,7 +178,7 @@ class ManyEmbeddedProxyTest < Test::Unit::TestCase
179
178
  doc.people.first.pets.first._parent_document.should == doc.people.first
180
179
  end
181
180
 
182
- should "create a reference to the root document for all embedded documents" do
181
+ it "should create a reference to the root document for all embedded documents" do
183
182
  sparky = @pet_class.new(:name => 'Sparky', :species => 'Dog')
184
183
  meg = @person_class.new(:name => 'Meg', :pets => [sparky])
185
184
  doc = @klass.new
@@ -190,7 +189,7 @@ class ManyEmbeddedProxyTest < Test::Unit::TestCase
190
189
  doc.people.first._root_document.should == doc
191
190
  doc.people.first.pets.first._root_document.should == doc
192
191
  end
193
- should "create a reference to the owning document for all embedded documents" do
192
+ it "should create a reference to the owning document for all embedded documents" do
194
193
  doc = @klass.new
195
194
  meg = @person_class.new(:name => 'Meg')
196
195
  pet = @pet_class.new(:name => 'Sparky', :species => 'Dog')
@@ -204,7 +203,7 @@ class ManyEmbeddedProxyTest < Test::Unit::TestCase
204
203
  doc.people.first.pets.first._parent_document.should == doc.people.first
205
204
  end
206
205
 
207
- should "create embedded_in relationship for embedded docs" do
206
+ it "should create embedded_in relationship for embedded docs" do
208
207
  doc = @klass.new
209
208
  meg = @person_class.new(:name => 'Meg')
210
209
  pet = @pet_class.new(:name => 'Sparky', :species => 'Dog')
@@ -218,7 +217,7 @@ class ManyEmbeddedProxyTest < Test::Unit::TestCase
218
217
  end
219
218
  end
220
219
 
221
- should "allow finding by id" do
220
+ it "should allow finding by id" do
222
221
  sparky = @pet_class.new(:name => 'Sparky', :species => 'Dog')
223
222
  meg = @owner_class.create(:name => 'Meg', :pets => [sparky])
224
223
 
@@ -227,11 +226,11 @@ class ManyEmbeddedProxyTest < Test::Unit::TestCase
227
226
  end
228
227
 
229
228
  context "count" do
230
- should "default to 0" do
229
+ it "should default to 0" do
231
230
  @owner_class.new.pets.count.should == 0
232
231
  end
233
232
 
234
- should "return correct count if any are embedded" do
233
+ it "should return correct count if any are embedded" do
235
234
  owner = @owner_class.new(:name => 'Meg')
236
235
  owner.pets = [@pet_class.new, @pet_class.new]
237
236
  owner.pets.count.should == 2
@@ -242,7 +241,7 @@ class ManyEmbeddedProxyTest < Test::Unit::TestCase
242
241
  end
243
242
 
244
243
  context "extending the association" do
245
- setup do
244
+ before do
246
245
  @address_class = EDoc do
247
246
  key :address, String
248
247
  key :city, String
@@ -255,7 +254,7 @@ class ManyEmbeddedProxyTest < Test::Unit::TestCase
255
254
  end
256
255
  end
257
256
 
258
- should "work using a block passed to many" do
257
+ it "should work using a block passed to many" do
259
258
  @project_class.many :addresses, :class => @address_class do
260
259
  def find_all_by_state(state)
261
260
  find_all { |a| a.state == state }
@@ -270,7 +269,7 @@ class ManyEmbeddedProxyTest < Test::Unit::TestCase
270
269
  project.addresses.find_all_by_state("CA").should == [addr1, addr2]
271
270
  end
272
271
 
273
- should "work using many's :extend option" do
272
+ it "should work using many's :extend option" do
274
273
  module FindByCity
275
274
  def find_by_city(city)
276
275
  find_all { |a| a.city == city }
@@ -1,21 +1,20 @@
1
- require 'test_helper'
2
- require 'models'
1
+ require 'spec_helper'
3
2
 
4
- class ManyPolymorphicProxyTest < Test::Unit::TestCase
5
- def setup
3
+ describe "ManyPolymorphicProxy" do
4
+ before do
6
5
  Room.collection.remove
7
6
  Message.collection.remove
8
7
  end
9
8
 
10
- should "default reader to empty array" do
9
+ it "should default reader to empty array" do
11
10
  Room.new.messages.should == []
12
11
  end
13
12
 
14
- should "add type key to polymorphic class base" do
13
+ it "should add type key to polymorphic class base" do
15
14
  Message.keys.keys.should include('_type')
16
15
  end
17
16
 
18
- should "allow adding to assiciation like it was an array" do
17
+ it "should allow adding to assiciation like it was an array" do
19
18
  room = Room.new
20
19
  room.messages << Enter.new
21
20
  room.messages.push Exit.new
@@ -23,7 +22,7 @@ class ManyPolymorphicProxyTest < Test::Unit::TestCase
23
22
  room.messages.size.should == 3
24
23
  end
25
24
 
26
- should "be able to replace the association" do
25
+ it "should be able to replace the association" do
27
26
  room = Room.create(:name => 'Lounge')
28
27
 
29
28
  lambda {
@@ -42,7 +41,7 @@ class ManyPolymorphicProxyTest < Test::Unit::TestCase
42
41
  messages[2].body.should == 'John exited room'
43
42
  end
44
43
 
45
- should "correctly store type when using <<, push and concat" do
44
+ it "should correctly store type when using <<, push and concat" do
46
45
  room = Room.new
47
46
  room.messages << Enter.new(:body => 'John entered the room', :position => 1)
48
47
  room.messages.push Exit.new(:body => 'John entered the room', :position => 2)
@@ -56,19 +55,19 @@ class ManyPolymorphicProxyTest < Test::Unit::TestCase
56
55
  end
57
56
 
58
57
  context "build" do
59
- should "assign foreign key" do
58
+ it "should assign foreign key" do
60
59
  room = Room.create
61
60
  message = room.messages.build
62
61
  message.room_id.should == room._id
63
62
  end
64
63
 
65
- should "assign _type" do
64
+ it "should assign _type" do
66
65
  room = Room.create
67
66
  message = room.messages.build
68
67
  message._type.should == 'Message'
69
68
  end
70
69
 
71
- should "allow assigning attributes" do
70
+ it "should allow assigning attributes" do
72
71
  room = Room.create
73
72
  message = room.messages.build(:body => 'Foo!')
74
73
  message.body.should == 'Foo!'
@@ -76,26 +75,26 @@ class ManyPolymorphicProxyTest < Test::Unit::TestCase
76
75
  end
77
76
 
78
77
  context "create" do
79
- should "assign foreign key" do
78
+ it "should assign foreign key" do
80
79
  room = Room.create
81
80
  message = room.messages.create
82
81
  message.room_id.should == room._id
83
82
  end
84
83
 
85
- should "assign _type" do
84
+ it "should assign _type" do
86
85
  room = Room.create
87
86
  message = room.messages.create
88
87
  message._type.should == 'Message'
89
88
  end
90
89
 
91
- should "save record" do
90
+ it "should save record" do
92
91
  room = Room.create
93
92
  lambda {
94
93
  room.messages.create
95
94
  }.should change { Message.count }
96
95
  end
97
96
 
98
- should "allow passing attributes" do
97
+ it "should allow passing attributes" do
99
98
  room = Room.create
100
99
  message = room.messages.create(:body => 'Foo!')
101
100
  message.body.should == 'Foo!'
@@ -103,7 +102,7 @@ class ManyPolymorphicProxyTest < Test::Unit::TestCase
103
102
  end
104
103
 
105
104
  context "count" do
106
- should "work scoped to association" do
105
+ it "should work scoped to association" do
107
106
  room = Room.create
108
107
  3.times { room.messages.create }
109
108
 
@@ -114,7 +113,7 @@ class ManyPolymorphicProxyTest < Test::Unit::TestCase
114
113
  other_room.messages.count.should == 2
115
114
  end
116
115
 
117
- should "work with conditions" do
116
+ it "should work with conditions" do
118
117
  room = Room.create
119
118
  room.messages.create(:body => 'Foo')
120
119
  room.messages.create(:body => 'Other 1')
@@ -125,7 +124,7 @@ class ManyPolymorphicProxyTest < Test::Unit::TestCase
125
124
  end
126
125
 
127
126
  context "Finding scoped to association" do
128
- setup do
127
+ before do
129
128
  @lounge = Room.create(:name => 'Lounge')
130
129
  @lm1 = Message.create(:body => 'Loungin!', :position => 1)
131
130
  @lm2 = Message.create(:body => 'I love loungin!', :position => 2)
@@ -142,24 +141,24 @@ class ManyPolymorphicProxyTest < Test::Unit::TestCase
142
141
  end
143
142
 
144
143
  context "dynamic finders" do
145
- should "work with single key" do
144
+ it "should work with single key" do
146
145
  @lounge.messages.find_by_position(1).should == @lm1
147
146
  @hall.messages.find_by_position(2).should == @hm2
148
147
  end
149
148
 
150
- should "work with multiple keys" do
149
+ it "should work with multiple keys" do
151
150
  @lounge.messages.find_by_body_and_position('Loungin!', 1).should == @lm1
152
151
  @lounge.messages.find_by_body_and_position('Loungin!', 2).should be_nil
153
152
  end
154
153
 
155
- should "raise error when using !" do
154
+ it "should raise error when using !" do
156
155
  lambda {
157
156
  @lounge.messages.find_by_position!(222)
158
157
  }.should raise_error(MongoMapper::DocumentNotFound)
159
158
  end
160
159
 
161
160
  context "find_or_create_by" do
162
- should "not create document if found" do
161
+ it "should not create document if found" do
163
162
  lambda {
164
163
  message = @lounge.messages.find_or_create_by_body('Loungin!')
165
164
  message.room.should == @lounge
@@ -167,7 +166,7 @@ class ManyPolymorphicProxyTest < Test::Unit::TestCase
167
166
  }.should_not change { Message.count }
168
167
  end
169
168
 
170
- should "create document if not found" do
169
+ it "should create document if not found" do
171
170
  lambda {
172
171
  message = @lounge.messages.find_or_create_by_body('Yo dawg!')
173
172
  message.room.should == @lounge
@@ -178,49 +177,49 @@ class ManyPolymorphicProxyTest < Test::Unit::TestCase
178
177
  end
179
178
 
180
179
  context "with #all" do
181
- should "work" do
180
+ it "should work" do
182
181
  @lounge.messages.all(:order => "position").should == [@lm1, @lm2]
183
182
  end
184
183
 
185
- should "work with conditions" do
184
+ it "should work with conditions" do
186
185
  messages = @lounge.messages.all(:body => 'Loungin!', :order => "position")
187
186
  messages.should == [@lm1]
188
187
  end
189
188
 
190
- should "work with order" do
189
+ it "should work with order" do
191
190
  messages = @lounge.messages.all(:order => 'position desc')
192
191
  messages.should == [@lm2, @lm1]
193
192
  end
194
193
  end
195
194
 
196
195
  context "with #first" do
197
- should "work" do
196
+ it "should work" do
198
197
  @lounge.messages.first(:order => "position asc").should == @lm1
199
198
  end
200
199
 
201
- should "work with conditions" do
200
+ it "should work with conditions" do
202
201
  message = @lounge.messages.first(:body => 'I love loungin!', :order => "position asc")
203
202
  message.should == @lm2
204
203
  end
205
204
  end
206
205
 
207
206
  context "with #last" do
208
- should "work" do
207
+ it "should work" do
209
208
  @lounge.messages.last(:order => "position asc").should == @lm2
210
209
  end
211
210
 
212
- should "work with conditions" do
211
+ it "should work with conditions" do
213
212
  message = @lounge.messages.last(:body => 'Loungin!', :order => "position asc")
214
213
  message.should == @lm1
215
214
  end
216
215
  end
217
216
 
218
217
  context "with one id" do
219
- should "work for id in association" do
218
+ it "should work for id in association" do
220
219
  @lounge.messages.find(@lm2._id).should == @lm2
221
220
  end
222
221
 
223
- should "not work for id not in association" do
222
+ it "should not work for id not in association" do
224
223
  lambda {
225
224
  @lounge.messages.find!(@hm2._id)
226
225
  }.should raise_error(MongoMapper::DocumentNotFound)
@@ -228,53 +227,53 @@ class ManyPolymorphicProxyTest < Test::Unit::TestCase
228
227
  end
229
228
 
230
229
  context "with query options/criteria" do
231
- should "work with order on association" do
230
+ it "should work with order on association" do
232
231
  @lounge.messages.should == [@lm1, @lm2]
233
232
  end
234
233
 
235
- should "allow overriding the order provided to the association" do
234
+ it "should allow overriding the order provided to the association" do
236
235
  @lounge.messages.all(:order => 'position').should == [@lm1, @lm2]
237
236
  end
238
237
 
239
- should "allow using conditions on association" do
238
+ it "should allow using conditions on association" do
240
239
  @hall.latest_messages.should == [@hm3, @hm2]
241
240
  end
242
241
  end
243
242
 
244
243
  context "with multiple ids" do
245
- should "work for ids in association" do
244
+ it "should work for ids in association" do
246
245
  messages = @lounge.messages.find(@lm1._id, @lm2._id)
247
246
  messages.should == [@lm1, @lm2]
248
247
  end
249
248
 
250
- should "not work for ids not in association" do
251
- assert_raises(MongoMapper::DocumentNotFound) do
249
+ it "should not work for ids not in association" do
250
+ expect {
252
251
  @lounge.messages.find!(@lm1._id, @lm2._id, @hm2._id)
253
- end
252
+ }.to raise_error(MongoMapper::DocumentNotFound)
254
253
  end
255
254
  end
256
255
 
257
256
  context "with #paginate" do
258
- setup do
257
+ before do
259
258
  @messages = @hall.messages.paginate(:per_page => 2, :page => 1, :order => 'position asc')
260
259
  end
261
260
 
262
- should "return total pages" do
261
+ it "should return total pages" do
263
262
  @messages.total_pages.should == 2
264
263
  end
265
264
 
266
- should "return total entries" do
265
+ it "should return total entries" do
267
266
  @messages.total_entries.should == 3
268
267
  end
269
268
 
270
- should "return the subject" do
269
+ it "should return the subject" do
271
270
  @messages.should == [@hm1, @hm2]
272
271
  end
273
272
  end
274
273
  end
275
274
 
276
275
  context "extending the association" do
277
- should "work using a block passed to many" do
276
+ it "should work using a block passed to many" do
278
277
  room = Room.new(:name => "Amazing Room")
279
278
  messages = room.messages = [
280
279
  Enter.new(:body => 'John entered room', :position => 3),
@@ -288,7 +287,7 @@ class ManyPolymorphicProxyTest < Test::Unit::TestCase
288
287
  room.messages.older.should == messages[3..5]
289
288
  end
290
289
 
291
- should "work using many's :extend option" do
290
+ it "should work using many's :extend option" do
292
291
 
293
292
  room = Room.new(:name => "Amazing Room")
294
293
  accounts = room.accounts = [