mongo_doc 0.6.26 → 0.6.27
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +14 -203
- data/Rakefile +0 -134
- data/lib/mongo_doc/collection.rb +4 -0
- data/lib/mongo_doc/finders.rb +1 -0
- data/lib/mongo_doc/timestamps.rb +4 -3
- data/lib/mongo_doc/version.rb +3 -0
- data/lib/mongo_doc.rb +0 -5
- metadata +25 -212
- data/.document +0 -5
- data/.gitignore +0 -8
- data/.rspec +0 -2
- data/.rvmrc +0 -1
- data/.watchr +0 -32
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -72
- data/HISTORY.md +0 -11
- data/VERSION +0 -1
- data/examples/simple_document.rb +0 -46
- data/examples/simple_object.rb +0 -34
- data/features/collections.feature +0 -9
- data/features/connection.feature +0 -13
- data/features/db_references.feature +0 -21
- data/features/embed_hash.feature +0 -16
- data/features/finders.feature +0 -76
- data/features/indexes.feature +0 -28
- data/features/mongodb.yml +0 -7
- data/features/mongodoc_base.feature +0 -128
- data/features/new_record.feature +0 -36
- data/features/partial_updates.feature +0 -95
- data/features/polymorphic_collections.feature +0 -16
- data/features/references.feature +0 -28
- data/features/removing_documents.feature +0 -68
- data/features/saving_an_object.feature +0 -15
- data/features/scopes.feature +0 -66
- data/features/step_definitions/collection_steps.rb +0 -17
- data/features/step_definitions/connection_steps.rb +0 -13
- data/features/step_definitions/document_steps.rb +0 -155
- data/features/step_definitions/documents.rb +0 -61
- data/features/step_definitions/embed_hash_steps.rb +0 -6
- data/features/step_definitions/field_steps.rb +0 -28
- data/features/step_definitions/finder_steps.rb +0 -15
- data/features/step_definitions/index_steps.rb +0 -10
- data/features/step_definitions/json_steps.rb +0 -9
- data/features/step_definitions/object_steps.rb +0 -50
- data/features/step_definitions/objects.rb +0 -24
- data/features/step_definitions/partial_update_steps.rb +0 -31
- data/features/step_definitions/query_steps.rb +0 -69
- data/features/step_definitions/removing_documents_steps.rb +0 -14
- data/features/step_definitions/scope_steps.rb +0 -18
- data/features/step_definitions/string_casting_steps.rb +0 -29
- data/features/step_definitions/util_steps.rb +0 -7
- data/features/string_casting.feature +0 -10
- data/features/support/support.rb +0 -12
- data/features/timestamps.feature +0 -14
- data/features/using_criteria.feature +0 -148
- data/mongo_doc.gemspec +0 -272
- data/mongodb.example.yml +0 -14
- data/perf/mongo_doc_object.rb +0 -83
- data/perf/mongo_document.rb +0 -84
- data/perf/ruby_driver.rb +0 -49
- data/script/console +0 -8
- data/spec/active_model_behavior.rb +0 -64
- data/spec/array_including_argument_matcher.rb +0 -62
- data/spec/associations/collection_proxy_spec.rb +0 -233
- data/spec/associations/document_proxy_spec.rb +0 -45
- data/spec/associations/hash_proxy_spec.rb +0 -181
- data/spec/associations/proxy_base_spec.rb +0 -92
- data/spec/associations_spec.rb +0 -218
- data/spec/attributes_accessor_spec.rb +0 -39
- data/spec/attributes_spec.rb +0 -184
- data/spec/bson_matchers.rb +0 -54
- data/spec/bson_spec.rb +0 -196
- data/spec/collection_spec.rb +0 -169
- data/spec/connection_spec.rb +0 -169
- data/spec/contexts/ids_spec.rb +0 -49
- data/spec/contexts/mongo_spec.rb +0 -241
- data/spec/contexts_spec.rb +0 -56
- data/spec/criteria/optional_spec.rb +0 -26
- data/spec/criteria_spec.rb +0 -73
- data/spec/cursor_spec.rb +0 -91
- data/spec/database_cleaner_spec.rb +0 -24
- data/spec/document_ext.rb +0 -9
- data/spec/document_spec.rb +0 -569
- data/spec/embedded_save_spec.rb +0 -73
- data/spec/ext_spec.rb +0 -100
- data/spec/finders_spec.rb +0 -61
- data/spec/hash_matchers.rb +0 -29
- data/spec/index_spec.rb +0 -79
- data/spec/matchers_spec.rb +0 -342
- data/spec/mongodb.yml +0 -6
- data/spec/mongodb_pairs.yml +0 -8
- data/spec/new_record_spec.rb +0 -128
- data/spec/polymorphic_collection_spec.rb +0 -47
- data/spec/references_many_spec.rb +0 -214
- data/spec/references_spec.rb +0 -121
- data/spec/root_spec.rb +0 -41
- data/spec/scope_spec.rb +0 -88
- data/spec/spec_helper.rb +0 -16
- data/spec/timestamps_spec.rb +0 -154
- data/spec/update_spec.rb +0 -167
- data/spec/validations_spec.rb +0 -30
data/spec/new_record_spec.rb
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "MongoDoc::Document _id and #new_record?" do
|
4
|
-
class Child
|
5
|
-
include MongoDoc::Document
|
6
|
-
end
|
7
|
-
|
8
|
-
class Parent
|
9
|
-
include MongoDoc::Document
|
10
|
-
|
11
|
-
embed :child
|
12
|
-
embed_many :children
|
13
|
-
|
14
|
-
attr_accessor :data
|
15
|
-
|
16
|
-
validates_presence_of :data
|
17
|
-
end
|
18
|
-
|
19
|
-
let(:id) { 'id' }
|
20
|
-
let(:collection) { stub('collection', :save => id) }
|
21
|
-
let(:child) { Child.new }
|
22
|
-
|
23
|
-
context "as a embed child" do
|
24
|
-
it "when added to the parent is a new record" do
|
25
|
-
Parent.new(:data => 'data', :child => child)
|
26
|
-
child.should be_new_record
|
27
|
-
end
|
28
|
-
|
29
|
-
context "saving" do
|
30
|
-
before do
|
31
|
-
Parent.stub(:collection).and_return(collection)
|
32
|
-
end
|
33
|
-
|
34
|
-
context "#save" do
|
35
|
-
it "when saved is not a new record" do
|
36
|
-
parent = Parent.new(:data => 'data', :child => child)
|
37
|
-
parent.save
|
38
|
-
child.should_not be_new_record
|
39
|
-
end
|
40
|
-
|
41
|
-
it "if parent is invalid, remains a new record" do
|
42
|
-
parent = Parent.new(:child => child)
|
43
|
-
parent.save
|
44
|
-
child.should be_new_record
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "#save!" do
|
49
|
-
it "when saved is not a new record" do
|
50
|
-
parent = Parent.new(:data => 'data', :child => child)
|
51
|
-
parent.save!
|
52
|
-
child.should_not be_new_record
|
53
|
-
end
|
54
|
-
|
55
|
-
it "if parent is invalid, remains a new record" do
|
56
|
-
parent = Parent.new(:child => child)
|
57
|
-
parent.save! rescue nil
|
58
|
-
child.should be_new_record
|
59
|
-
end
|
60
|
-
|
61
|
-
it "when db error is raised, remains a new record" do
|
62
|
-
collection.stub(:save).and_raise(Mongo::OperationFailure)
|
63
|
-
parent = Parent.new(:data => 'data', :child => child)
|
64
|
-
expect do
|
65
|
-
parent.save!
|
66
|
-
end.should raise_error(Mongo::OperationFailure)
|
67
|
-
child.should be_new_record
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context "as a embed_many child" do
|
74
|
-
it "when added to the parent is a new record" do
|
75
|
-
parent = Parent.new(:data => 'data')
|
76
|
-
parent.children << child
|
77
|
-
child.should be_new_record
|
78
|
-
end
|
79
|
-
|
80
|
-
context "saving" do
|
81
|
-
before do
|
82
|
-
Parent.stub(:collection).and_return(collection)
|
83
|
-
end
|
84
|
-
|
85
|
-
context "#save" do
|
86
|
-
it "when saved is not a new record" do
|
87
|
-
parent = Parent.new(:data => 'data')
|
88
|
-
parent.children << child
|
89
|
-
parent.save
|
90
|
-
child.should_not be_new_record
|
91
|
-
end
|
92
|
-
|
93
|
-
it "if parent is invalid, remains a new record" do
|
94
|
-
parent = Parent.new
|
95
|
-
parent.children << child
|
96
|
-
parent.save
|
97
|
-
child.should be_new_record
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
context "#save!" do
|
102
|
-
it "when saved is not a new record" do
|
103
|
-
parent = Parent.new(:data => 'data')
|
104
|
-
parent.children << child
|
105
|
-
parent.save!
|
106
|
-
child.should_not be_new_record
|
107
|
-
end
|
108
|
-
|
109
|
-
it "if parent is invalid, remains a new record" do
|
110
|
-
parent = Parent.new
|
111
|
-
parent.children << child
|
112
|
-
parent.save! rescue nil
|
113
|
-
child.should be_new_record
|
114
|
-
end
|
115
|
-
|
116
|
-
it "when db error is raised, remains a new record" do
|
117
|
-
collection.stub(:save).and_raise(Mongo::OperationFailure)
|
118
|
-
parent = Parent.new(:data => 'data')
|
119
|
-
parent.children << child
|
120
|
-
expect do
|
121
|
-
parent.save!
|
122
|
-
end.should raise_error(Mongo::OperationFailure)
|
123
|
-
child.should be_new_record
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe MongoDoc::PolymorphicCollection do
|
4
|
-
|
5
|
-
class BaseCollectionName
|
6
|
-
include MongoDoc::Document
|
7
|
-
|
8
|
-
attr_accessor :base
|
9
|
-
end
|
10
|
-
|
11
|
-
class SubCollectionName < BaseCollectionName
|
12
|
-
attr_accessor :sub
|
13
|
-
end
|
14
|
-
|
15
|
-
class OverriddenCollectionName < BaseCollectionName
|
16
|
-
collection_name :overridden
|
17
|
-
attr_accessor :over
|
18
|
-
end
|
19
|
-
|
20
|
-
class TwoSubCollectionName < OverriddenCollectionName
|
21
|
-
attr_accessor :two_sub
|
22
|
-
end
|
23
|
-
|
24
|
-
describe BaseCollectionName do
|
25
|
-
it "uses the default collection_name for base doc" do
|
26
|
-
BaseCollectionName.collection_name.should == BaseCollectionName.to_s.tableize.gsub('/', '.')
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe SubCollectionName do
|
31
|
-
it "uses the base's collection_name for the derived doc" do
|
32
|
-
SubCollectionName.collection_name.should == BaseCollectionName.to_s.tableize.gsub('/', '.')
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe OverriddenCollectionName do
|
37
|
-
it "sets the collection_name to the overridden name" do
|
38
|
-
OverriddenCollectionName.collection_name.should == 'overridden'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe TwoSubCollectionName do
|
43
|
-
it "climbs the inheritance chain looking for the collection name" do
|
44
|
-
TwoSubCollectionName.collection_name.should == 'overridden'
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,214 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe MongoDoc::ReferencesMany do
|
4
|
-
class PostalAddress
|
5
|
-
include MongoDoc::Document
|
6
|
-
|
7
|
-
attr_accessor :state
|
8
|
-
end
|
9
|
-
|
10
|
-
context "Simple Reference" do
|
11
|
-
class PersonSimple
|
12
|
-
include MongoDoc::Document
|
13
|
-
|
14
|
-
references_many :postal_addresses
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:person) { PersonSimple.new }
|
18
|
-
subject { person }
|
19
|
-
|
20
|
-
context "Object accessor" do
|
21
|
-
it { should respond_to(:postal_addresses) }
|
22
|
-
it { should respond_to(:postal_addresses=) }
|
23
|
-
|
24
|
-
it "is not part of the persistent key set" do
|
25
|
-
PersonSimple._keys.should_not include('postal_addresses')
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context "Object Id accessor" do
|
30
|
-
it { should respond_to(:postal_address_ids) }
|
31
|
-
it { should respond_to(:postal_address_ids=) }
|
32
|
-
|
33
|
-
it "is part of the persistent key set" do
|
34
|
-
PersonSimple._keys.should include('postal_address_ids')
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context "setting the ids" do
|
39
|
-
let(:postal_address) { PostalAddress.new(:_id => BSON::ObjectID.new) }
|
40
|
-
|
41
|
-
before do
|
42
|
-
person.postal_addresses = [postal_address]
|
43
|
-
end
|
44
|
-
|
45
|
-
context "to nil" do
|
46
|
-
before do
|
47
|
-
person.postal_address_ids = nil
|
48
|
-
end
|
49
|
-
|
50
|
-
its(:postal_address_ids) { should == [] }
|
51
|
-
its(:postal_addresses) { should == [] }
|
52
|
-
end
|
53
|
-
|
54
|
-
context "to []" do
|
55
|
-
before do
|
56
|
-
person.postal_address_ids = []
|
57
|
-
end
|
58
|
-
|
59
|
-
its(:postal_addresses) { should == [] }
|
60
|
-
end
|
61
|
-
|
62
|
-
context "to strings" do
|
63
|
-
before do
|
64
|
-
person.postal_address_ids = [postal_address._id.to_s]
|
65
|
-
end
|
66
|
-
|
67
|
-
its(:postal_address_ids) { should == [postal_address._id] }
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context "Named Reference" do
|
73
|
-
class PersonNamed
|
74
|
-
include MongoDoc::Document
|
75
|
-
|
76
|
-
references_many :postal_addresses, :as => :known_addresses
|
77
|
-
end
|
78
|
-
|
79
|
-
let(:person) { PersonNamed.new }
|
80
|
-
|
81
|
-
subject { person }
|
82
|
-
|
83
|
-
context "Object accessor" do
|
84
|
-
it { should respond_to(:known_addresses) }
|
85
|
-
it { should respond_to(:known_addresses=) }
|
86
|
-
|
87
|
-
it "is not part of the persistent key set" do
|
88
|
-
PersonNamed._keys.should_not include('known_addresses')
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
context "Object Id accessor" do
|
93
|
-
it { should respond_to(:known_address_ids) }
|
94
|
-
it { should respond_to(:known_address_ids=) }
|
95
|
-
|
96
|
-
it "is part of the persistent key set" do
|
97
|
-
PersonNamed._keys.should include('known_address_ids')
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
context "setting the ids" do
|
102
|
-
let(:address) { PostalAddress.new(:_id => BSON::ObjectID.new) }
|
103
|
-
|
104
|
-
before do
|
105
|
-
person.known_addresses = [address]
|
106
|
-
end
|
107
|
-
|
108
|
-
context "to nil" do
|
109
|
-
before do
|
110
|
-
person.known_address_ids = nil
|
111
|
-
end
|
112
|
-
|
113
|
-
its(:known_address_ids) { should == [] }
|
114
|
-
its(:known_addresses) { should == [] }
|
115
|
-
end
|
116
|
-
|
117
|
-
context "to []" do
|
118
|
-
before do
|
119
|
-
person.known_address_ids = []
|
120
|
-
end
|
121
|
-
|
122
|
-
its(:known_addresses) { should == [] }
|
123
|
-
end
|
124
|
-
|
125
|
-
context "to strings" do
|
126
|
-
before do
|
127
|
-
person.known_address_ids = [address._id.to_s]
|
128
|
-
end
|
129
|
-
|
130
|
-
its(:known_address_ids) { should == [address._id] }
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
context "DBRef reference" do
|
136
|
-
class PersonDBRef
|
137
|
-
include MongoDoc::Document
|
138
|
-
|
139
|
-
references_many :as_ref => :addresses
|
140
|
-
end
|
141
|
-
|
142
|
-
let(:address) { PostalAddress.new(:_id => BSON::ObjectID.new) }
|
143
|
-
let(:person) { PersonDBRef.new }
|
144
|
-
|
145
|
-
subject { person }
|
146
|
-
|
147
|
-
context "Object accessor" do
|
148
|
-
it { should respond_to(:addresses) }
|
149
|
-
it { should respond_to(:addresses=) }
|
150
|
-
|
151
|
-
it "is not part of the persistent key set" do
|
152
|
-
PersonDBRef._keys.should_not include('addresses')
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
context "DBRef accessor" do
|
157
|
-
it { should respond_to(:address_refs) }
|
158
|
-
it { should respond_to(:address_refs=) }
|
159
|
-
|
160
|
-
it "is part of the persistent key set" do
|
161
|
-
PersonDBRef._keys.should include('address_refs')
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
context "setting the collection" do
|
166
|
-
before do
|
167
|
-
person.addresses = [address]
|
168
|
-
end
|
169
|
-
|
170
|
-
it "sets the refs to an array of refs]" do
|
171
|
-
person.address_refs.first.namespace.should == PostalAddress.collection_name
|
172
|
-
person.address_refs.first.object_id.should == address._id
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
context "setting the refs" do
|
177
|
-
before do
|
178
|
-
person.addresses = [address]
|
179
|
-
end
|
180
|
-
|
181
|
-
context "to nil" do
|
182
|
-
before do
|
183
|
-
person.address_refs = nil
|
184
|
-
end
|
185
|
-
|
186
|
-
it "sets the refs to []" do
|
187
|
-
person.address_refs.should == []
|
188
|
-
end
|
189
|
-
|
190
|
-
its(:addresses) { should == [] }
|
191
|
-
end
|
192
|
-
|
193
|
-
context "to []" do
|
194
|
-
before do
|
195
|
-
person.address_refs = []
|
196
|
-
end
|
197
|
-
|
198
|
-
its(:addresses) { should == [] }
|
199
|
-
end
|
200
|
-
|
201
|
-
context "to an array of references" do
|
202
|
-
let(:dbref) { ::BSON::DBRef.new(PostalAddress.collection_name, address._id) }
|
203
|
-
|
204
|
-
before do
|
205
|
-
person.address_refs = [dbref]
|
206
|
-
end
|
207
|
-
|
208
|
-
it "sets the addresses to nil" do
|
209
|
-
person.instance_variable_get('@addresses').should be_nil
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
data/spec/references_spec.rb
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe MongoDoc::References do
|
4
|
-
class PostalAddress
|
5
|
-
include MongoDoc::Document
|
6
|
-
|
7
|
-
attr_accessor :state
|
8
|
-
end
|
9
|
-
|
10
|
-
context "Simple Reference" do
|
11
|
-
class SimplePerson
|
12
|
-
include MongoDoc::Document
|
13
|
-
|
14
|
-
references :postal_address
|
15
|
-
end
|
16
|
-
|
17
|
-
subject { SimplePerson.new }
|
18
|
-
|
19
|
-
context "Object accessor" do
|
20
|
-
it { should respond_to(:postal_address) }
|
21
|
-
it { should respond_to(:postal_address=) }
|
22
|
-
|
23
|
-
it "is not part of the persistent key set" do
|
24
|
-
SimplePerson._keys.should_not include(:postal_address)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "Object Id accessor" do
|
29
|
-
it { should respond_to(:postal_address_id) }
|
30
|
-
it { should respond_to(:postal_address_id=) }
|
31
|
-
|
32
|
-
it "is part of the persistent key set" do
|
33
|
-
SimplePerson._keys.should include(:postal_address_id)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "setting the id" do
|
38
|
-
let(:postal_address) { PostalAddress.new(:_id => BSON::ObjectID.new) }
|
39
|
-
|
40
|
-
it "resets the object to nil" do
|
41
|
-
subject.postal_address = postal_address
|
42
|
-
subject.postal_address_id = nil
|
43
|
-
subject.postal_address.should be_nil
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "Named Reference" do
|
49
|
-
class NamedPerson
|
50
|
-
include MongoDoc::Document
|
51
|
-
|
52
|
-
references :postal_address, :as => :work_address
|
53
|
-
end
|
54
|
-
|
55
|
-
subject { NamedPerson.new }
|
56
|
-
|
57
|
-
context "Object accessor" do
|
58
|
-
it { should respond_to(:work_address) }
|
59
|
-
it { should respond_to(:work_address=) }
|
60
|
-
|
61
|
-
it "is not part of the persistent key set" do
|
62
|
-
NamedPerson._keys.should_not include(:work_address)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context "Object Id accessor" do
|
67
|
-
it { should respond_to(:work_address_id) }
|
68
|
-
it { should respond_to(:work_address_id=) }
|
69
|
-
|
70
|
-
it "is part of the persistent key set" do
|
71
|
-
NamedPerson._keys.should include(:work_address_id)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context "DBRef Reference" do
|
77
|
-
class DBRefPerson
|
78
|
-
include MongoDoc::Document
|
79
|
-
|
80
|
-
references :as_ref => :address
|
81
|
-
end
|
82
|
-
|
83
|
-
let(:address) { PostalAddress.new(:_id => BSON::ObjectID.new) }
|
84
|
-
subject { DBRefPerson.new }
|
85
|
-
|
86
|
-
context "Object accessor" do
|
87
|
-
it { should respond_to(:address) }
|
88
|
-
it { should respond_to(:address=) }
|
89
|
-
|
90
|
-
it "is not part of the persistent key set" do
|
91
|
-
DBRefPerson._keys.should_not include(:address)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context "DBRef accessor" do
|
96
|
-
it { should respond_to(:address_ref) }
|
97
|
-
it { should respond_to(:address_ref=) }
|
98
|
-
|
99
|
-
it "is part of the persistent key set" do
|
100
|
-
DBRefPerson._keys.should include(:address_ref)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context "setting the object" do
|
105
|
-
it "sets the reference" do
|
106
|
-
subject.address = address
|
107
|
-
subject.address_ref.namespace.should == PostalAddress.collection_name
|
108
|
-
subject.address_ref.object_id.should == address._id
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
context "setting the reference" do
|
113
|
-
|
114
|
-
it "resets the object to nil" do
|
115
|
-
subject.address = address
|
116
|
-
subject.address_ref = nil
|
117
|
-
subject.address.should be_nil
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
data/spec/root_spec.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "MongoDoc::Root" do
|
4
|
-
class RootTest
|
5
|
-
include MongoDoc::Root
|
6
|
-
attr_accessor_with_default(:_associations) {[]}
|
7
|
-
attr_accessor :association
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:doc) { RootTest.new }
|
11
|
-
|
12
|
-
context "cascade properties" do
|
13
|
-
let(:prop_val) { stub }
|
14
|
-
|
15
|
-
%w(_modifier_path _root _selector_path).each do |prop|
|
16
|
-
it "sets the #{prop}" do
|
17
|
-
doc.send("#{prop}=", prop_val)
|
18
|
-
doc.send(prop).should == prop_val
|
19
|
-
end
|
20
|
-
|
21
|
-
it "sets the prop on any associations" do
|
22
|
-
doc.association = stub
|
23
|
-
doc.association.should_receive("#{prop}=").with(prop_val)
|
24
|
-
doc._associations = ['association']
|
25
|
-
doc.send("#{prop}=", prop_val)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "#_selector_path" do
|
31
|
-
it "defaults to ''" do
|
32
|
-
doc._selector_path.should == ''
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "#_modifier_path" do
|
37
|
-
it "defaults to ''" do
|
38
|
-
doc._modifier_path.should == ''
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/spec/scope_spec.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe MongoDoc::Scope do
|
4
|
-
|
5
|
-
module Extension
|
6
|
-
def extension_module_method
|
7
|
-
"extension module method"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class ScopeTest
|
12
|
-
include MongoDoc::Document
|
13
|
-
|
14
|
-
attr_accessor :active
|
15
|
-
attr_accessor :count
|
16
|
-
|
17
|
-
scope :active, where(:active => true)
|
18
|
-
scope :count_lte_one, where(:count.lte => 1) do
|
19
|
-
def extension_method
|
20
|
-
"extension method"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
scope :count_gt_one, where(:count.gt => 1), :extend => Extension
|
24
|
-
scope :at_least_count, lambda {|count| where(:count.gt => count)}
|
25
|
-
end
|
26
|
-
|
27
|
-
context ".scope" do
|
28
|
-
it "adds the named scope to the hash of scopes" do
|
29
|
-
ScopeTest.scopes.should have_key(:active)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "creates a class method for the named scope" do
|
33
|
-
ScopeTest.should respond_to(:active)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "accessing a named scope" do
|
38
|
-
it "is a criteria proxy" do
|
39
|
-
MongoDoc::Scope::CriteriaProxy.should === ScopeTest.active
|
40
|
-
end
|
41
|
-
|
42
|
-
it "responds like a criteria" do
|
43
|
-
ScopeTest.active.should respond_to(:selector)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "has set the conditions on the criteria" do
|
47
|
-
ScopeTest.active.selector.should has_entry(:active => true)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "sets the association extension by block" do
|
51
|
-
ScopeTest.count_lte_one.extension_method.should == "extension method"
|
52
|
-
end
|
53
|
-
|
54
|
-
it "sets the association extension by :extend" do
|
55
|
-
ScopeTest.count_gt_one.extension_module_method.should == "extension module method"
|
56
|
-
end
|
57
|
-
|
58
|
-
context "when using a lambda" do
|
59
|
-
it "accepts parameters to the criteria" do
|
60
|
-
ScopeTest.at_least_count(3).selector.should has_entry(:count => {'$gt' => 3})
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "chained scopes" do
|
66
|
-
it "is a criteria proxy" do
|
67
|
-
MongoDoc::Scope::CriteriaProxy.should === ScopeTest.active.count_gt_one
|
68
|
-
end
|
69
|
-
|
70
|
-
it "responds like a criteria" do
|
71
|
-
ScopeTest.active.count_gt_one.should respond_to(:selector)
|
72
|
-
end
|
73
|
-
|
74
|
-
it "merges the criteria" do
|
75
|
-
ScopeTest.active.count_gt_one.selector.should have_entries(:count => {'$gt' => 1}, :active => true)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "chains with other criteria" do
|
79
|
-
ScopeTest.active.where(:count => 1).selector.should have_entries(:count => 1, :active => true)
|
80
|
-
end
|
81
|
-
|
82
|
-
let(:id) { BSON::ObjectID.new }
|
83
|
-
it "chains with id" do
|
84
|
-
ScopeTest.active.id(id).selector.should have_entries(:active => true, :_id => id)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
data/spec/spec_helper.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
-
require 'mongo_doc'
|
4
|
-
require 'rspec'
|
5
|
-
require 'rspec/autorun'
|
6
|
-
require 'bson_matchers'
|
7
|
-
require 'hash_matchers'
|
8
|
-
require 'array_including_argument_matcher'
|
9
|
-
require 'active_model_behavior'
|
10
|
-
require 'document_ext'
|
11
|
-
|
12
|
-
RSpec.configure do |config|
|
13
|
-
config.include(BsonMatchers)
|
14
|
-
config.include(HashMatchers)
|
15
|
-
config.include(ActiveModelBehavior)
|
16
|
-
end
|