mongo_mapper 0.13.1 → 0.14.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +13 -5
  2. data/README.rdoc +3 -6
  3. data/lib/mongo_mapper.rb +1 -0
  4. data/lib/mongo_mapper/document.rb +2 -0
  5. data/lib/mongo_mapper/extensions/array.rb +14 -6
  6. data/lib/mongo_mapper/extensions/hash.rb +15 -3
  7. data/lib/mongo_mapper/extensions/object.rb +4 -0
  8. data/lib/mongo_mapper/extensions/string.rb +13 -5
  9. data/lib/mongo_mapper/plugins/accessible.rb +12 -11
  10. data/lib/mongo_mapper/plugins/associations.rb +7 -6
  11. data/lib/mongo_mapper/plugins/associations/base.rb +13 -12
  12. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +9 -8
  13. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +12 -11
  14. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +4 -4
  15. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +24 -23
  16. data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +18 -16
  17. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +55 -48
  18. data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +14 -13
  19. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +7 -6
  20. data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +7 -5
  21. data/lib/mongo_mapper/plugins/associations/one_as_proxy.rb +14 -11
  22. data/lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb +14 -13
  23. data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +9 -9
  24. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +27 -26
  25. data/lib/mongo_mapper/plugins/associations/proxy.rb +29 -26
  26. data/lib/mongo_mapper/plugins/callbacks.rb +13 -0
  27. data/lib/mongo_mapper/plugins/counter_cache.rb +23 -4
  28. data/lib/mongo_mapper/plugins/dirty.rb +2 -2
  29. data/lib/mongo_mapper/plugins/dynamic_querying.rb +10 -9
  30. data/lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb +17 -16
  31. data/lib/mongo_mapper/plugins/embedded_callbacks.rb +1 -1
  32. data/lib/mongo_mapper/plugins/identity_map.rb +1 -1
  33. data/lib/mongo_mapper/plugins/indexes.rb +1 -1
  34. data/lib/mongo_mapper/plugins/keys.rb +158 -158
  35. data/lib/mongo_mapper/plugins/keys/key.rb +16 -10
  36. data/lib/mongo_mapper/plugins/keys/static.rb +45 -0
  37. data/lib/mongo_mapper/plugins/modifiers.rb +27 -26
  38. data/lib/mongo_mapper/plugins/partial_updates.rb +86 -0
  39. data/lib/mongo_mapper/plugins/persistence.rb +7 -6
  40. data/lib/mongo_mapper/plugins/protected.rb +6 -5
  41. data/lib/mongo_mapper/plugins/querying.rb +80 -43
  42. data/lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb +14 -9
  43. data/lib/mongo_mapper/plugins/scopes.rb +78 -7
  44. data/lib/mongo_mapper/plugins/timestamps.rb +1 -0
  45. data/lib/mongo_mapper/plugins/validations.rb +0 -0
  46. data/lib/mongo_mapper/version.rb +1 -1
  47. data/lib/rails/generators/mongo_mapper/config/config_generator.rb +12 -13
  48. data/lib/rails/generators/mongo_mapper/model/model_generator.rb +9 -9
  49. data/spec/functional/accessible_spec.rb +12 -12
  50. data/spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb +11 -11
  51. data/spec/functional/associations/belongs_to_proxy_spec.rb +14 -15
  52. data/spec/functional/associations/in_array_proxy_spec.rb +6 -6
  53. data/spec/functional/associations/many_documents_proxy_spec.rb +89 -18
  54. data/spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb +11 -11
  55. data/spec/functional/associations/many_embedded_proxy_spec.rb +1 -1
  56. data/spec/functional/associations/one_as_proxy_spec.rb +14 -14
  57. data/spec/functional/associations/one_embedded_polymorphic_proxy_spec.rb +9 -9
  58. data/spec/functional/associations/one_embedded_proxy_spec.rb +3 -3
  59. data/spec/functional/associations/one_proxy_spec.rb +14 -14
  60. data/spec/functional/caching_spec.rb +8 -8
  61. data/spec/functional/callbacks_spec.rb +87 -0
  62. data/spec/functional/counter_cache_spec.rb +89 -0
  63. data/spec/functional/dirty_spec.rb +41 -41
  64. data/spec/functional/document_spec.rb +3 -3
  65. data/spec/functional/embedded_document_spec.rb +18 -18
  66. data/spec/functional/identity_map_spec.rb +28 -15
  67. data/spec/functional/indexes_spec.rb +4 -4
  68. data/spec/functional/keys_spec.rb +12 -3
  69. data/spec/functional/logger_spec.rb +1 -1
  70. data/spec/functional/modifiers_spec.rb +2 -2
  71. data/spec/functional/partial_updates_spec.rb +577 -0
  72. data/spec/functional/protected_spec.rb +13 -13
  73. data/spec/functional/querying_spec.rb +11 -10
  74. data/spec/functional/safe_spec.rb +2 -2
  75. data/spec/functional/sci_spec.rb +3 -3
  76. data/spec/functional/scopes_spec.rb +234 -1
  77. data/spec/functional/static_keys_spec.rb +153 -0
  78. data/spec/functional/stats_spec.rb +0 -4
  79. data/spec/functional/touch_spec.rb +1 -1
  80. data/spec/functional/validations_spec.rb +59 -57
  81. data/spec/quality_spec.rb +1 -1
  82. data/spec/spec_helper.rb +7 -3
  83. data/spec/support/matchers.rb +4 -13
  84. data/spec/unit/associations/base_spec.rb +12 -12
  85. data/spec/unit/associations/belongs_to_association_spec.rb +2 -2
  86. data/spec/unit/associations/many_association_spec.rb +2 -2
  87. data/spec/unit/associations/one_association_spec.rb +2 -2
  88. data/spec/unit/associations/proxy_spec.rb +13 -15
  89. data/spec/unit/document_spec.rb +5 -5
  90. data/spec/unit/dynamic_finder_spec.rb +8 -8
  91. data/spec/unit/embedded_document_spec.rb +14 -14
  92. data/spec/unit/extensions_spec.rb +17 -17
  93. data/spec/unit/identity_map_middleware_spec.rb +5 -5
  94. data/spec/unit/key_spec.rb +24 -21
  95. data/spec/unit/keys_spec.rb +5 -5
  96. data/spec/unit/mongo_mapper_spec.rb +26 -26
  97. data/spec/unit/rails_spec.rb +2 -2
  98. data/spec/unit/serialization_spec.rb +1 -1
  99. data/spec/unit/time_zones_spec.rb +2 -2
  100. data/spec/unit/validations_spec.rb +28 -15
  101. metadata +16 -14
  102. data/lib/mongo_mapper/connections/10gen.rb +0 -0
  103. data/lib/mongo_mapper/connections/moped.rb +0 -0
@@ -38,7 +38,7 @@ describe "OneEmbeddedProxy" do
38
38
  post.reload
39
39
 
40
40
  post.author.should == author
41
- post.author.nil?.should be_false
41
+ post.author.nil?.should be_falsey
42
42
 
43
43
  new_author = @author_class.new(:name => 'Emily')
44
44
  post.author = new_author
@@ -72,10 +72,10 @@ describe "OneEmbeddedProxy" do
72
72
  @post_class.one :author, :class => @author_class
73
73
 
74
74
  post = @post_class.new
75
- post.author?.should be_false
75
+ post.author?.should be_falsey
76
76
 
77
77
  post.author = @author_class.new(:name => 'Frank')
78
- post.author?.should be_true
78
+ post.author?.should be_truthy
79
79
  end
80
80
 
81
81
  it "should initialize id for nested embedded document created from hash" do
@@ -11,7 +11,7 @@ describe "OneProxy" do
11
11
 
12
12
  it "should default to nil" do
13
13
  @post_class.one :author, :class => @author_class
14
- @post_class.new.author.nil?.should be_true
14
+ @post_class.new.author.nil?.should be_truthy
15
15
  end
16
16
 
17
17
  it "should return nil instead of a proxy" do
@@ -25,7 +25,7 @@ describe "OneProxy" do
25
25
  post = @post_class.new('author' => { 'name' => 'Frank' })
26
26
  post.author.name.should == 'Frank'
27
27
 
28
- post.save.should be_true
28
+ post.save.should be_truthy
29
29
  post.reload
30
30
 
31
31
  post.author.name.should == 'Frank'
@@ -42,7 +42,7 @@ describe "OneProxy" do
42
42
  post.reload
43
43
 
44
44
  post.author.should == author
45
- post.author.nil?.should be_false
45
+ post.author.nil?.should be_falsey
46
46
 
47
47
  new_author = @author_class.new(:name => 'Emily')
48
48
  post.author = new_author
@@ -58,7 +58,7 @@ describe "OneProxy" do
58
58
  post.reload
59
59
 
60
60
  post.author.should == author
61
- post.author.nil?.should be_false
61
+ post.author.nil?.should be_falsey
62
62
 
63
63
  original_author = post.author
64
64
  original_author.name.should == 'Frank'
@@ -79,7 +79,7 @@ describe "OneProxy" do
79
79
  post.reload
80
80
 
81
81
  post.author.name.should == 'Frank'
82
- post.author.nil?.should be_false
82
+ post.author.nil?.should be_falsey
83
83
 
84
84
  post.author = {'name' => 'Emily'}
85
85
  post.author.name.should == 'Emily'
@@ -97,7 +97,7 @@ describe "OneProxy" do
97
97
  end
98
98
 
99
99
  it "should call delete on the existing document" do
100
- @author_class.any_instance.should_receive(:delete).once
100
+ expect_any_instance_of(@author_class).to receive(:delete).once
101
101
  @post.author = @author_class.new
102
102
  end
103
103
 
@@ -107,7 +107,7 @@ describe "OneProxy" do
107
107
  end
108
108
 
109
109
  it "should do nothing if it's the same document" do
110
- @author_class.any_instance.should_receive(:delete).never
110
+ expect_any_instance_of(@author_class).to receive(:delete).never
111
111
  @post.author = @author
112
112
  end
113
113
  end
@@ -122,7 +122,7 @@ describe "OneProxy" do
122
122
  end
123
123
 
124
124
  it "should call destroy the existing document" do
125
- @author_class.any_instance.should_receive(:destroy).once
125
+ expect_any_instance_of(@author_class).to receive(:destroy).once
126
126
  @post.author = @author_class.new
127
127
  end
128
128
 
@@ -132,7 +132,7 @@ describe "OneProxy" do
132
132
  end
133
133
 
134
134
  it "should do nothing if it's the same document" do
135
- @author_class.any_instance.should_receive(:destroy).never
135
+ expect_any_instance_of(@author_class).to receive(:destroy).never
136
136
  @post.author = @author
137
137
  end
138
138
  end
@@ -207,10 +207,10 @@ describe "OneProxy" do
207
207
  @post_class.one :author, :class => @author_class
208
208
 
209
209
  post = @post_class.new
210
- post.author?.should be_false
210
+ post.author?.should be_falsey
211
211
 
212
212
  post.author = @author_class.new(:name => 'Frank')
213
- post.author?.should be_true
213
+ post.author?.should be_truthy
214
214
  end
215
215
 
216
216
  it "should work with criteria" do
@@ -232,7 +232,7 @@ describe "OneProxy" do
232
232
  post.update_attributes!(:author => author)
233
233
  post.reload
234
234
  post.author = nil
235
- post.author.nil?.should be_true
235
+ post.author.nil?.should be_truthy
236
236
  end
237
237
 
238
238
  context "destroying parent with :dependent" do
@@ -246,7 +246,7 @@ describe "OneProxy" do
246
246
  end
247
247
 
248
248
  it "should should call destroy on the associated documents" do
249
- @author_class.any_instance.should_receive(:destroy).once
249
+ expect_any_instance_of(@author_class).to receive(:destroy).once
250
250
  @post.destroy
251
251
  end
252
252
 
@@ -268,7 +268,7 @@ describe "OneProxy" do
268
268
  end
269
269
 
270
270
  it "should should call delete the associated documents" do
271
- @author_class.any_instance.should_receive(:delete).once
271
+ expect_any_instance_of(@author_class).to receive(:delete).once
272
272
  @post.destroy
273
273
  end
274
274
 
@@ -6,16 +6,16 @@ describe "Caching" do
6
6
  extend MongoMapper::Plugins
7
7
  plugin MongoMapper::Plugins::Caching
8
8
  end
9
- @klass.stub(:name).and_return('Post')
10
- @klass.any_instance.stub(:persisted?).and_return(true)
11
- @klass.any_instance.stub(:[]).and_return(nil)
12
- @klass.any_instance.stub(:[]=).and_return(nil)
9
+ allow(@klass).to receive(:name).and_return('Post')
10
+ allow_any_instance_of(@klass).to receive(:persisted?).and_return(true)
11
+ allow_any_instance_of(@klass).to receive(:[]).and_return(nil)
12
+ allow_any_instance_of(@klass).to receive(:[]=).and_return(nil)
13
13
  end
14
14
 
15
15
  context "new" do
16
16
  before do
17
17
  @doc = @klass.new
18
- @doc.stub(:persisted?).and_return(false)
18
+ allow(@doc).to receive(:persisted?).and_return(false)
19
19
  end
20
20
 
21
21
  it "should be class/new" do
@@ -35,14 +35,14 @@ describe "Caching" do
35
35
  before do
36
36
  @object_id = BSON::ObjectId.new
37
37
  @doc = @klass.new
38
- @doc.stub(:persisted).and_return(true)
39
- @doc.stub(:id).and_return(@object_id)
38
+ allow(@doc).to receive(:persisted).and_return(true)
39
+ allow(@doc).to receive(:id).and_return(@object_id)
40
40
  end
41
41
 
42
42
  context "with updated_at" do
43
43
  before do
44
44
  time = Time.utc(2010, 6, 20, 8, 10, 7)
45
- @doc.stub(:[]).with(:updated_at).and_return(time)
45
+ allow(@doc).to receive(:[]).with(:updated_at).and_return(time)
46
46
  end
47
47
 
48
48
  it "should be class/id-timestamp" do
@@ -240,4 +240,91 @@ describe "Callbacks" do
240
240
  doc.message.should == 'Ho!'
241
241
  end
242
242
  end
243
+
244
+ describe "after_find" do
245
+ before do
246
+ @found_objects = []
247
+ found_objects = @found_objects # use a local for closure
248
+
249
+ @doc_class = Doc("User") do
250
+ after_find :set_found_object
251
+
252
+ define_method :set_found_object do
253
+ found_objects << self
254
+ end
255
+ end
256
+ end
257
+
258
+ it "should run after finding an object with find!" do
259
+ @doc = @doc_class.create!
260
+
261
+ @doc_class.find!(@doc.id)
262
+ @found_objects.should == [@doc]
263
+ end
264
+
265
+ it "should not have run if nothing was queried" do
266
+ @found_objects.should == []
267
+ end
268
+
269
+ it "should run for multiple objects" do
270
+ @doc1 = @doc_class.create!
271
+ @doc2 = @doc_class.create!
272
+
273
+ @doc_class.all
274
+ @found_objects.should == [@doc1, @doc2]
275
+ end
276
+
277
+ it "should run after finding an object through the query proxy" do
278
+ @doc = @doc_class.create!
279
+ @doc_class.where(:_id => @doc.id).first
280
+ @found_objects.should == [@doc]
281
+ end
282
+
283
+ it "should still return the object" do
284
+ @doc = @doc_class.create!
285
+ @doc_class.where(:_id => @doc.id).first.should == @doc
286
+ end
287
+
288
+ it "should not bail if the method return false" do
289
+ @doc_class = Doc("User") do
290
+ after_find :set_found_object
291
+
292
+ define_method :set_found_object do
293
+ false
294
+ end
295
+ end
296
+
297
+ @doc = @doc_class.create!
298
+ @doc_class.where(:_id => @doc.id).first.should == @doc
299
+ end
300
+ end
301
+
302
+ describe "after_initialize" do
303
+ before do
304
+ @objects = []
305
+ objects = @objects
306
+
307
+ @doc_class = Doc("User") do
308
+ after_initialize :set_initialized_object
309
+
310
+ define_method :set_initialized_object do
311
+ objects << self
312
+ end
313
+ end
314
+ end
315
+
316
+ it "should be triggered for objects created with new" do
317
+ @objects.should == []
318
+ obj = @doc_class.new
319
+ @objects.should == [obj]
320
+ end
321
+
322
+ it "should be triggered for objects found in the db" do
323
+ @doc = @doc_class.create!
324
+ @objects.clear # don't re-assign as we want the operation to be in place
325
+
326
+ @doc_class.all
327
+ @objects.should == [@doc]
328
+ end
329
+ end
243
330
  end
@@ -15,6 +15,7 @@ module CounterCacheFixtureModels
15
15
 
16
16
  key :comments_count, Integer, :default => 0
17
17
  key :some_custom_comments_count, Integer, :default => 0
18
+ key :commentable_count, Integer, :default => 0
18
19
 
19
20
  has_many :comments,
20
21
  :class_name => "CounterCacheFixtureModels::Comment"
@@ -22,6 +23,20 @@ module CounterCacheFixtureModels
22
23
  belongs_to :user,
23
24
  :counter_cache => true,
24
25
  :class_name => "CounterCacheFixtureModels::User"
26
+
27
+ many :polymorphic_comments,
28
+ :as => :commentable,
29
+ :class_name => "CounterCacheFixtureModels::Comment"
30
+ end
31
+
32
+ class Article
33
+ include MongoMapper::Document
34
+
35
+ key :commentable_count, Integer, :default => 0
36
+
37
+ many :polymorphic_comments,
38
+ :as => :commentable,
39
+ :class_name => "CounterCacheFixtureModels::Comment"
25
40
  end
26
41
 
27
42
  class Comment
@@ -30,6 +45,10 @@ module CounterCacheFixtureModels
30
45
  belongs_to :post,
31
46
  :counter_cache => true,
32
47
  :class_name => "CounterCacheFixtureModels::Post"
48
+
49
+ belongs_to :commentable,
50
+ :polymorphic => true,
51
+ :counter_cache => :commentable_count
33
52
  end
34
53
 
35
54
  class CustomComment
@@ -143,4 +162,74 @@ describe MongoMapper::Plugins::CounterCache do
143
162
  end
144
163
  }.should raise_error(MongoMapper::Plugins::CounterCache::InvalidCounterCacheError, "Missing `key :invalid_field, Integer, :default => 0' on model CounterCacheFixtureModels::Post")
145
164
  end
165
+
166
+ describe "with polymorphic associations" do
167
+ before do
168
+ @article = CounterCacheFixtureModels::Article.new
169
+ @comment = CounterCacheFixtureModels::Comment.new
170
+ @comment.commentable = @article
171
+ end
172
+
173
+ it "should update the counter cache on save" do
174
+ expect {
175
+ @comment.save!
176
+ @article.reload
177
+ }.to change(@article, :commentable_count).by(1)
178
+ end
179
+
180
+ it "should increment with a second object" do
181
+ @comment.save!
182
+
183
+ expect {
184
+ second_comment = CounterCacheFixtureModels::Comment.new
185
+ second_comment.commentable = @article
186
+ second_comment.save!
187
+ @article.reload
188
+ }.to change(@article, :commentable_count).by(1)
189
+ end
190
+
191
+ it "should decrement the counter cache on destroy" do
192
+ @comment.save!
193
+
194
+ expect {
195
+ @comment.destroy
196
+ @article.reload
197
+ }.to change(@article, :commentable_count).by(-1)
198
+ end
199
+
200
+ it "should increment with a different type of object" do
201
+ @comment.save!
202
+
203
+ expect {
204
+ second_comment = CounterCacheFixtureModels::Comment.new
205
+ second_comment.commentable = @article
206
+ second_comment.save!
207
+
208
+ @article.reload
209
+ }.to change(@article, :commentable_count).by(1)
210
+ end
211
+
212
+ describe "without a counter cache field" do
213
+ before do
214
+ @comment = CounterCacheFixtureModels::Comment.new
215
+ @klass = Class.new do
216
+ include MongoMapper::Document
217
+
218
+ many :polymorphic_comments,
219
+ :as => :commentable,
220
+ :class_name => "CounterCacheFixtureModels::Comment"
221
+ end
222
+
223
+ @obj = @klass.new
224
+ end
225
+
226
+ it "should raise at save (runtime) if there is no counter cache field" do
227
+ @comment.commentable = @obj
228
+
229
+ expect {
230
+ @comment.save!
231
+ }.to raise_error(MongoMapper::Plugins::CounterCache::InvalidCounterCacheError)
232
+ end
233
+ end
234
+ end
146
235
  end
@@ -11,73 +11,73 @@ describe "Dirty" do
11
11
  context "marking changes" do
12
12
  it "should not happen if there are none" do
13
13
  doc = @document.new
14
- doc.phrase_changed?.should be_false
14
+ doc.phrase_changed?.should be_falsey
15
15
  doc.phrase_change.should be_nil
16
16
  end
17
17
 
18
18
  it "should happen when change happens" do
19
19
  doc = @document.new
20
20
  doc.phrase = 'Golly Gee Willikers Batman'
21
- doc.phrase_changed?.should be_true
21
+ doc.phrase_changed?.should be_truthy
22
22
  doc.phrase_was.should be_nil
23
23
  doc.phrase_change.should == [nil, 'Golly Gee Willikers Batman']
24
24
  end
25
25
 
26
26
  it "should happen when initializing" do
27
27
  doc = @document.new(:phrase => 'Foo')
28
- doc.changed?.should be_true
28
+ doc.changed?.should be_truthy
29
29
  end
30
30
 
31
31
  it "should clear changes on save" do
32
32
  doc = @document.new
33
33
  doc.phrase = 'Golly Gee Willikers Batman'
34
- doc.phrase_changed?.should be_true
34
+ doc.phrase_changed?.should be_truthy
35
35
  doc.save
36
- doc.phrase_changed?.should_not be_true
36
+ doc.phrase_changed?.should_not be_truthy
37
37
  doc.phrase_change.should be_nil
38
38
  end
39
39
 
40
40
  it "should clear changes on save!" do
41
41
  doc = @document.new
42
42
  doc.phrase = 'Golly Gee Willikers Batman'
43
- doc.phrase_changed?.should be_true
43
+ doc.phrase_changed?.should be_truthy
44
44
  doc.save!
45
- doc.phrase_changed?.should_not be_true
45
+ doc.phrase_changed?.should_not be_truthy
46
46
  doc.phrase_change.should be_nil
47
47
  end
48
48
 
49
49
  it "should not happen when loading from database" do
50
50
  doc = @document.create(:phrase => 'Foo')
51
- @document.any_instance.should_receive(:attribute_will_change!).never
52
- @document.any_instance.should_receive(:attribute_changed?).never
51
+ expect_any_instance_of(@document).to receive(:attribute_will_change!).never
52
+ expect_any_instance_of(@document).to receive(:attribute_changed?).never
53
53
  doc = @document.find(doc.id)
54
- doc.changed?.should be_false
54
+ doc.changed?.should be_falsey
55
55
  end
56
56
 
57
57
  it "should not happen when reloading from database" do
58
58
  doc = @document.create(:phrase => 'Foo')
59
59
  doc = @document.find(doc.id)
60
60
 
61
- doc.changed?.should be_false
61
+ doc.changed?.should be_falsey
62
62
  doc.phrase = 'Fart'
63
- doc.changed?.should be_true
63
+ doc.changed?.should be_truthy
64
64
  doc.reload
65
- doc.changed?.should be_false
65
+ doc.changed?.should be_falsey
66
66
  end
67
67
 
68
68
  it "should happen if changed after loading from database" do
69
69
  doc = @document.create(:phrase => 'Foo')
70
70
  doc.reload
71
- doc.changed?.should be_false
71
+ doc.changed?.should be_falsey
72
72
  doc.phrase = 'Bar'
73
- doc.changed?.should be_true
73
+ doc.changed?.should be_truthy
74
74
  end
75
75
 
76
76
  it "should happen with aliased keys" do
77
77
  doc = @document.create(:paragraph => 'Wibbly')
78
78
  doc.paragraph = "Wobbly"
79
- doc.changed?.should be_true
80
- doc.paragraph_changed?.should be_true
79
+ doc.changed?.should be_truthy
80
+ doc.paragraph_changed?.should be_truthy
81
81
  end
82
82
  end
83
83
 
@@ -88,7 +88,7 @@ describe "Dirty" do
88
88
  [nil, ''].each do |value|
89
89
  doc = @document.new
90
90
  doc.age = value
91
- doc.age_changed?.should be_false
91
+ doc.age_changed?.should be_falsey
92
92
  doc.age_change.should be_nil
93
93
  end
94
94
  end
@@ -101,7 +101,7 @@ describe "Dirty" do
101
101
  [nil, ''].each do |value|
102
102
  doc = @document.new
103
103
  doc.amount = value
104
- doc.amount_changed?.should be_false
104
+ doc.amount_changed?.should be_falsey
105
105
  doc.amount_change.should be_nil
106
106
  end
107
107
  end
@@ -111,27 +111,27 @@ describe "Dirty" do
111
111
  it "should be true if key changed" do
112
112
  doc = @document.new
113
113
  doc.phrase = 'A penny saved is a penny earned.'
114
- doc.changed?.should be_true
114
+ doc.changed?.should be_truthy
115
115
  end
116
116
 
117
117
  it "should be false if no keys changed" do
118
- @document.new.changed?.should be_false
118
+ @document.new.changed?.should be_falsey
119
119
  end
120
120
 
121
121
  it "should not raise when key name is 'value'" do
122
122
  @document.key :value, Integer
123
123
 
124
124
  doc = @document.new
125
- doc.value_changed?.should be_false
125
+ doc.value_changed?.should be_falsey
126
126
  end
127
127
 
128
128
  it "should be false if the same ObjectId was assigned in String format" do
129
129
  @document.key :doc_id, ObjectId
130
130
 
131
131
  doc = @document.create!(:doc_id => BSON::ObjectId.new)
132
- doc.changed?.should be_false
132
+ doc.changed?.should be_falsey
133
133
  doc.doc_id = doc.doc_id.to_s
134
- doc.changed?.should be_false
134
+ doc.changed?.should be_falsey
135
135
  end
136
136
  end
137
137
 
@@ -164,14 +164,14 @@ describe "Dirty" do
164
164
  doc = @document.create(:phrase => 'Foo')
165
165
 
166
166
  doc.phrase << 'bar'
167
- doc.phrase_changed?.should be_false
167
+ doc.phrase_changed?.should be_falsey
168
168
 
169
169
  doc.phrase_will_change!
170
- doc.phrase_changed?.should be_true
170
+ doc.phrase_changed?.should be_truthy
171
171
  doc.phrase_change.should == ['Foobar', 'Foobar']
172
172
 
173
173
  doc.phrase << '!'
174
- doc.phrase_changed?.should be_true
174
+ doc.phrase_changed?.should be_truthy
175
175
  doc.phrase_change.should == ['Foobar', 'Foobar!']
176
176
  end
177
177
  end
@@ -190,7 +190,7 @@ describe "Dirty" do
190
190
 
191
191
  milestone = milestone_class.create(:name => 'Launch')
192
192
  milestone.project = project_class.create(:name => 'Harmony')
193
- milestone.changed?.should be_true
193
+ milestone.changed?.should be_truthy
194
194
  milestone.changed.should == %w(project_id)
195
195
  end
196
196
  end
@@ -204,11 +204,11 @@ describe "Dirty" do
204
204
  validated_doc = validated_class.new
205
205
  validated_doc.name = "I'm a changin"
206
206
  validated_doc.save
207
- validated_doc.changed?.should be_true
207
+ validated_doc.changed?.should be_truthy
208
208
 
209
209
  validated_doc.required = 1
210
210
  validated_doc.save
211
- validated_doc.changed?.should be_false
211
+ validated_doc.changed?.should be_falsey
212
212
  end
213
213
  end
214
214
 
@@ -224,7 +224,7 @@ describe "Dirty" do
224
224
  doc = @document.create(:a=>"b")
225
225
  doc.a = "c"
226
226
  doc.a = "b"
227
- doc.changed?.should be_false
227
+ doc.changed?.should be_falsey
228
228
  end
229
229
  end
230
230
 
@@ -233,7 +233,7 @@ describe "Dirty" do
233
233
  doc = @document.create(:a=>"b")
234
234
  doc.a = "c"
235
235
  doc.reset_a!
236
- doc.changed?.should be_false
236
+ doc.changed?.should be_falsey
237
237
  doc.a.should == "b"
238
238
  end
239
239
  it "should reset the attribute back to the original value after several changes" do
@@ -242,7 +242,7 @@ describe "Dirty" do
242
242
  doc.a = "d"
243
243
  doc.a = "e"
244
244
  doc.reset_a!
245
- doc.changed?.should be_false
245
+ doc.changed?.should be_falsey
246
246
  doc.a.should == "b"
247
247
  end
248
248
  end
@@ -275,21 +275,21 @@ describe "Dirty" do
275
275
 
276
276
  it "should track changes" do
277
277
  @duck.name = "hi"
278
- @duck.changed?.should be_true
278
+ @duck.changed?.should be_truthy
279
279
  end
280
280
 
281
281
  it "should clear changes when saved" do
282
282
  @duck.name = "hi"
283
- @duck.changed?.should be_true
283
+ @duck.changed?.should be_truthy
284
284
  @duck.save!
285
- @duck.changed?.should_not be_true
285
+ @duck.changed?.should_not be_truthy
286
286
  end
287
287
 
288
288
  it "should clear changes when the parent is saved" do
289
289
  @duck.name = "hi"
290
- @duck.changed?.should be_true
290
+ @duck.changed?.should be_truthy
291
291
  @doc.save!
292
- @duck.changed?.should_not be_true
292
+ @duck.changed?.should_not be_truthy
293
293
  end
294
294
 
295
295
  context "with nested embedded documents" do
@@ -302,14 +302,14 @@ describe "Dirty" do
302
302
 
303
303
  it "should track changes" do
304
304
  @dong.name = "hi"
305
- @dong.changed?.should be_true
305
+ @dong.changed?.should be_truthy
306
306
  end
307
307
 
308
308
  it "should clear changes when the root saves" do
309
309
  @dong.name = "hi"
310
- @dong.changed?.should be_true
310
+ @dong.changed?.should be_truthy
311
311
  @doc.save!
312
- @dong.changed?.should be_false
312
+ @dong.changed?.should be_falsey
313
313
  end
314
314
  end
315
315
  end