mongoid 1.2.12 → 1.2.13
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/mongoid.rb +1 -0
- data/lib/mongoid/commands/delete.rb +1 -1
- data/lib/mongoid/commands/destroy.rb +1 -1
- data/lib/mongoid/components.rb +1 -0
- data/lib/mongoid/document.rb +0 -17
- data/lib/mongoid/state.rb +32 -0
- data/mongoid.gemspec +4 -1
- data/spec/integration/mongoid/document_spec.rb +6 -0
- data/spec/unit/mongoid/commands/delete_spec.rb +6 -3
- data/spec/unit/mongoid/commands/destroy_spec.rb +6 -3
- data/spec/unit/mongoid/document_spec.rb +0 -45
- data/spec/unit/mongoid/state_spec.rb +83 -0
- metadata +5 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.13
|
data/lib/mongoid.rb
CHANGED
data/lib/mongoid/components.rb
CHANGED
data/lib/mongoid/document.rb
CHANGED
@@ -175,23 +175,6 @@ module Mongoid #:nodoc:
|
|
175
175
|
"#<#{self.class.name} _id: #{id}, #{attrs}>"
|
176
176
|
end
|
177
177
|
|
178
|
-
# Returns true is the +Document+ has not been persisted to the database,
|
179
|
-
# false if it has. This is determined by the variable @new_record
|
180
|
-
# and NOT if the object has an id.
|
181
|
-
def new_record?
|
182
|
-
@new_record == true
|
183
|
-
end
|
184
|
-
|
185
|
-
# Sets the new_record boolean - used after document is saved.
|
186
|
-
def new_record=(saved)
|
187
|
-
@new_record = saved
|
188
|
-
end
|
189
|
-
|
190
|
-
# Checks if the document has been saved to the database.
|
191
|
-
def persisted?
|
192
|
-
!new_record?
|
193
|
-
end
|
194
|
-
|
195
178
|
# Set the changed state of the +Document+ then notify observers that it has changed.
|
196
179
|
#
|
197
180
|
# Example:
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Mongoid #:nodoc:
|
3
|
+
module State #:nodoc:
|
4
|
+
# Returns true if the +Document+ has not been persisted to the database,
|
5
|
+
# false if it has. This is determined by the variable @new_record
|
6
|
+
# and NOT if the object has an id.
|
7
|
+
def new_record?
|
8
|
+
@new_record == true
|
9
|
+
end
|
10
|
+
|
11
|
+
# Sets the new_record boolean - used after document is saved.
|
12
|
+
def new_record=(saved)
|
13
|
+
@new_record = saved
|
14
|
+
end
|
15
|
+
|
16
|
+
# Checks if the document has been saved to the database.
|
17
|
+
def persisted?
|
18
|
+
!new_record?
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns true if the +Document+ has been succesfully destroyed, and false if it hasn't.
|
22
|
+
# This is determined by the variable @destroyed and NOT by checking the database.
|
23
|
+
def destroyed?
|
24
|
+
@destroyed == true
|
25
|
+
end
|
26
|
+
|
27
|
+
# Sets the destroyed boolean - used after document is destroyed.
|
28
|
+
def destroyed=(destroyed)
|
29
|
+
@destroyed = destroyed && true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/mongoid.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongoid}
|
8
|
-
s.version = "1.2.
|
8
|
+
s.version = "1.2.13"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Durran Jordan"]
|
@@ -114,6 +114,7 @@ Gem::Specification.new do |s|
|
|
114
114
|
"lib/mongoid/memoization.rb",
|
115
115
|
"lib/mongoid/named_scope.rb",
|
116
116
|
"lib/mongoid/scope.rb",
|
117
|
+
"lib/mongoid/state.rb",
|
117
118
|
"lib/mongoid/timestamps.rb",
|
118
119
|
"lib/mongoid/versioning.rb",
|
119
120
|
"mongoid.gemspec",
|
@@ -232,6 +233,7 @@ Gem::Specification.new do |s|
|
|
232
233
|
"spec/unit/mongoid/memoization_spec.rb",
|
233
234
|
"spec/unit/mongoid/named_scope_spec.rb",
|
234
235
|
"spec/unit/mongoid/scope_spec.rb",
|
236
|
+
"spec/unit/mongoid/state_spec.rb",
|
235
237
|
"spec/unit/mongoid/timestamps_spec.rb",
|
236
238
|
"spec/unit/mongoid/versioning_spec.rb",
|
237
239
|
"spec/unit/mongoid_spec.rb"
|
@@ -355,6 +357,7 @@ Gem::Specification.new do |s|
|
|
355
357
|
"spec/unit/mongoid/memoization_spec.rb",
|
356
358
|
"spec/unit/mongoid/named_scope_spec.rb",
|
357
359
|
"spec/unit/mongoid/scope_spec.rb",
|
360
|
+
"spec/unit/mongoid/state_spec.rb",
|
358
361
|
"spec/unit/mongoid/timestamps_spec.rb",
|
359
362
|
"spec/unit/mongoid/versioning_spec.rb",
|
360
363
|
"spec/unit/mongoid_spec.rb"
|
@@ -121,6 +121,12 @@ describe Mongoid::Document do
|
|
121
121
|
lambda { Person.find(@person.id) }.should raise_error
|
122
122
|
end
|
123
123
|
|
124
|
+
it "marks the document as destroyed" do
|
125
|
+
@person.should_not be_destroyed
|
126
|
+
@person.destroy
|
127
|
+
@person.should be_destroyed
|
128
|
+
end
|
129
|
+
|
124
130
|
end
|
125
131
|
|
126
132
|
context "on an embedded document" do
|
@@ -14,6 +14,12 @@ describe Mongoid::Commands::Delete do
|
|
14
14
|
Mongoid::Commands::Delete.execute(@document)
|
15
15
|
end
|
16
16
|
|
17
|
+
it "sets the destroyed flag to true" do
|
18
|
+
@collection.expects(:remove).with({ :_id => @document.id }).returns(true)
|
19
|
+
@document.expects(:destroyed=).with(true)
|
20
|
+
Mongoid::Commands::Delete.execute(@document)
|
21
|
+
end
|
22
|
+
|
17
23
|
context "when the document is embedded" do
|
18
24
|
|
19
25
|
before do
|
@@ -27,9 +33,6 @@ describe Mongoid::Commands::Delete do
|
|
27
33
|
Mongoid::Commands::Delete.execute(@address)
|
28
34
|
@parent.addresses.should be_empty
|
29
35
|
end
|
30
|
-
|
31
36
|
end
|
32
|
-
|
33
37
|
end
|
34
|
-
|
35
38
|
end
|
@@ -23,6 +23,12 @@ describe Mongoid::Commands::Destroy do
|
|
23
23
|
Mongoid::Commands::Destroy.execute(@document)
|
24
24
|
end
|
25
25
|
|
26
|
+
it "sets the destroy flag on the document" do
|
27
|
+
@collection.expects(:remove).with({ :_id => @document.id }).returns(true)
|
28
|
+
@document.expects(:destroyed=).with(true)
|
29
|
+
Mongoid::Commands::Destroy.execute(@document)
|
30
|
+
end
|
31
|
+
|
26
32
|
context "when the document is embedded" do
|
27
33
|
|
28
34
|
before do
|
@@ -39,9 +45,6 @@ describe Mongoid::Commands::Destroy do
|
|
39
45
|
Mongoid::Commands::Destroy.execute(@address)
|
40
46
|
@parent.addresses.should be_empty
|
41
47
|
end
|
42
|
-
|
43
48
|
end
|
44
|
-
|
45
49
|
end
|
46
|
-
|
47
50
|
end
|
@@ -471,45 +471,6 @@ describe Mongoid::Document do
|
|
471
471
|
|
472
472
|
end
|
473
473
|
|
474
|
-
describe "#new_record?" do
|
475
|
-
|
476
|
-
context "when the object has been saved" do
|
477
|
-
|
478
|
-
before do
|
479
|
-
@person = Person.new(:_id => "1")
|
480
|
-
end
|
481
|
-
|
482
|
-
it "returns false" do
|
483
|
-
@person.new_record?.should be_false
|
484
|
-
end
|
485
|
-
|
486
|
-
end
|
487
|
-
|
488
|
-
context "when the object has not been saved" do
|
489
|
-
|
490
|
-
before do
|
491
|
-
@person = Person.new
|
492
|
-
end
|
493
|
-
|
494
|
-
it "returns true" do
|
495
|
-
@person.new_record?.should be_true
|
496
|
-
end
|
497
|
-
|
498
|
-
end
|
499
|
-
|
500
|
-
end
|
501
|
-
|
502
|
-
describe "#persisted?" do
|
503
|
-
|
504
|
-
before do
|
505
|
-
@person = Person.new
|
506
|
-
end
|
507
|
-
|
508
|
-
it "delegates to new_record?" do
|
509
|
-
@person.persisted?.should be_false
|
510
|
-
end
|
511
|
-
end
|
512
|
-
|
513
474
|
describe "#_parent" do
|
514
475
|
|
515
476
|
before do
|
@@ -600,9 +561,7 @@ describe Mongoid::Document do
|
|
600
561
|
@person.remove(@name)
|
601
562
|
@person.name.should be_nil
|
602
563
|
end
|
603
|
-
|
604
564
|
end
|
605
|
-
|
606
565
|
end
|
607
566
|
|
608
567
|
describe "#_root" do
|
@@ -620,7 +579,6 @@ describe Mongoid::Document do
|
|
620
579
|
it "returns self" do
|
621
580
|
@person._root.should == @person
|
622
581
|
end
|
623
|
-
|
624
582
|
end
|
625
583
|
|
626
584
|
context "when document is embedded one level" do
|
@@ -628,7 +586,6 @@ describe Mongoid::Document do
|
|
628
586
|
it "returns the parent" do
|
629
587
|
@phone_number._root.should == @person
|
630
588
|
end
|
631
|
-
|
632
589
|
end
|
633
590
|
|
634
591
|
context "when document is embedded multiple levels" do
|
@@ -636,9 +593,7 @@ describe Mongoid::Document do
|
|
636
593
|
it "returns the top level parent" do
|
637
594
|
@country_code._root.should == @person
|
638
595
|
end
|
639
|
-
|
640
596
|
end
|
641
|
-
|
642
597
|
end
|
643
598
|
|
644
599
|
describe ".store_in" do
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Mongoid::State do
|
4
|
+
|
5
|
+
describe "#new_record?" do
|
6
|
+
|
7
|
+
context "when the object has been saved" do
|
8
|
+
|
9
|
+
before do
|
10
|
+
@person = Person.new(:_id => "1")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns false" do
|
14
|
+
@person.new_record?.should be_false
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when the object has not been saved" do
|
20
|
+
|
21
|
+
before do
|
22
|
+
@person = Person.new
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns true" do
|
26
|
+
@person.new_record?.should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#persisted?" do
|
34
|
+
|
35
|
+
before do
|
36
|
+
@person = Person.new
|
37
|
+
end
|
38
|
+
|
39
|
+
it "delegates to new_record?" do
|
40
|
+
@person.persisted?.should be_false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "destroyed?" do
|
45
|
+
|
46
|
+
before do
|
47
|
+
@person = Person.new
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when destroyed is true" do
|
51
|
+
|
52
|
+
before do
|
53
|
+
@person.destroyed = true
|
54
|
+
end
|
55
|
+
|
56
|
+
it "returns true" do
|
57
|
+
@person.destroyed?.should be_true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when destroyed is false" do
|
62
|
+
|
63
|
+
before do
|
64
|
+
@person.destroyed = false
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns true" do
|
68
|
+
@person.destroyed?.should be_false
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "when destroyed is nil" do
|
73
|
+
|
74
|
+
before do
|
75
|
+
@person.destroyed = nil
|
76
|
+
end
|
77
|
+
|
78
|
+
it "returns false" do
|
79
|
+
@person.destroyed?.should be_false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 1.2.
|
8
|
+
- 13
|
9
|
+
version: 1.2.13
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Durran Jordan
|
@@ -208,6 +208,7 @@ files:
|
|
208
208
|
- lib/mongoid/memoization.rb
|
209
209
|
- lib/mongoid/named_scope.rb
|
210
210
|
- lib/mongoid/scope.rb
|
211
|
+
- lib/mongoid/state.rb
|
211
212
|
- lib/mongoid/timestamps.rb
|
212
213
|
- lib/mongoid/versioning.rb
|
213
214
|
- mongoid.gemspec
|
@@ -326,6 +327,7 @@ files:
|
|
326
327
|
- spec/unit/mongoid/memoization_spec.rb
|
327
328
|
- spec/unit/mongoid/named_scope_spec.rb
|
328
329
|
- spec/unit/mongoid/scope_spec.rb
|
330
|
+
- spec/unit/mongoid/state_spec.rb
|
329
331
|
- spec/unit/mongoid/timestamps_spec.rb
|
330
332
|
- spec/unit/mongoid/versioning_spec.rb
|
331
333
|
- spec/unit/mongoid_spec.rb
|
@@ -473,6 +475,7 @@ test_files:
|
|
473
475
|
- spec/unit/mongoid/memoization_spec.rb
|
474
476
|
- spec/unit/mongoid/named_scope_spec.rb
|
475
477
|
- spec/unit/mongoid/scope_spec.rb
|
478
|
+
- spec/unit/mongoid/state_spec.rb
|
476
479
|
- spec/unit/mongoid/timestamps_spec.rb
|
477
480
|
- spec/unit/mongoid/versioning_spec.rb
|
478
481
|
- spec/unit/mongoid_spec.rb
|