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,29 +1,29 @@
1
- require 'test_helper'
2
- require 'models'
1
+ require 'spec_helper'
2
+ require 'support/models'
3
3
 
4
- class OneAsProxyTest < Test::Unit::TestCase
5
- def setup
4
+ describe "OneAsProxy" do
5
+ before do
6
6
  @post_class = Doc('Post')
7
7
  @author_class = Doc('Author')
8
8
  end
9
9
 
10
- should "default to nil" do
10
+ it "should default to nil" do
11
11
  @post_class.one :author, :as => :authorable, :class => @author_class
12
12
  @post_class.new.author.nil?.should be_true
13
13
  end
14
14
 
15
- should "return nil instead of a proxy" do
15
+ it "should return nil instead of a proxy" do
16
16
  @post_class.one :author, :as => :authorable, :class => @author_class
17
17
  nil.should === @post_class.new.author
18
18
  end
19
19
 
20
- should "not define any keys" do
20
+ it "should not define any keys" do
21
21
  count = @post_class.keys.length
22
22
  @post_class.one :author, :class => @author_class
23
23
  @post_class.keys.length.should == count
24
24
  end
25
25
 
26
- should "allow assignment of associated document using a hash" do
26
+ it "should allow assignment of associated document using a hash" do
27
27
  @post_class.one :author, :as => :authorable, :class => @author_class
28
28
 
29
29
  post = @post_class.new('author' => { 'name' => 'Frank' })
@@ -35,7 +35,7 @@ class OneAsProxyTest < Test::Unit::TestCase
35
35
  post.author.name.should == 'Frank'
36
36
  end
37
37
 
38
- should "only return a document with the correct type" do
38
+ it "should only return a document with the correct type" do
39
39
  @post_class.one :author, :as => :authorable, :class => @author_class
40
40
  post = @post_class.create
41
41
 
@@ -48,13 +48,13 @@ class OneAsProxyTest < Test::Unit::TestCase
48
48
 
49
49
  context "replacing the association" do
50
50
  context "with an object of the class" do
51
- setup do
51
+ before do
52
52
  @post_class.one :author, :as => :authorable, :class => @author_class
53
53
  @post = @post_class.new
54
54
  @author = @author_class.new(:name => 'Frank')
55
55
  end
56
56
 
57
- should "work" do
57
+ it "should work" do
58
58
  @post.author = @author
59
59
  @post.reload
60
60
 
@@ -66,7 +66,7 @@ class OneAsProxyTest < Test::Unit::TestCase
66
66
  @post.author.should == new_author
67
67
  end
68
68
 
69
- should "generate a new proxy instead of modifying the existing one" do
69
+ it "should generate a new proxy instead of modifying the existing one" do
70
70
  @post.author = @author
71
71
  @post.reload
72
72
 
@@ -82,24 +82,24 @@ class OneAsProxyTest < Test::Unit::TestCase
82
82
  original_author.name.should == 'Frank'
83
83
  end
84
84
 
85
- should "assign foreign key" do
85
+ it "should assign foreign key" do
86
86
  @post.author = @author
87
87
  @post.author.authorable_id.should == @post.id
88
88
  end
89
89
 
90
- should "assign _type" do
90
+ it "should assign _type" do
91
91
  @post.author = @author
92
92
  @post.author.authorable_type.should == "Post"
93
93
  end
94
94
  end
95
95
 
96
96
  context "with a Hash" do
97
- setup do
97
+ before do
98
98
  @post_class.one :author, :as => :authorable, :class => @author_class
99
99
  @post = @post_class.new
100
100
  end
101
101
 
102
- should "convert to an object of the class and work" do
102
+ it "should convert to an object of the class and work" do
103
103
  @post.author = {'name' => 'Frank'}
104
104
  @post.reload
105
105
 
@@ -110,12 +110,12 @@ class OneAsProxyTest < Test::Unit::TestCase
110
110
  @post.author.name.should == 'Emily'
111
111
  end
112
112
 
113
- should "assign foreign key" do
113
+ it "should assign foreign key" do
114
114
  @post.author = {'name' => 'Frank'}
115
115
  @post.author.authorable_id.should == @post.id
116
116
  end
117
117
 
118
- should "assign _type" do
118
+ it "should assign _type" do
119
119
  @post.author = {'name' => 'Frank'}
120
120
  @post.author.authorable_type.should == "Post"
121
121
  end
@@ -123,7 +123,7 @@ class OneAsProxyTest < Test::Unit::TestCase
123
123
 
124
124
  context "with :dependent" do
125
125
  context "=> delete" do
126
- setup do
126
+ before do
127
127
  @post_class.one :author, :as => :authorable, :class => @author_class, :dependent => :delete
128
128
 
129
129
  @post = @post_class.create
@@ -131,24 +131,24 @@ class OneAsProxyTest < Test::Unit::TestCase
131
131
  @post.author = @author
132
132
  end
133
133
 
134
- should "call delete on the existing document" do
135
- @author_class.any_instance.expects(:delete).once
134
+ it "should call delete on the existing document" do
135
+ @author_class.any_instance.should_receive(:delete).once
136
136
  @post.author = @author_class.new
137
137
  end
138
138
 
139
- should "remove the existing document from the database" do
139
+ it "should remove the existing document from the database" do
140
140
  @post.author = @author_class.new
141
141
  lambda { @author.reload }.should raise_error(MongoMapper::DocumentNotFound)
142
142
  end
143
143
 
144
- should "do nothing if it's the same document" do
145
- @author_class.any_instance.expects(:delete).never
144
+ it "should do nothing if it's the same document" do
145
+ @author_class.any_instance.should_receive(:delete).never
146
146
  @post.author = @author
147
147
  end
148
148
  end
149
149
 
150
150
  context "=> destory" do
151
- setup do
151
+ before do
152
152
  @post_class.one :author, :as => :authorable, :class => @author_class, :dependent => :destroy
153
153
 
154
154
  @post = @post_class.create
@@ -156,24 +156,24 @@ class OneAsProxyTest < Test::Unit::TestCase
156
156
  @post.author = @author
157
157
  end
158
158
 
159
- should "call destroy the existing document" do
160
- @author_class.any_instance.expects(:destroy).once
159
+ it "should call destroy the existing document" do
160
+ @author_class.any_instance.should_receive(:destroy).once
161
161
  @post.author = @author_class.new
162
162
  end
163
163
 
164
- should "remove the existing document from the database" do
164
+ it "should remove the existing document from the database" do
165
165
  @post.author = @author_class.new
166
166
  lambda { @author.reload }.should raise_error(MongoMapper::DocumentNotFound)
167
167
  end
168
168
 
169
- should "do nothing if it's the same document" do
170
- @author_class.any_instance.expects(:destroy).never
169
+ it "should do nothing if it's the same document" do
170
+ @author_class.any_instance.should_receive(:destroy).never
171
171
  @post.author = @author
172
172
  end
173
173
  end
174
174
 
175
175
  context "=> nullify" do
176
- setup do
176
+ before do
177
177
  @post_class.one :author, :as => :authorable, :class => @author_class, :dependent => :nullify
178
178
 
179
179
  @post = @post_class.create
@@ -181,7 +181,7 @@ class OneAsProxyTest < Test::Unit::TestCase
181
181
  @post.author = @author
182
182
  end
183
183
 
184
- should "nullify the existing document" do
184
+ it "should nullify the existing document" do
185
185
  @author.reload
186
186
  @author.authorable_id.should == @post.id
187
187
 
@@ -191,13 +191,13 @@ class OneAsProxyTest < Test::Unit::TestCase
191
191
  @author.authorable_id.should be_nil
192
192
  end
193
193
 
194
- should "work when it's the same document" do
194
+ it "should work when it's the same document" do
195
195
  old_author = @post.author
196
196
  @post.author = @author
197
197
  old_author.should == @post.author
198
198
  end
199
199
 
200
- should "nullify _type" do
200
+ it "should nullify _type" do
201
201
  @post.author = @author_class.new
202
202
  @author.reload
203
203
  @author.authorable_type.should be_nil
@@ -205,7 +205,7 @@ class OneAsProxyTest < Test::Unit::TestCase
205
205
  end
206
206
 
207
207
  context "unspecified" do
208
- setup do
208
+ before do
209
209
  @post_class.one :author, :as => :authorable, :class => @author_class
210
210
 
211
211
  @post = @post_class.create
@@ -213,7 +213,7 @@ class OneAsProxyTest < Test::Unit::TestCase
213
213
  @post.author = @author
214
214
  end
215
215
 
216
- should "nullify the existing document" do
216
+ it "should nullify the existing document" do
217
217
  @author.reload
218
218
  @author.authorable_id.should == @post.id
219
219
 
@@ -223,7 +223,7 @@ class OneAsProxyTest < Test::Unit::TestCase
223
223
  @author.authorable_id.should be_nil
224
224
  end
225
225
 
226
- should "nullify _type" do
226
+ it "should nullify _type" do
227
227
  @post.author = @author_class.new
228
228
  @author.reload
229
229
  @author.authorable_type.should be_nil
@@ -232,7 +232,7 @@ class OneAsProxyTest < Test::Unit::TestCase
232
232
  end
233
233
 
234
234
  context "with nil" do
235
- setup do
235
+ before do
236
236
  @post_class.one :author, :as => :authorable, :class => @author_class
237
237
 
238
238
  @post = @post_class.new
@@ -240,18 +240,18 @@ class OneAsProxyTest < Test::Unit::TestCase
240
240
  @post.author = @author
241
241
  end
242
242
 
243
- should "nullify the existing document" do
243
+ it "should nullify the existing document" do
244
244
  @post.author = nil
245
245
  @author.reload
246
246
  @author.authorable_id.should be_nil
247
247
  end
248
248
 
249
- should "set the target to nil" do
249
+ it "should set the target to nil" do
250
250
  @post.author = nil
251
251
  @post.author.should == nil
252
252
  end
253
253
 
254
- should "nullify _type" do
254
+ it "should nullify _type" do
255
255
  @post.author = nil
256
256
  @author.reload
257
257
  @author.authorable_type.should be_nil
@@ -259,7 +259,7 @@ class OneAsProxyTest < Test::Unit::TestCase
259
259
  end
260
260
  end
261
261
 
262
- should "have boolean method for testing presence" do
262
+ it "should have boolean method for testing presence" do
263
263
  @post_class.one :author, :as => :authorable, :class => @author_class
264
264
 
265
265
  post = @post_class.new
@@ -269,7 +269,7 @@ class OneAsProxyTest < Test::Unit::TestCase
269
269
  post.author?.should be_true
270
270
  end
271
271
 
272
- should "work with criteria" do
272
+ it "should work with criteria" do
273
273
  @post_class.one :primary_author, :as => :authorable, :class => @author_class, :primary => true
274
274
  @post_class.one :author, :as => :authorable, :class => @author_class, :primary => false
275
275
 
@@ -281,7 +281,7 @@ class OneAsProxyTest < Test::Unit::TestCase
281
281
  post.primary_author.should == primary
282
282
  end
283
283
 
284
- should "unset the association" do
284
+ it "should unset the association" do
285
285
  @post_class.one :author, :as => :authorable, :class => @author_class
286
286
  post = @post_class.create
287
287
  author = @author_class.create
@@ -293,7 +293,7 @@ class OneAsProxyTest < Test::Unit::TestCase
293
293
 
294
294
  context "destroying parent with :dependent" do
295
295
  context "=> destroy" do
296
- setup do
296
+ before do
297
297
  @post_class.one :author, :as => :authorable, :class => @author_class, :dependent => :destroy
298
298
 
299
299
  @post = @post_class.create
@@ -301,12 +301,12 @@ class OneAsProxyTest < Test::Unit::TestCase
301
301
  @post.author = @author
302
302
  end
303
303
 
304
- should "should call destroy on the associated documents" do
305
- @author_class.any_instance.expects(:destroy).once
304
+ it "should should call destroy on the associated documents" do
305
+ @author_class.any_instance.should_receive(:destroy).once
306
306
  @post.destroy
307
307
  end
308
308
 
309
- should "should remove the associated documents" do
309
+ it "should should remove the associated documents" do
310
310
  @author_class.count.should == 1
311
311
  @post.destroy
312
312
  @post.author.should == nil
@@ -315,7 +315,7 @@ class OneAsProxyTest < Test::Unit::TestCase
315
315
  end
316
316
 
317
317
  context "=> delete" do
318
- setup do
318
+ before do
319
319
  @post_class.one :author, :as => :authorable, :class => @author_class, :dependent => :delete
320
320
 
321
321
  @post = @post_class.create
@@ -323,12 +323,12 @@ class OneAsProxyTest < Test::Unit::TestCase
323
323
  @post.author = @author
324
324
  end
325
325
 
326
- should "should call delete the associated documents" do
327
- @author_class.any_instance.expects(:delete).once
326
+ it "should should call delete the associated documents" do
327
+ @author_class.any_instance.should_receive(:delete).once
328
328
  @post.destroy
329
329
  end
330
330
 
331
- should "remove the associated documents" do
331
+ it "should remove the associated documents" do
332
332
  @author_class.count.should == 1
333
333
  @post.destroy
334
334
  @post.author.should == nil
@@ -337,7 +337,7 @@ class OneAsProxyTest < Test::Unit::TestCase
337
337
  end
338
338
 
339
339
  context "=> nullify" do
340
- setup do
340
+ before do
341
341
  @post_class.one :author, :as => :authorable, :class => @author_class, :dependent => :nullify
342
342
 
343
343
  @post = @post_class.create
@@ -345,7 +345,7 @@ class OneAsProxyTest < Test::Unit::TestCase
345
345
  @post.author = @author
346
346
  end
347
347
 
348
- should "should nullify the relationship but not destroy the associated document" do
348
+ it "should should nullify the relationship but not destroy the associated document" do
349
349
  @author_class.count.should == 1
350
350
  @post.destroy
351
351
  @post.author.should == nil
@@ -355,14 +355,14 @@ class OneAsProxyTest < Test::Unit::TestCase
355
355
  @author.authorable_id.should == nil
356
356
  end
357
357
 
358
- should "nullify _type" do
358
+ it "should nullify _type" do
359
359
  @post.destroy
360
360
  @author.authorable_type.should be_nil
361
361
  end
362
362
  end
363
363
 
364
364
  context "unspecified" do
365
- setup do
365
+ before do
366
366
  @post_class.one :author, :as => :authorable, :class => @author_class
367
367
 
368
368
  @post = @post_class.create
@@ -370,7 +370,7 @@ class OneAsProxyTest < Test::Unit::TestCase
370
370
  @post.author = @author
371
371
  end
372
372
 
373
- should "should nullify the relationship but not destroy the associated document" do
373
+ it "should should nullify the relationship but not destroy the associated document" do
374
374
  @author_class.count.should == 1
375
375
  @post.destroy
376
376
  @post.author.should == nil
@@ -380,7 +380,7 @@ class OneAsProxyTest < Test::Unit::TestCase
380
380
  @author.authorable_id.should == nil
381
381
  end
382
382
 
383
- should "nullify _type" do
383
+ it "should nullify _type" do
384
384
  @post.destroy
385
385
  @author.authorable_type.should be_nil
386
386
  end
@@ -388,12 +388,12 @@ class OneAsProxyTest < Test::Unit::TestCase
388
388
  end
389
389
 
390
390
  context "#build" do
391
- setup do
391
+ before do
392
392
  @post_class.one :author, :as => :authorable, :class => @author_class
393
393
  @post = @post_class.create
394
394
  end
395
395
 
396
- should "be able to build with attributes" do
396
+ it "should be able to build with attributes" do
397
397
  author = @post.build_author(:name => 'John')
398
398
  @post.author.should be_instance_of(@author_class)
399
399
  @post.author.should be_new
@@ -401,24 +401,24 @@ class OneAsProxyTest < Test::Unit::TestCase
401
401
  @post.author.should == author
402
402
  end
403
403
 
404
- should "assign foreign key" do
404
+ it "should assign foreign key" do
405
405
  @post.build_author
406
406
  @post.author.authorable_id.should == @post.id
407
407
  end
408
408
 
409
- should "assign _type" do
409
+ it "should assign _type" do
410
410
  @post.build_author
411
411
  @post.author.authorable_type.should == 'Post'
412
412
  end
413
413
  end
414
414
 
415
415
  context "#create" do
416
- setup do
416
+ before do
417
417
  @post_class.one :author, :as => :authorable, :class => @author_class
418
418
  @post = @post_class.create
419
419
  end
420
420
 
421
- should "be able to create" do
421
+ it "should be able to create" do
422
422
  author = @post.create_author(:name => 'John')
423
423
  @post.author.should be_instance_of(@author_class)
424
424
  @post.author.should_not be_new
@@ -426,31 +426,29 @@ class OneAsProxyTest < Test::Unit::TestCase
426
426
  @post.author.should == author
427
427
  end
428
428
 
429
- should "assign foreign key" do
429
+ it "should assign foreign key" do
430
430
  @post.create_author
431
431
  @post.author.authorable_id.should == @post.id
432
432
  end
433
433
 
434
- should "assign _type" do
434
+ it "should assign _type" do
435
435
  @post.create_author
436
436
  @post.author.authorable_type.should == 'Post'
437
437
  end
438
438
  end
439
439
 
440
440
  context "#create!" do
441
- setup do
441
+ before do
442
442
  @author_class.key :name, String, :required => true
443
443
  @post_class.one :author, :as => :authorable, :class => @author_class
444
444
  @post = @post_class.create
445
445
  end
446
446
 
447
- should "raise exception if invalid" do
448
- assert_raises(MongoMapper::DocumentNotValid) do
449
- @post.create_author!
450
- end
447
+ it "should raise exception if invalid" do
448
+ expect { @post.create_author! }.to raise_error(MongoMapper::DocumentNotValid)
451
449
  end
452
450
 
453
- should "work if valid" do
451
+ it "should work if valid" do
454
452
  author = @post.create_author!(:name => 'John')
455
453
  @post.author.should be_instance_of(@author_class)
456
454
  @post.author.should_not be_new
@@ -458,31 +456,31 @@ class OneAsProxyTest < Test::Unit::TestCase
458
456
  @post.author.should == author
459
457
  end
460
458
 
461
- should "assign foreign key if valid" do
459
+ it "should assign foreign key if valid" do
462
460
  @post.create_author!(:name => 'John')
463
461
  @post.author.authorable_id.should == @post.id
464
462
  end
465
463
 
466
- should "assign _type if valid" do
464
+ it "should assign _type if valid" do
467
465
  @post.create_author!(:name => 'John')
468
466
  @post.author.authorable_type.should == 'Post'
469
467
  end
470
468
  end
471
469
 
472
470
  context "namespaced foreign keys" do
473
- setup do
471
+ before do
474
472
  News::Paper.one :article, :as => 'articleable', :class_name => 'News::Article'
475
473
  News::Article.belongs_to :articleable, :polymorphic => true
476
474
 
477
475
  @paper = News::Paper.create
478
476
  end
479
477
 
480
- should "work" do
478
+ it "should work" do
481
479
  @paper.create_article
482
480
  @paper.article.class.should == News::Article
483
481
  end
484
482
 
485
- should "properly infer the foreign key" do
483
+ it "should properly infer the foreign key" do
486
484
  article = @paper.create_article
487
485
  article.should respond_to(:articleable_id)
488
486
  article.articleable_id.should == @paper.id