mongo_mapper 0.8.6 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/UPGRADES +10 -0
  2. data/bin/mmconsole +0 -1
  3. data/examples/identity_map/automatic.rb +1 -7
  4. data/examples/plugins.rb +9 -9
  5. data/examples/safe.rb +43 -0
  6. data/lib/mongo_mapper.rb +46 -33
  7. data/lib/mongo_mapper/document.rb +33 -32
  8. data/lib/mongo_mapper/embedded_document.rb +22 -22
  9. data/lib/mongo_mapper/locale/en.yml +5 -0
  10. data/lib/mongo_mapper/middleware/identity_map.rb +16 -0
  11. data/lib/mongo_mapper/plugins.rb +16 -3
  12. data/lib/mongo_mapper/plugins/accessible.rb +2 -0
  13. data/lib/mongo_mapper/plugins/active_model.rb +18 -0
  14. data/lib/mongo_mapper/plugins/associations.rb +37 -42
  15. data/lib/mongo_mapper/plugins/associations/base.rb +14 -50
  16. data/lib/mongo_mapper/plugins/associations/belongs_to_association.rb +58 -0
  17. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +6 -1
  18. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +30 -2
  19. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +4 -0
  20. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +12 -6
  21. data/lib/mongo_mapper/plugins/associations/many_association.rb +67 -0
  22. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +5 -5
  23. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +1 -1
  24. data/lib/mongo_mapper/plugins/associations/one_association.rb +20 -0
  25. data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +5 -0
  26. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +7 -7
  27. data/lib/mongo_mapper/plugins/associations/proxy.rb +2 -2
  28. data/lib/mongo_mapper/plugins/caching.rb +3 -1
  29. data/lib/mongo_mapper/plugins/callbacks.rb +12 -221
  30. data/lib/mongo_mapper/plugins/clone.rb +3 -1
  31. data/lib/mongo_mapper/plugins/dirty.rb +38 -91
  32. data/lib/mongo_mapper/plugins/document.rb +4 -2
  33. data/lib/mongo_mapper/plugins/dynamic_querying.rb +2 -0
  34. data/lib/mongo_mapper/plugins/embedded_callbacks.rb +43 -0
  35. data/lib/mongo_mapper/plugins/embedded_document.rb +16 -9
  36. data/lib/mongo_mapper/plugins/equality.rb +2 -0
  37. data/lib/mongo_mapper/plugins/identity_map.rb +4 -2
  38. data/lib/mongo_mapper/plugins/indexes.rb +2 -0
  39. data/lib/mongo_mapper/plugins/inspect.rb +3 -1
  40. data/lib/mongo_mapper/plugins/keys.rb +28 -22
  41. data/lib/mongo_mapper/plugins/keys/key.rb +12 -6
  42. data/lib/mongo_mapper/plugins/logger.rb +2 -0
  43. data/lib/mongo_mapper/plugins/modifiers.rb +3 -1
  44. data/lib/mongo_mapper/plugins/pagination.rb +2 -0
  45. data/lib/mongo_mapper/plugins/persistence.rb +2 -0
  46. data/lib/mongo_mapper/plugins/protected.rb +2 -0
  47. data/lib/mongo_mapper/plugins/querying.rb +5 -4
  48. data/lib/mongo_mapper/plugins/rails.rb +3 -5
  49. data/lib/mongo_mapper/plugins/safe.rb +2 -0
  50. data/lib/mongo_mapper/plugins/sci.rb +2 -0
  51. data/lib/mongo_mapper/plugins/scopes.rb +2 -0
  52. data/lib/mongo_mapper/plugins/serialization.rb +67 -46
  53. data/lib/mongo_mapper/plugins/timestamps.rb +3 -1
  54. data/lib/mongo_mapper/plugins/userstamps.rb +2 -0
  55. data/lib/mongo_mapper/plugins/validations.rb +40 -24
  56. data/lib/mongo_mapper/railtie.rb +49 -0
  57. data/lib/mongo_mapper/railtie/database.rake +60 -0
  58. data/lib/mongo_mapper/support/descendant_appends.rb +11 -11
  59. data/lib/mongo_mapper/translation.rb +10 -0
  60. data/lib/mongo_mapper/version.rb +1 -1
  61. data/lib/rails/generators/mongo_mapper/config/config_generator.rb +24 -0
  62. data/lib/rails/generators/mongo_mapper/config/templates/mongo.yml +18 -0
  63. data/lib/rails/generators/mongo_mapper/model/model_generator.rb +23 -0
  64. data/lib/rails/generators/mongo_mapper/model/templates/model.rb +11 -0
  65. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +1 -0
  66. data/test/functional/associations/test_belongs_to_proxy.rb +131 -1
  67. data/test/functional/associations/test_in_array_proxy.rb +30 -0
  68. data/test/functional/associations/test_many_documents_proxy.rb +30 -2
  69. data/test/functional/associations/test_many_embedded_proxy.rb +33 -0
  70. data/test/functional/associations/test_many_polymorphic_proxy.rb +1 -0
  71. data/test/functional/associations/test_one_embedded_proxy.rb +21 -2
  72. data/test/functional/associations/test_one_proxy.rb +49 -9
  73. data/test/functional/test_associations.rb +2 -0
  74. data/test/functional/test_caching.rb +3 -2
  75. data/test/functional/test_callbacks.rb +25 -18
  76. data/test/functional/test_dirty.rb +123 -1
  77. data/test/functional/test_document.rb +26 -2
  78. data/test/functional/test_embedded_document.rb +68 -2
  79. data/test/functional/test_identity_map.rb +3 -4
  80. data/test/functional/test_querying.rb +11 -0
  81. data/test/functional/test_userstamps.rb +2 -2
  82. data/test/functional/test_validations.rb +31 -29
  83. data/test/models.rb +10 -0
  84. data/test/test_active_model_lint.rb +1 -1
  85. data/test/test_helper.rb +9 -10
  86. data/test/unit/associations/test_base.rb +24 -100
  87. data/test/unit/associations/test_belongs_to_association.rb +29 -0
  88. data/test/unit/associations/test_many_association.rb +63 -0
  89. data/test/unit/associations/test_one_association.rb +18 -0
  90. data/test/unit/serializers/test_json_serializer.rb +0 -1
  91. data/test/unit/test_descendant_appends.rb +8 -16
  92. data/test/unit/test_document.rb +4 -9
  93. data/test/unit/test_dynamic_finder.rb +1 -1
  94. data/test/unit/test_embedded_document.rb +51 -18
  95. data/test/unit/test_identity_map_middleware.rb +34 -0
  96. data/test/unit/test_inspect.rb +22 -0
  97. data/test/unit/test_key.rb +21 -1
  98. data/test/unit/test_keys.rb +0 -2
  99. data/test/unit/test_plugins.rb +106 -20
  100. data/test/unit/test_rails.rb +8 -8
  101. data/test/unit/test_serialization.rb +116 -1
  102. data/test/unit/test_translation.rb +27 -0
  103. data/test/unit/test_validations.rb +66 -81
  104. metadata +103 -43
  105. data/examples/identity_map/middleware.rb +0 -14
  106. data/lib/mongo_mapper/plugins/descendants.rb +0 -17
  107. data/rails/init.rb +0 -19
@@ -2,8 +2,6 @@ require 'test_helper'
2
2
  require 'models'
3
3
 
4
4
  class KeyTest < Test::Unit::TestCase
5
- include MongoMapper::Plugins::Keys
6
-
7
5
  context ".new with no id and _id of type integer" do
8
6
  should "not error" do
9
7
  lambda {
@@ -1,29 +1,35 @@
1
1
  require 'test_helper'
2
2
 
3
- module MyPlugin
4
- def self.configure(model)
5
- model.class_eval { attr_accessor :from_configure }
3
+ class PluginsTest < Test::Unit::TestCase
4
+ should "default plugins to empty array" do
5
+ Class.new { extend MongoMapper::Plugins }.plugins.should == []
6
6
  end
7
7
 
8
- module ClassMethods
9
- def class_foo
10
- 'class_foo'
11
- end
12
- end
8
+ context "ActiveSupport::Concern" do
9
+ module MyConcern
10
+ extend ActiveSupport::Concern
11
+
12
+ included do
13
+ attr_accessor :from_concern
14
+ end
15
+
16
+ module ClassMethods
17
+ def class_foo
18
+ 'class_foo'
19
+ end
20
+ end
13
21
 
14
- module InstanceMethods
15
- def instance_foo
16
- 'instance_foo'
22
+ module InstanceMethods
23
+ def instance_foo
24
+ 'instance_foo'
25
+ end
26
+ end
17
27
  end
18
- end
19
- end
20
28
 
21
- class PluginsTest < Test::Unit::TestCase
22
- context "plugin" do
23
29
  setup do
24
30
  @document = Class.new do
25
31
  extend MongoMapper::Plugins
26
- plugin MyPlugin
32
+ plugin MyConcern
27
33
  end
28
34
  end
29
35
 
@@ -36,15 +42,95 @@ class PluginsTest < Test::Unit::TestCase
36
42
  end
37
43
 
38
44
  should "pass model to configure" do
39
- @document.new.should respond_to(:from_configure)
45
+ @document.new.should respond_to(:from_concern)
46
+ end
47
+
48
+ should "add plugin to plugins" do
49
+ @document.plugins.should include(MyConcern)
50
+ end
51
+
52
+ context "Document" do
53
+ setup do
54
+ MongoMapper::Document.plugins.delete(MyConcern)
55
+ end
56
+
57
+ should 'allow plugins on Document' do
58
+ MongoMapper::Document.plugin(MyConcern)
59
+ Doc().should respond_to(:class_foo)
60
+ Doc().new.should respond_to(:instance_foo)
61
+ end
62
+
63
+ should 'add plugins to classes that include Document before they are added' do
64
+ article = Doc()
65
+ MongoMapper::Document.plugin(MyConcern)
66
+ article.should respond_to(:class_foo)
67
+ article.new.should respond_to(:instance_foo)
68
+ end
69
+ end
70
+
71
+ context "EmbeddedDocument" do
72
+ setup do
73
+ MongoMapper::EmbeddedDocument.plugins.delete(MyConcern)
74
+ end
75
+
76
+ should 'allow plugins on EmbeddedDocument' do
77
+ MongoMapper::EmbeddedDocument.plugin(MyConcern)
78
+ article = EDoc()
79
+ article.should respond_to(:class_foo)
80
+ article.new.should respond_to(:instance_foo)
81
+ end
82
+
83
+ should 'add plugins to classes that include EmbeddedDocument before they are added' do
84
+ article = EDoc()
85
+ MongoMapper::EmbeddedDocument.plugin(MyConcern)
86
+ article.should respond_to(:class_foo)
87
+ article.new.should respond_to(:instance_foo)
88
+ end
40
89
  end
90
+ end
41
91
 
42
- should "default plugins to empty array" do
43
- Class.new { extend MongoMapper::Plugins }.plugins.should == []
92
+ context "deprecated plugin" do
93
+ module DeprecatedPlugin
94
+ def self.configure(model)
95
+ model.class_eval { attr_accessor :from_configure }
96
+ end
97
+
98
+ module ClassMethods
99
+ def class_foo
100
+ 'class_foo'
101
+ end
102
+ end
103
+
104
+ module InstanceMethods
105
+ def instance_foo
106
+ 'instance_foo'
107
+ end
108
+ end
109
+ end
110
+
111
+ setup do
112
+ silence_stderr do
113
+ @document = Class.new do
114
+ extend MongoMapper::Plugins
115
+ plugin DeprecatedPlugin
116
+ end
117
+ end
118
+ end
119
+
120
+ should "include instance methods" do
121
+ @document.new.instance_foo.should == 'instance_foo'
122
+ end
123
+
124
+ should "extend class methods" do
125
+ @document.class_foo.should == 'class_foo'
126
+ end
127
+
128
+ should "pass model to configure" do
129
+ @document.new.should respond_to(:from_configure)
44
130
  end
45
131
 
46
132
  should "add plugin to plugins" do
47
- @document.plugins.should include(MyPlugin)
133
+ @document.plugins.should include(DeprecatedPlugin)
48
134
  end
49
135
  end
50
136
  end
@@ -33,8 +33,8 @@ class TestRails < Test::Unit::TestCase
33
33
  write_attribute(:foo, value)
34
34
  end
35
35
 
36
- def bar_before_typecast
37
- read_attribute_before_typecast(:foo)
36
+ def bar_before_type_cast
37
+ read_attribute_before_type_cast(:foo)
38
38
  end
39
39
 
40
40
  def bar
@@ -51,8 +51,8 @@ class TestRails < Test::Unit::TestCase
51
51
  @klass.new(:foo => 'Bar').bar.should == 'Bar'
52
52
  end
53
53
 
54
- should "be able to read key before typecast with read_attribute_before_typecast" do
55
- @klass.new(:foo => 21).bar_before_typecast.should == 21
54
+ should "be able to read key before type cast with read_attribute_before_type_cast" do
55
+ @klass.new(:foo => 21).bar_before_type_cast.should == 21
56
56
  @klass.new(:foo => 21).bar.should == '21'
57
57
  end
58
58
 
@@ -120,8 +120,8 @@ class TestRails < Test::Unit::TestCase
120
120
  write_attribute(:foo, value)
121
121
  end
122
122
 
123
- def bar_before_typecast
124
- read_attribute_before_typecast(:foo)
123
+ def bar_before_type_cast
124
+ read_attribute_before_type_cast(:foo)
125
125
  end
126
126
 
127
127
  def bar
@@ -138,8 +138,8 @@ class TestRails < Test::Unit::TestCase
138
138
  @klass.new(:foo => 'Bar').bar.should == 'Bar'
139
139
  end
140
140
 
141
- should "be able to read key before typecast with read_attribute_before_typecast" do
142
- @klass.new(:foo => 21).bar_before_typecast.should == 21
141
+ should "be able to read key before type cast with read_attribute_before_type_cast" do
142
+ @klass.new(:foo => 21).bar_before_type_cast.should == 21
143
143
  @klass.new(:foo => 21).bar.should == '21'
144
144
  end
145
145
 
@@ -19,7 +19,122 @@ class SerializationTest < Test::Unit::TestCase
19
19
  )
20
20
  end
21
21
 
22
- [:json].each do |format|
22
+ context "#serializable_hash" do
23
+ class List
24
+ include MongoMapper::Document
25
+ key :name
26
+ many :items, :class_name => 'SerializationTest::Item'
27
+ belongs_to :creator, :class_name => 'SerializationTest::User'
28
+ end
29
+
30
+ class Item
31
+ include MongoMapper::Document
32
+
33
+ key :title
34
+ key :description
35
+ many :assignments, :class_name => 'SerializationTest::Assignment'
36
+
37
+ def a_method
38
+ 1
39
+ end
40
+ end
41
+
42
+ class Assignment
43
+ include MongoMapper::EmbeddedDocument
44
+ belongs_to :assigned_by, :class_name => 'SerializationTest::User'
45
+ belongs_to :user, :class_name => 'SerializationTest::User'
46
+
47
+ def serializable_hash(options = {})
48
+ super({:only => :user_id}.merge(options))
49
+ end
50
+ end
51
+
52
+ class User
53
+ include MongoMapper::Document
54
+ key :name, String
55
+ end
56
+
57
+ setup do
58
+ @user1 = User.new(:name => 'Brandon')
59
+ @user2 = User.new(:name => 'John')
60
+ @item = Item.new(
61
+ :title => 'Serialization',
62
+ :description => 'Make it work like magic!',
63
+ :assignments => [
64
+ Assignment.new(:assigned_by => @user1, :user => @user2)
65
+ ]
66
+ )
67
+ end
68
+
69
+ should "only include specified attributes with :only option" do
70
+ @item.serializable_hash(:only => :title).should == {'title' => 'Serialization'}
71
+ end
72
+
73
+ should "exclude attributes specified with :except option" do
74
+ hash = @item.serializable_hash(:except => :description)
75
+ hash['title'].should_not be_nil
76
+ hash['description'].should be_nil
77
+ end
78
+
79
+ should "add :methods with :only option" do
80
+ @item.serializable_hash(:only => :title, :methods => :a_method).should == {
81
+ 'title' => 'Serialization',
82
+ 'a_method' => 1
83
+ }
84
+ end
85
+
86
+ should "call #serializable_hash on embedded many docs" do
87
+ @item.serializable_hash.should == {
88
+ 'id' => @item.id,
89
+ 'title' => 'Serialization',
90
+ 'description' => 'Make it work like magic!',
91
+ 'assignments' => [{'user_id' => @user2.id}]
92
+ }
93
+ end
94
+
95
+ context "with :include" do
96
+ setup do
97
+ @list = List.new(:title => 'MongoMapper', :items => [@item], :creator => @user1)
98
+ end
99
+
100
+ should "add many association" do
101
+ hash = @list.serializable_hash(:include => :items)
102
+ hash['items'].should be_instance_of(Array)
103
+ hash['items'].first['title'].should == 'Serialization'
104
+ end
105
+
106
+ should "add belongs_to association" do
107
+ hash = @list.serializable_hash(:include => :creator)
108
+ hash['creator'].should == @user1.serializable_hash
109
+ end
110
+
111
+ should "add one association" do
112
+ author_class = Doc do
113
+ key :post_id, ObjectId
114
+ end
115
+ post_class = Doc('Post') do
116
+ one :author, :class => author_class
117
+ end
118
+
119
+ author = author_class.new
120
+ hash = post_class.new(:author => author).serializable_hash(:include => :author)
121
+ hash['author'].should == author.serializable_hash
122
+ end
123
+
124
+ should "include multiple associations" do
125
+ hash = @list.serializable_hash(:include => [:items, :creator])
126
+ hash['items'].should be_instance_of(Array)
127
+ hash['creator'].should == @user1.serializable_hash
128
+ end
129
+
130
+ should "include multiple associations with options" do
131
+ hash = @list.serializable_hash(:include => {:creator => {:only => :name}})
132
+ hash['creator'].should == @user1.serializable_hash(:only => :name)
133
+ end
134
+ end
135
+ end
136
+
137
+ [:json, :xml].each do |format|
23
138
  context format do
24
139
  should "be reversable" do
25
140
  serialized = @instance.send("to_#{format}")
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ class TranslationTest < Test::Unit::TestCase
4
+ should "translate add mongo_mapper translations" do
5
+ I18n.translate("mongo_mapper.errors.messages.taken").should == "has already been taken"
6
+ end
7
+
8
+ should "set i18n_scope" do
9
+ Doc().i18n_scope.should == :mongo_mapper
10
+ end
11
+
12
+ should "translate document attributes" do
13
+ I18n.config.backend.store_translations(:en, :mongo_mapper => {:attributes => {:thing => {:foo => 'Bar'}}})
14
+ doc = Doc('Thing') do
15
+ key :foo, String
16
+ end
17
+ doc.human_attribute_name(:foo).should == 'Bar'
18
+ end
19
+
20
+ should "translate embedded document attributes" do
21
+ I18n.config.backend.store_translations(:en, :mongo_mapper => {:attributes => {:thing => {:foo => 'Bar'}}})
22
+ doc = EDoc('Thing') do
23
+ key :foo, String
24
+ end
25
+ doc.human_attribute_name(:foo).should == 'Bar'
26
+ end
27
+ end
@@ -4,27 +4,7 @@ class ValidationsTest < Test::Unit::TestCase
4
4
  context "Validations" do
5
5
  context "on a Document" do
6
6
  setup do
7
- @document = Doc()
8
- end
9
-
10
- context "Validating uniquness of" do
11
- should "not validate nil when allow_nil false" do
12
- @document.key :name, String
13
- @document.validates_uniqueness_of :name, :allow_nil => false
14
- doc = @document.new(:name => nil)
15
- doc.should have_error_on(:name)
16
- doc.name = "Ryan"
17
- doc.should_not have_error_on(:name)
18
- end
19
-
20
- should "not validate blank when allow_blank false" do
21
- @document.key :name, String
22
- @document.validates_uniqueness_of :name, :allow_blank => false
23
- doc = @document.new(:name => "")
24
- doc.should have_error_on(:name)
25
- doc.name = "Ryan"
26
- doc.should_not have_error_on(:name)
27
- end
7
+ @document = Doc('John')
28
8
  end
29
9
 
30
10
  context "Validating acceptance of" do
@@ -42,9 +22,13 @@ class ValidationsTest < Test::Unit::TestCase
42
22
  should "work with validates_confirmation_of macro" do
43
23
  @document.key :password, String
44
24
  @document.validates_confirmation_of :password
25
+
26
+ # NOTE: Api change as ActiveModel passes if password_confirmation is nil
45
27
  doc = @document.new
46
28
  doc.password = 'foobar'
29
+ doc.password_confirmation = 'foobar1'
47
30
  doc.should have_error_on(:password)
31
+
48
32
  doc.password_confirmation = 'foobar'
49
33
  doc.should_not have_error_on(:password)
50
34
  end
@@ -160,19 +144,19 @@ class ValidationsTest < Test::Unit::TestCase
160
144
  end # numericality of
161
145
 
162
146
  context "validating presence of" do
163
- should "work with validates_presence_of macro" do
164
- @document.key :name, String
165
- @document.validates_presence_of :name
166
- doc = @document.new
167
- doc.should have_error_on(:name)
168
- end
169
-
170
- should "work with :required shortcut on key definition" do
171
- @document.key :name, String, :required => true
172
- doc = @document.new
173
- doc.should have_error_on(:name)
174
- end
175
- end
147
+ should "work with validates_presence_of macro" do
148
+ @document.key :name, String
149
+ @document.validates_presence_of :name
150
+ doc = @document.new
151
+ doc.should have_error_on(:name)
152
+ end
153
+
154
+ should "work with :required shortcut on key definition" do
155
+ @document.key :name, String, :required => true
156
+ doc = @document.new
157
+ doc.should have_error_on(:name)
158
+ end
159
+ end
176
160
 
177
161
  context "validating exclusion of" do
178
162
  should "throw error if enumerator not provided" do
@@ -184,7 +168,7 @@ class ValidationsTest < Test::Unit::TestCase
184
168
 
185
169
  should "work with validates_exclusion_of macro" do
186
170
  @document.key :action, String
187
- @document.validates_exclusion_of :action, :within => %w(kick run)
171
+ @document.validates_exclusion_of :action, :in => %w(kick run)
188
172
 
189
173
  doc = @document.new
190
174
  doc.should_not have_error_on(:action)
@@ -211,7 +195,7 @@ class ValidationsTest < Test::Unit::TestCase
211
195
 
212
196
  should "not have error if allow nil is true and value is nil" do
213
197
  @document.key :action, String
214
- @document.validates_exclusion_of :action, :within => %w(kick run), :allow_nil => true
198
+ @document.validates_exclusion_of :action, :in => %w(kick run), :allow_nil => true
215
199
 
216
200
  doc = @document.new
217
201
  doc.should_not have_error_on(:action)
@@ -219,7 +203,7 @@ class ValidationsTest < Test::Unit::TestCase
219
203
 
220
204
  should "not have error if allow blank is true and value is blank" do
221
205
  @document.key :action, String
222
- @document.validates_exclusion_of :action, :within => %w(kick run), :allow_nil => true
206
+ @document.validates_exclusion_of :action, :in => %w(kick run), :allow_nil => true
223
207
 
224
208
  doc = @document.new(:action => '')
225
209
  doc.should_not have_error_on(:action)
@@ -236,13 +220,13 @@ class ValidationsTest < Test::Unit::TestCase
236
220
 
237
221
  should "work with validates_inclusion_of macro" do
238
222
  @document.key :action, String
239
- @document.validates_inclusion_of :action, :within => %w(kick run)
223
+ @document.validates_inclusion_of :action, :in => %w(kick run)
240
224
 
241
225
  doc = @document.new
242
- doc.should have_error_on(:action, 'is not in the list')
226
+ doc.should have_error_on(:action, 'is not included in the list')
243
227
 
244
228
  doc.action = 'fart'
245
- doc.should have_error_on(:action, 'is not in the list')
229
+ doc.should have_error_on(:action, 'is not included in the list')
246
230
 
247
231
  doc.action = 'kick'
248
232
  doc.should_not have_error_on(:action)
@@ -252,10 +236,10 @@ class ValidationsTest < Test::Unit::TestCase
252
236
  @document.key :action, String, :in => %w(kick run)
253
237
 
254
238
  doc = @document.new
255
- doc.should have_error_on(:action, 'is not in the list')
239
+ doc.should have_error_on(:action, 'is not included in the list')
256
240
 
257
241
  doc.action = 'fart'
258
- doc.should have_error_on(:action, 'is not in the list')
242
+ doc.should have_error_on(:action, 'is not included in the list')
259
243
 
260
244
  doc.action = 'kick'
261
245
  doc.should_not have_error_on(:action)
@@ -263,7 +247,7 @@ class ValidationsTest < Test::Unit::TestCase
263
247
 
264
248
  should "not have error if allow nil is true and value is nil" do
265
249
  @document.key :action, String
266
- @document.validates_inclusion_of :action, :within => %w(kick run), :allow_nil => true
250
+ @document.validates_inclusion_of :action, :in => %w(kick run), :allow_nil => true
267
251
 
268
252
  doc = @document.new
269
253
  doc.should_not have_error_on(:action)
@@ -271,7 +255,7 @@ class ValidationsTest < Test::Unit::TestCase
271
255
 
272
256
  should "not have error if allow blank is true and value is blank" do
273
257
  @document.key :action, String
274
- @document.validates_inclusion_of :action, :within => %w(kick run), :allow_blank => true
258
+ @document.validates_inclusion_of :action, :in => %w(kick run), :allow_blank => true
275
259
 
276
260
  doc = @document.new(:action => '')
277
261
  doc.should_not have_error_on(:action)
@@ -302,6 +286,7 @@ class ValidationsTest < Test::Unit::TestCase
302
286
  @embedded_doc.validates_confirmation_of :password
303
287
  doc = @embedded_doc.new
304
288
  doc.password = 'foobar'
289
+ doc.password_confirmation = 'foobar1'
305
290
  doc.should have_error_on(:password)
306
291
  doc.password_confirmation = 'foobar'
307
292
  doc.should_not have_error_on(:password)
@@ -418,19 +403,19 @@ class ValidationsTest < Test::Unit::TestCase
418
403
  end # numericality of
419
404
 
420
405
  context "validating presence of" do
421
- should "work with validates_presence_of macro" do
422
- @embedded_doc.key :name, String
423
- @embedded_doc.validates_presence_of :name
424
- doc = @embedded_doc.new
425
- doc.should have_error_on(:name)
426
- end
427
-
428
- should "work with :required shortcut on key definition" do
429
- @embedded_doc.key :name, String, :required => true
430
- doc = @embedded_doc.new
431
- doc.should have_error_on(:name)
432
- end
433
- end
406
+ should "work with validates_presence_of macro" do
407
+ @embedded_doc.key :name, String
408
+ @embedded_doc.validates_presence_of :name
409
+ doc = @embedded_doc.new
410
+ doc.should have_error_on(:name)
411
+ end
412
+
413
+ should "work with :required shortcut on key definition" do
414
+ @embedded_doc.key :name, String, :required => true
415
+ doc = @embedded_doc.new
416
+ doc.should have_error_on(:name)
417
+ end
418
+ end
434
419
 
435
420
  context "validating exclusion of" do
436
421
  should "throw error if enumerator not provided" do
@@ -442,7 +427,7 @@ class ValidationsTest < Test::Unit::TestCase
442
427
 
443
428
  should "work with validates_exclusion_of macro" do
444
429
  @embedded_doc.key :action, String
445
- @embedded_doc.validates_exclusion_of :action, :within => %w(kick run)
430
+ @embedded_doc.validates_exclusion_of :action, :in => %w(kick run)
446
431
 
447
432
  doc = @embedded_doc.new
448
433
  doc.should_not have_error_on(:action)
@@ -469,7 +454,7 @@ class ValidationsTest < Test::Unit::TestCase
469
454
 
470
455
  should "not have error if allow nil is true and value is nil" do
471
456
  @embedded_doc.key :action, String
472
- @embedded_doc.validates_exclusion_of :action, :within => %w(kick run), :allow_nil => true
457
+ @embedded_doc.validates_exclusion_of :action, :in => %w(kick run), :allow_nil => true
473
458
 
474
459
  doc = @embedded_doc.new
475
460
  doc.should_not have_error_on(:action)
@@ -477,7 +462,7 @@ class ValidationsTest < Test::Unit::TestCase
477
462
 
478
463
  should "not have error if allow blank is true and value is blank" do
479
464
  @embedded_doc.key :action, String
480
- @embedded_doc.validates_exclusion_of :action, :within => %w(kick run), :allow_nil => true
465
+ @embedded_doc.validates_exclusion_of :action, :in => %w(kick run), :allow_nil => true
481
466
 
482
467
  doc = @embedded_doc.new(:action => '')
483
468
  doc.should_not have_error_on(:action)
@@ -494,13 +479,13 @@ class ValidationsTest < Test::Unit::TestCase
494
479
 
495
480
  should "work with validates_inclusion_of macro" do
496
481
  @embedded_doc.key :action, String
497
- @embedded_doc.validates_inclusion_of :action, :within => %w(kick run)
482
+ @embedded_doc.validates_inclusion_of :action, :in => %w(kick run)
498
483
 
499
484
  doc = @embedded_doc.new
500
- doc.should have_error_on(:action, 'is not in the list')
485
+ doc.should have_error_on(:action, 'is not included in the list')
501
486
 
502
487
  doc.action = 'fart'
503
- doc.should have_error_on(:action, 'is not in the list')
488
+ doc.should have_error_on(:action, 'is not included in the list')
504
489
 
505
490
  doc.action = 'kick'
506
491
  doc.should_not have_error_on(:action)
@@ -510,10 +495,10 @@ class ValidationsTest < Test::Unit::TestCase
510
495
  @embedded_doc.key :action, String, :in => %w(kick run)
511
496
 
512
497
  doc = @embedded_doc.new
513
- doc.should have_error_on(:action, 'is not in the list')
498
+ doc.should have_error_on(:action, 'is not included in the list')
514
499
 
515
500
  doc.action = 'fart'
516
- doc.should have_error_on(:action, 'is not in the list')
501
+ doc.should have_error_on(:action, 'is not included in the list')
517
502
 
518
503
  doc.action = 'kick'
519
504
  doc.should_not have_error_on(:action)
@@ -521,7 +506,7 @@ class ValidationsTest < Test::Unit::TestCase
521
506
 
522
507
  should "not have error if allow nil is true and value is nil" do
523
508
  @embedded_doc.key :action, String
524
- @embedded_doc.validates_inclusion_of :action, :within => %w(kick run), :allow_nil => true
509
+ @embedded_doc.validates_inclusion_of :action, :in => %w(kick run), :allow_nil => true
525
510
 
526
511
  doc = @embedded_doc.new
527
512
  doc.should_not have_error_on(:action)
@@ -529,7 +514,7 @@ class ValidationsTest < Test::Unit::TestCase
529
514
 
530
515
  should "not have error if allow blank is true and value is blank" do
531
516
  @embedded_doc.key :action, String
532
- @embedded_doc.validates_inclusion_of :action, :within => %w(kick run), :allow_blank => true
517
+ @embedded_doc.validates_inclusion_of :action, :in => %w(kick run), :allow_blank => true
533
518
 
534
519
  doc = @embedded_doc.new(:action => '')
535
520
  doc.should_not have_error_on(:action)
@@ -541,24 +526,24 @@ class ValidationsTest < Test::Unit::TestCase
541
526
  end # Validations
542
527
 
543
528
  context "Adding validation errors" do
544
- setup do
545
- @document = Doc do
546
- key :action, String
547
- def action_present
548
- errors.add(:action, 'is invalid') if action.blank?
529
+ setup do
530
+ @document = Doc do
531
+ key :action, String
532
+ def action_present
533
+ errors.add(:action, 'is invalid') if action.blank?
534
+ end
549
535
  end
550
536
  end
551
- end
552
537
 
553
- should "work with validate callback" do
554
- @document.validate :action_present
538
+ should "work with validate callback" do
539
+ @document.validate :action_present
555
540
 
556
- doc = @document.new
557
- doc.action = nil
558
- doc.should have_error_on(:action)
541
+ doc = @document.new
542
+ doc.action = nil
543
+ doc.should have_error_on(:action)
559
544
 
560
- doc.action = 'kick'
561
- doc.should_not have_error_on(:action)
545
+ doc.action = 'kick'
546
+ doc.should_not have_error_on(:action)
547
+ end
562
548
  end
563
- end
564
549
  end