mongo_mapper 0.12.0 → 0.13.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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,15 +1,15 @@
1
- require 'test_helper'
1
+ require 'spec_helper'
2
2
 
3
- class TranslationTest < Test::Unit::TestCase
4
- should "translate add mongo_mapper translations" do
3
+ describe "Translation" do
4
+ it "should translate add mongo_mapper translations" do
5
5
  I18n.translate("mongo_mapper.errors.messages.taken").should == "has already been taken"
6
6
  end
7
7
 
8
- should "set i18n_scope" do
8
+ it "should set i18n_scope" do
9
9
  Doc().i18n_scope.should == :mongo_mapper
10
10
  end
11
11
 
12
- should "translate document attributes" do
12
+ it "should translate document attributes" do
13
13
  I18n.config.backend.store_translations(:en, :mongo_mapper => {:attributes => {:thing => {:foo => 'Bar'}}})
14
14
  doc = Doc('Thing') do
15
15
  key :foo, String
@@ -17,7 +17,7 @@ class TranslationTest < Test::Unit::TestCase
17
17
  doc.human_attribute_name(:foo).should == 'Bar'
18
18
  end
19
19
 
20
- should "translate embedded document attributes" do
20
+ it "should translate embedded document attributes" do
21
21
  I18n.config.backend.store_translations(:en, :mongo_mapper => {:attributes => {:thing => {:foo => 'Bar'}}})
22
22
  doc = EDoc('Thing') do
23
23
  key :foo, String
@@ -1,14 +1,14 @@
1
- require 'test_helper'
1
+ require 'spec_helper'
2
2
 
3
- class ValidationsTest < Test::Unit::TestCase
3
+ describe "Validations" do
4
4
  context "Validations" do
5
5
  context "on a Document" do
6
- setup do
6
+ before do
7
7
  @document = Doc('John')
8
8
  end
9
9
 
10
10
  context "Validating acceptance of" do
11
- should "work with validates_acceptance_of macro" do
11
+ it "should work with validates_acceptance_of macro" do
12
12
  @document.key :terms, String
13
13
  @document.validates_acceptance_of :terms
14
14
  doc = @document.new(:terms => '')
@@ -19,7 +19,7 @@ class ValidationsTest < Test::Unit::TestCase
19
19
  end
20
20
 
21
21
  context "validating confirmation of" do
22
- should "work with validates_confirmation_of macro" do
22
+ it "should work with validates_confirmation_of macro" do
23
23
  @document.key :password, String
24
24
  @document.validates_confirmation_of :password
25
25
 
@@ -27,15 +27,28 @@ class ValidationsTest < Test::Unit::TestCase
27
27
  doc = @document.new
28
28
  doc.password = 'foobar'
29
29
  doc.password_confirmation = 'foobar1'
30
- doc.should have_error_on(:password)
30
+ doc.should have_error_on(:password_confirmation).or(:password)
31
31
 
32
32
  doc.password_confirmation = 'foobar'
33
33
  doc.should_not have_error_on(:password)
34
34
  end
35
35
  end
36
36
 
37
+ context "validating uniqueness of" do
38
+ it "should work with :unique => true passed to ::key" do
39
+ @document.key :email, String, :unique => true
40
+
41
+ @document.create(:email => "cheald@gmail.com")
42
+ doc = @document.new :email => "cheald@gmail.com"
43
+ doc.should_not be_valid
44
+ doc.should have_error_on(:email)
45
+ doc.email = "cheald@mashable.com"
46
+ doc.should be_valid
47
+ end
48
+ end
49
+
37
50
  context "validating format of" do
38
- should "work with validates_format_of macro" do
51
+ it "should work with validates_format_of macro" do
39
52
  @document.key :name, String
40
53
  @document.validates_format_of :name, :with => /.+/
41
54
  doc = @document.new
@@ -44,7 +57,7 @@ class ValidationsTest < Test::Unit::TestCase
44
57
  doc.should_not have_error_on(:name)
45
58
  end
46
59
 
47
- should "work with :format shorcut key" do
60
+ it "should work with :format shorcut key" do
48
61
  @document.key :name, String, :format => /.+/
49
62
  doc = @document.new
50
63
  doc.should have_error_on(:name)
@@ -54,7 +67,7 @@ class ValidationsTest < Test::Unit::TestCase
54
67
  end
55
68
 
56
69
  context "validating length of" do
57
- should "work with validates_length_of macro" do
70
+ it "should work with validates_length_of macro" do
58
71
  @document.key :name, String
59
72
  @document.validates_length_of :name, :minimum => 5
60
73
  doc = @document.new
@@ -62,7 +75,7 @@ class ValidationsTest < Test::Unit::TestCase
62
75
  end
63
76
 
64
77
  context "with :length => integer shortcut" do
65
- should "set maximum of integer provided" do
78
+ it "should set maximum of integer provided" do
66
79
  @document.key :name, String, :length => 5
67
80
  doc = @document.new
68
81
  doc.name = '123456'
@@ -73,18 +86,18 @@ class ValidationsTest < Test::Unit::TestCase
73
86
  end
74
87
 
75
88
  context "with :length => range shortcut" do
76
- setup do
89
+ before do
77
90
  @document.key :name, String, :length => 5..7
78
91
  end
79
92
 
80
- should "set minimum of range min" do
93
+ it "should set minimum of range min" do
81
94
  doc = @document.new
82
95
  doc.should have_error_on(:name)
83
96
  doc.name = '123456'
84
97
  doc.should_not have_error_on(:name)
85
98
  end
86
99
 
87
- should "set maximum of range max" do
100
+ it "should set maximum of range max" do
88
101
  doc = @document.new
89
102
  doc.should have_error_on(:name)
90
103
  doc.name = '12345678'
@@ -95,7 +108,7 @@ class ValidationsTest < Test::Unit::TestCase
95
108
  end
96
109
 
97
110
  context "with :length => hash shortcut" do
98
- should "pass options through" do
111
+ it "should pass options through" do
99
112
  @document.key :name, String, :length => {:minimum => 2}
100
113
  doc = @document.new
101
114
  doc.should have_error_on(:name)
@@ -106,7 +119,7 @@ class ValidationsTest < Test::Unit::TestCase
106
119
  end # validates_length_of
107
120
 
108
121
  context "Validating numericality of" do
109
- should "work with validates_numericality_of macro" do
122
+ it "should work with validates_numericality_of macro" do
110
123
  @document.key :age, Integer
111
124
  @document.validates_numericality_of :age
112
125
  doc = @document.new
@@ -117,7 +130,7 @@ class ValidationsTest < Test::Unit::TestCase
117
130
  end
118
131
 
119
132
  context "with :numeric shortcut" do
120
- should "work with integer or float" do
133
+ it "should work with integer or float" do
121
134
  @document.key :weight, Float, :numeric => true
122
135
  doc = @document.new
123
136
  doc.weight = 'String'
@@ -130,7 +143,7 @@ class ValidationsTest < Test::Unit::TestCase
130
143
  end
131
144
 
132
145
  context "with :numeric shortcut on Integer key" do
133
- should "only work with integers" do
146
+ it "should only work with integers" do
134
147
  @document.key :age, Integer, :numeric => true
135
148
  doc = @document.new
136
149
  doc.age = 'String'
@@ -144,14 +157,14 @@ class ValidationsTest < Test::Unit::TestCase
144
157
  end # numericality of
145
158
 
146
159
  context "validating presence of" do
147
- should "work with validates_presence_of macro" do
160
+ it "should work with validates_presence_of macro" do
148
161
  @document.key :name, String
149
162
  @document.validates_presence_of :name
150
163
  doc = @document.new
151
164
  doc.should have_error_on(:name)
152
165
  end
153
166
 
154
- should "work with :required shortcut on key definition" do
167
+ it "should work with :required shortcut on key definition" do
155
168
  @document.key :name, String, :required => true
156
169
  doc = @document.new
157
170
  doc.should have_error_on(:name)
@@ -159,14 +172,14 @@ class ValidationsTest < Test::Unit::TestCase
159
172
  end
160
173
 
161
174
  context "validating exclusion of" do
162
- should "throw error if enumerator not provided" do
175
+ it "should throw error if enumerator not provided" do
163
176
  @document.key :action, String
164
177
  lambda {
165
178
  @document.validates_exclusion_of :action
166
179
  }.should raise_error(ArgumentError)
167
180
  end
168
181
 
169
- should "work with validates_exclusion_of macro" do
182
+ it "should work with validates_exclusion_of macro" do
170
183
  @document.key :action, String
171
184
  @document.validates_exclusion_of :action, :in => %w(kick run)
172
185
 
@@ -180,7 +193,7 @@ class ValidationsTest < Test::Unit::TestCase
180
193
  doc.should have_error_on(:action, 'is reserved')
181
194
  end
182
195
 
183
- should "work with :not_in shortcut on key definition" do
196
+ it "should work with :not_in shortcut on key definition" do
184
197
  @document.key :action, String, :not_in => %w(kick run)
185
198
 
186
199
  doc = @document.new
@@ -193,7 +206,7 @@ class ValidationsTest < Test::Unit::TestCase
193
206
  doc.should have_error_on(:action, 'is reserved')
194
207
  end
195
208
 
196
- should "not have error if allow nil is true and value is nil" do
209
+ it "should not have error if allow nil is true and value is nil" do
197
210
  @document.key :action, String
198
211
  @document.validates_exclusion_of :action, :in => %w(kick run), :allow_nil => true
199
212
 
@@ -201,7 +214,7 @@ class ValidationsTest < Test::Unit::TestCase
201
214
  doc.should_not have_error_on(:action)
202
215
  end
203
216
 
204
- should "not have error if allow blank is true and value is blank" do
217
+ it "should not have error if allow blank is true and value is blank" do
205
218
  @document.key :action, String
206
219
  @document.validates_exclusion_of :action, :in => %w(kick run), :allow_nil => true
207
220
 
@@ -211,14 +224,14 @@ class ValidationsTest < Test::Unit::TestCase
211
224
  end
212
225
 
213
226
  context "validating inclusion of" do
214
- should "throw error if enumerator not provided" do
227
+ it "should throw error if enumerator not provided" do
215
228
  @document.key :action, String
216
229
  lambda {
217
230
  @document.validates_inclusion_of :action
218
231
  }.should raise_error(ArgumentError)
219
232
  end
220
233
 
221
- should "work with validates_inclusion_of macro" do
234
+ it "should work with validates_inclusion_of macro" do
222
235
  @document.key :action, String
223
236
  @document.validates_inclusion_of :action, :in => %w(kick run)
224
237
 
@@ -232,7 +245,7 @@ class ValidationsTest < Test::Unit::TestCase
232
245
  doc.should_not have_error_on(:action)
233
246
  end
234
247
 
235
- should "work with :in shortcut on key definition" do
248
+ it "should work with :in shortcut on key definition" do
236
249
  @document.key :action, String, :in => %w(kick run)
237
250
 
238
251
  doc = @document.new
@@ -245,7 +258,7 @@ class ValidationsTest < Test::Unit::TestCase
245
258
  doc.should_not have_error_on(:action)
246
259
  end
247
260
 
248
- should "work with :required shortcut on Boolean type" do
261
+ it "should work with :required shortcut on Boolean type" do
249
262
  @document.key :flag, Boolean, :required => true
250
263
 
251
264
  doc = @document.new
@@ -258,7 +271,7 @@ class ValidationsTest < Test::Unit::TestCase
258
271
  doc.should_not have_error_on(:action)
259
272
  end
260
273
 
261
- should "not have error if allow nil is true and value is nil" do
274
+ it "should not have error if allow nil is true and value is nil" do
262
275
  @document.key :action, String
263
276
  @document.validates_inclusion_of :action, :in => %w(kick run), :allow_nil => true
264
277
 
@@ -266,7 +279,7 @@ class ValidationsTest < Test::Unit::TestCase
266
279
  doc.should_not have_error_on(:action)
267
280
  end
268
281
 
269
- should "not have error if allow blank is true and value is blank" do
282
+ it "should not have error if allow blank is true and value is blank" do
270
283
  @document.key :action, String
271
284
  @document.validates_inclusion_of :action, :in => %w(kick run), :allow_blank => true
272
285
 
@@ -278,12 +291,12 @@ class ValidationsTest < Test::Unit::TestCase
278
291
  end # End on a Document
279
292
 
280
293
  context "On an EmbeddedDocument" do
281
- setup do
294
+ before do
282
295
  @embedded_doc = EDoc()
283
296
  end
284
297
 
285
298
  context "Validating acceptance of" do
286
- should "work with validates_acceptance_of macro" do
299
+ it "should work with validates_acceptance_of macro" do
287
300
  @embedded_doc.key :terms, String
288
301
  @embedded_doc.validates_acceptance_of :terms
289
302
  doc = @embedded_doc.new(:terms => '')
@@ -294,20 +307,20 @@ class ValidationsTest < Test::Unit::TestCase
294
307
  end
295
308
 
296
309
  context "validating confirmation of" do
297
- should "work with validates_confirmation_of macro" do
310
+ it "should work with validates_confirmation_of macro" do
298
311
  @embedded_doc.key :password, String
299
312
  @embedded_doc.validates_confirmation_of :password
300
313
  doc = @embedded_doc.new
301
314
  doc.password = 'foobar'
302
315
  doc.password_confirmation = 'foobar1'
303
- doc.should have_error_on(:password)
316
+ doc.should have_error_on(:password).or(:password_confirmation)
304
317
  doc.password_confirmation = 'foobar'
305
318
  doc.should_not have_error_on(:password)
306
319
  end
307
320
  end
308
321
 
309
322
  context "validating format of" do
310
- should "work with validates_format_of macro" do
323
+ it "should work with validates_format_of macro" do
311
324
  @embedded_doc.key :name, String
312
325
  @embedded_doc.validates_format_of :name, :with => /.+/
313
326
  doc = @embedded_doc.new
@@ -316,7 +329,7 @@ class ValidationsTest < Test::Unit::TestCase
316
329
  doc.should_not have_error_on(:name)
317
330
  end
318
331
 
319
- should "work with :format shorcut key" do
332
+ it "should work with :format shorcut key" do
320
333
  @embedded_doc.key :name, String, :format => /.+/
321
334
  doc = @embedded_doc.new
322
335
  doc.should have_error_on(:name)
@@ -326,7 +339,7 @@ class ValidationsTest < Test::Unit::TestCase
326
339
  end
327
340
 
328
341
  context "validating length of" do
329
- should "work with validates_length_of macro" do
342
+ it "should work with validates_length_of macro" do
330
343
  @embedded_doc.key :name, String
331
344
  @embedded_doc.validates_length_of :name, :minimum => 5
332
345
  doc = @embedded_doc.new
@@ -334,7 +347,7 @@ class ValidationsTest < Test::Unit::TestCase
334
347
  end
335
348
 
336
349
  context "with :length => integer shortcut" do
337
- should "set maximum of integer provided" do
350
+ it "should set maximum of integer provided" do
338
351
  @embedded_doc.key :name, String, :length => 5
339
352
  doc = @embedded_doc.new
340
353
  doc.name = '123456'
@@ -345,18 +358,18 @@ class ValidationsTest < Test::Unit::TestCase
345
358
  end
346
359
 
347
360
  context "with :length => range shortcut" do
348
- setup do
361
+ before do
349
362
  @embedded_doc.key :name, String, :length => 5..7
350
363
  end
351
364
 
352
- should "set minimum of range min" do
365
+ it "should set minimum of range min" do
353
366
  doc = @embedded_doc.new
354
367
  doc.should have_error_on(:name)
355
368
  doc.name = '123456'
356
369
  doc.should_not have_error_on(:name)
357
370
  end
358
371
 
359
- should "set maximum of range max" do
372
+ it "should set maximum of range max" do
360
373
  doc = @embedded_doc.new
361
374
  doc.should have_error_on(:name)
362
375
  doc.name = '12345678'
@@ -367,7 +380,7 @@ class ValidationsTest < Test::Unit::TestCase
367
380
  end
368
381
 
369
382
  context "with :length => hash shortcut" do
370
- should "pass options through" do
383
+ it "should pass options through" do
371
384
  @embedded_doc.key :name, String, :length => {:minimum => 2}
372
385
  doc = @embedded_doc.new
373
386
  doc.should have_error_on(:name)
@@ -378,7 +391,7 @@ class ValidationsTest < Test::Unit::TestCase
378
391
  end # validates_length_of
379
392
 
380
393
  context "Validating numericality of" do
381
- should "work with validates_numericality_of macro" do
394
+ it "should work with validates_numericality_of macro" do
382
395
  @embedded_doc.key :age, Integer
383
396
  @embedded_doc.validates_numericality_of :age
384
397
  doc = @embedded_doc.new
@@ -389,7 +402,7 @@ class ValidationsTest < Test::Unit::TestCase
389
402
  end
390
403
 
391
404
  context "with :numeric shortcut" do
392
- should "work with integer or float" do
405
+ it "should work with integer or float" do
393
406
  @embedded_doc.key :weight, Float, :numeric => true
394
407
  doc = @embedded_doc.new
395
408
  doc.weight = 'String'
@@ -402,7 +415,7 @@ class ValidationsTest < Test::Unit::TestCase
402
415
  end
403
416
 
404
417
  context "with :numeric shortcut on Integer key" do
405
- should "only work with integers" do
418
+ it "should only work with integers" do
406
419
  @embedded_doc.key :age, Integer, :numeric => true
407
420
  doc = @embedded_doc.new
408
421
  doc.age = 'String'
@@ -416,14 +429,14 @@ class ValidationsTest < Test::Unit::TestCase
416
429
  end # numericality of
417
430
 
418
431
  context "validating presence of" do
419
- should "work with validates_presence_of macro" do
432
+ it "should work with validates_presence_of macro" do
420
433
  @embedded_doc.key :name, String
421
434
  @embedded_doc.validates_presence_of :name
422
435
  doc = @embedded_doc.new
423
436
  doc.should have_error_on(:name)
424
437
  end
425
438
 
426
- should "work with :required shortcut on key definition" do
439
+ it "should work with :required shortcut on key definition" do
427
440
  @embedded_doc.key :name, String, :required => true
428
441
  doc = @embedded_doc.new
429
442
  doc.should have_error_on(:name)
@@ -431,14 +444,14 @@ class ValidationsTest < Test::Unit::TestCase
431
444
  end
432
445
 
433
446
  context "validating exclusion of" do
434
- should "throw error if enumerator not provided" do
447
+ it "should throw error if enumerator not provided" do
435
448
  @embedded_doc.key :action, String
436
449
  lambda {
437
450
  @embedded_doc.validates_exclusion_of :action
438
451
  }.should raise_error(ArgumentError)
439
452
  end
440
453
 
441
- should "work with validates_exclusion_of macro" do
454
+ it "should work with validates_exclusion_of macro" do
442
455
  @embedded_doc.key :action, String
443
456
  @embedded_doc.validates_exclusion_of :action, :in => %w(kick run)
444
457
 
@@ -452,7 +465,7 @@ class ValidationsTest < Test::Unit::TestCase
452
465
  doc.should have_error_on(:action, 'is reserved')
453
466
  end
454
467
 
455
- should "work with :not_in shortcut on key definition" do
468
+ it "should work with :not_in shortcut on key definition" do
456
469
  @embedded_doc.key :action, String, :not_in => %w(kick run)
457
470
 
458
471
  doc = @embedded_doc.new
@@ -465,7 +478,7 @@ class ValidationsTest < Test::Unit::TestCase
465
478
  doc.should have_error_on(:action, 'is reserved')
466
479
  end
467
480
 
468
- should "not have error if allow nil is true and value is nil" do
481
+ it "should not have error if allow nil is true and value is nil" do
469
482
  @embedded_doc.key :action, String
470
483
  @embedded_doc.validates_exclusion_of :action, :in => %w(kick run), :allow_nil => true
471
484
 
@@ -473,7 +486,7 @@ class ValidationsTest < Test::Unit::TestCase
473
486
  doc.should_not have_error_on(:action)
474
487
  end
475
488
 
476
- should "not have error if allow blank is true and value is blank" do
489
+ it "should not have error if allow blank is true and value is blank" do
477
490
  @embedded_doc.key :action, String
478
491
  @embedded_doc.validates_exclusion_of :action, :in => %w(kick run), :allow_nil => true
479
492
 
@@ -483,14 +496,14 @@ class ValidationsTest < Test::Unit::TestCase
483
496
  end
484
497
 
485
498
  context "validating inclusion of" do
486
- should "throw error if enumerator not provided" do
499
+ it "should throw error if enumerator not provided" do
487
500
  @embedded_doc.key :action, String
488
501
  lambda {
489
502
  @embedded_doc.validates_inclusion_of :action
490
503
  }.should raise_error(ArgumentError)
491
504
  end
492
505
 
493
- should "work with validates_inclusion_of macro" do
506
+ it "should work with validates_inclusion_of macro" do
494
507
  @embedded_doc.key :action, String
495
508
  @embedded_doc.validates_inclusion_of :action, :in => %w(kick run)
496
509
 
@@ -504,7 +517,7 @@ class ValidationsTest < Test::Unit::TestCase
504
517
  doc.should_not have_error_on(:action)
505
518
  end
506
519
 
507
- should "work with :in shortcut on key definition" do
520
+ it "should work with :in shortcut on key definition" do
508
521
  @embedded_doc.key :action, String, :in => %w(kick run)
509
522
 
510
523
  doc = @embedded_doc.new
@@ -517,7 +530,7 @@ class ValidationsTest < Test::Unit::TestCase
517
530
  doc.should_not have_error_on(:action)
518
531
  end
519
532
 
520
- should "not have error if allow nil is true and value is nil" do
533
+ it "should not have error if allow nil is true and value is nil" do
521
534
  @embedded_doc.key :action, String
522
535
  @embedded_doc.validates_inclusion_of :action, :in => %w(kick run), :allow_nil => true
523
536
 
@@ -525,7 +538,7 @@ class ValidationsTest < Test::Unit::TestCase
525
538
  doc.should_not have_error_on(:action)
526
539
  end
527
540
 
528
- should "not have error if allow blank is true and value is blank" do
541
+ it "should not have error if allow blank is true and value is blank" do
529
542
  @embedded_doc.key :action, String
530
543
  @embedded_doc.validates_inclusion_of :action, :in => %w(kick run), :allow_blank => true
531
544
 
@@ -539,7 +552,7 @@ class ValidationsTest < Test::Unit::TestCase
539
552
  end # Validations
540
553
 
541
554
  context "Adding validation errors" do
542
- setup do
555
+ before do
543
556
  @document = Doc do
544
557
  key :action, String
545
558
  def action_present
@@ -548,7 +561,7 @@ class ValidationsTest < Test::Unit::TestCase
548
561
  end
549
562
  end
550
563
 
551
- should "work with validate callback" do
564
+ it "should work with validate callback" do
552
565
  @document.validate :action_present
553
566
 
554
567
  doc = @document.new