mongo_doc 0.6.26 → 0.6.27
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.
- 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
@@ -1,64 +0,0 @@
|
|
1
|
-
module ActiveModelBehavior
|
2
|
-
share_as :AnActiveModel do
|
3
|
-
def be_a_boolean
|
4
|
-
::Rspec::Matchers::Matcher.new :be_a_boolean do
|
5
|
-
match do |value|
|
6
|
-
[ true, false ].include?( value )
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
it { should respond_to(:to_model) }
|
12
|
-
it { should respond_to(:to_key) }
|
13
|
-
it { should respond_to(:to_param) }
|
14
|
-
|
15
|
-
it { should respond_to(:valid?) }
|
16
|
-
its(:valid?) { should be_a_boolean }
|
17
|
-
|
18
|
-
it { should respond_to(:persisted?) }
|
19
|
-
its(:persisted?) { should be_a_boolean }
|
20
|
-
|
21
|
-
its(:class) { should respond_to(:model_name) }
|
22
|
-
|
23
|
-
context "the model name" do
|
24
|
-
subject do
|
25
|
-
described_class.model_name
|
26
|
-
end
|
27
|
-
|
28
|
-
it { should be_kind_of(String) }
|
29
|
-
its(:human) { should be_kind_of(String) }
|
30
|
-
its(:partial_path) { should be_kind_of(String) }
|
31
|
-
its(:singular) { should be_kind_of(String) }
|
32
|
-
its(:plural) { should be_kind_of(String) }
|
33
|
-
end
|
34
|
-
|
35
|
-
context "when its not persisted" do
|
36
|
-
subject do
|
37
|
-
obj = described_class.new
|
38
|
-
obj.stub!(:persisted?).and_return(false)
|
39
|
-
obj
|
40
|
-
end
|
41
|
-
|
42
|
-
its(:to_key) { should be_nil }
|
43
|
-
its(:to_param) { should be_nil }
|
44
|
-
end
|
45
|
-
|
46
|
-
it { should respond_to(:errors) }
|
47
|
-
|
48
|
-
context "errors" do
|
49
|
-
subject do
|
50
|
-
described_class.new.errors
|
51
|
-
end
|
52
|
-
|
53
|
-
it { should respond_to(:[]) }
|
54
|
-
it { should respond_to(:full_messages) }
|
55
|
-
|
56
|
-
context "[:hello]" do
|
57
|
-
it { subject[:hello].should be_an_instance_of(Array) }
|
58
|
-
|
59
|
-
its(:full_messages) { should be_an_instance_of(Array) }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
@@ -1,62 +0,0 @@
|
|
1
|
-
# From http://gist.github.com/62943
|
2
|
-
# Author http://github.com/trotter
|
3
|
-
module RSpec
|
4
|
-
module Mocks
|
5
|
-
module ArgumentMatchers
|
6
|
-
|
7
|
-
class ArrayIncludingMatcher
|
8
|
-
# We'll allow an array of arguments to be passed in, so that you can do
|
9
|
-
# things like obj.should_receive(:blah).with(array_including('a', 'b'))
|
10
|
-
def initialize(*expected)
|
11
|
-
@expected = expected
|
12
|
-
end
|
13
|
-
|
14
|
-
# actual is the array (hopefully) passed to the method by the user.
|
15
|
-
# We'll check that it includes all the expected values, and return false
|
16
|
-
# if it doesn't or if we blow up because #include? is not defined.
|
17
|
-
def ==(actual)
|
18
|
-
@expected.each do |expected|
|
19
|
-
return false unless actual.include?(expected)
|
20
|
-
end
|
21
|
-
true
|
22
|
-
rescue NoMethodError => ex
|
23
|
-
return false
|
24
|
-
end
|
25
|
-
|
26
|
-
def description
|
27
|
-
"array_including(#{@expected.join(', ')})"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class ArrayNotIncludingMatcher
|
32
|
-
def initialize(*expected)
|
33
|
-
@expected = expected
|
34
|
-
end
|
35
|
-
|
36
|
-
def ==(actual)
|
37
|
-
@expected.each do |expected|
|
38
|
-
return false if actual.include?(expected)
|
39
|
-
end
|
40
|
-
true
|
41
|
-
rescue NoMethodError => ex
|
42
|
-
return false
|
43
|
-
end
|
44
|
-
|
45
|
-
def description
|
46
|
-
"array_not_including(#{@expected.join(', ')})"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# array_including is a helpful wrapper that allows us to actually type
|
51
|
-
# #with(array_including(...)) instead of ArrayIncludingMatcher.new(...)
|
52
|
-
def array_including(*args)
|
53
|
-
ArrayIncludingMatcher.new(*args)
|
54
|
-
end
|
55
|
-
|
56
|
-
def array_not_including(*args)
|
57
|
-
ArrayNotIncludingMatcher.new(*args)
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,233 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe MongoDoc::Associations::CollectionProxy do
|
4
|
-
class CollectionProxyTest
|
5
|
-
include MongoDoc::Document
|
6
|
-
|
7
|
-
attr_accessor :name
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:name) { 'embed_many_name' }
|
11
|
-
let(:root) { CollectionProxyTest.new }
|
12
|
-
let(:proxy) { MongoDoc::Associations::CollectionProxy.new(:assoc_name => name, :assoc_class => CollectionProxyTest, :root => root, :parent => root) }
|
13
|
-
let(:item) { CollectionProxyTest.new }
|
14
|
-
|
15
|
-
describe "#_modifier_path" do
|
16
|
-
it "cascades to child documents with our assoc name and $" do
|
17
|
-
document = stub
|
18
|
-
proxy.stub(:collection => [document])
|
19
|
-
document.should_receive(:_modifier_path=).with("new.path.#{name}.$")
|
20
|
-
MongoDoc::Associations::ProxyBase.stub(:is_document?).and_return(true)
|
21
|
-
proxy._modifier_path = 'new.path'
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "#_selector_path=" do
|
26
|
-
it "cascades to child documents" do
|
27
|
-
document = stub
|
28
|
-
proxy.stub(:collection => [document])
|
29
|
-
document.should_receive("_selector_path=").with("new.path.#{name}")
|
30
|
-
MongoDoc::Associations::ProxyBase.stub(:is_document?).and_return(true)
|
31
|
-
proxy._selector_path = 'new.path'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "#attach_document" do
|
36
|
-
it "sets the Document's modifier path to our modifier path" do
|
37
|
-
item.should_receive(:_modifier_path=).with('embed_many_name.$')
|
38
|
-
proxy.send(:attach_document, item)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "sets the Document's selector path to our selector path" do
|
42
|
-
item.should_receive(:_selector_path=).with('embed_many_name')
|
43
|
-
proxy.send(:attach_document, item)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "#<<" do
|
48
|
-
it "appends the item to the collection" do
|
49
|
-
(proxy << item).should include(item)
|
50
|
-
end
|
51
|
-
|
52
|
-
context "when the item is a Hash" do
|
53
|
-
let(:hash) {{:name => 'hash'}}
|
54
|
-
|
55
|
-
it "does not register a save observer" do
|
56
|
-
root.should_not_receive(:register_save_observer)
|
57
|
-
proxy << hash
|
58
|
-
end
|
59
|
-
|
60
|
-
it "does not set the root" do
|
61
|
-
hash.should_not_receive(:_root=)
|
62
|
-
proxy << hash
|
63
|
-
end
|
64
|
-
|
65
|
-
it "adds the hash to the collection" do
|
66
|
-
proxy << hash
|
67
|
-
proxy.should include(hash)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "when the item is not a MongoDoc::Document" do
|
72
|
-
let(:other_item) {'not a doc'}
|
73
|
-
|
74
|
-
it "does not register a save observer" do
|
75
|
-
root.should_not_receive(:register_save_observer)
|
76
|
-
proxy << other_item
|
77
|
-
end
|
78
|
-
|
79
|
-
it "does not set the root" do
|
80
|
-
other_item.should_not_receive(:_root=)
|
81
|
-
proxy << other_item
|
82
|
-
end
|
83
|
-
|
84
|
-
it "adds the item to the collection" do
|
85
|
-
proxy << other_item
|
86
|
-
proxy.should include(other_item)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context "when the item is a MongoDoc::Document" do
|
91
|
-
it "registers a save observer" do
|
92
|
-
root.should_receive(:register_save_observer)
|
93
|
-
proxy << item
|
94
|
-
end
|
95
|
-
|
96
|
-
it "sets the root" do
|
97
|
-
proxy << item
|
98
|
-
item._root.should == root
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
context "when the item is an array" do
|
103
|
-
it "adds the array" do
|
104
|
-
array = ['something else']
|
105
|
-
proxy << array
|
106
|
-
proxy.should include(array)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context "#[]=" do
|
112
|
-
it "sets the item at the index" do
|
113
|
-
proxy[1] = item
|
114
|
-
proxy[1].should == item
|
115
|
-
end
|
116
|
-
|
117
|
-
context "when the item is not a MongoDoc::Document" do
|
118
|
-
let(:other_item) {'not a doc'}
|
119
|
-
|
120
|
-
it "does not register a save observer" do
|
121
|
-
root.should_not_receive(:register_save_observer)
|
122
|
-
proxy[1] = other_item
|
123
|
-
end
|
124
|
-
|
125
|
-
it "does not set the root" do
|
126
|
-
other_item.should_not_receive(:_root=)
|
127
|
-
proxy[1] = other_item
|
128
|
-
end
|
129
|
-
|
130
|
-
it "adds the item to the collection" do
|
131
|
-
proxy[1] = other_item
|
132
|
-
proxy.should include(other_item)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
context "when the item is a MongoDoc::Document" do
|
137
|
-
it "registers a save observer" do
|
138
|
-
root.should_receive(:register_save_observer)
|
139
|
-
proxy[1] = item
|
140
|
-
end
|
141
|
-
|
142
|
-
it "sets the root" do
|
143
|
-
proxy[1] = item
|
144
|
-
item._root.should == root
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
context "#concat" do
|
150
|
-
it "appends the items from the array to self" do
|
151
|
-
proxy.concat([item])
|
152
|
-
proxy.should include(item)
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
context "#replace" do
|
157
|
-
it "clears the existing collection" do
|
158
|
-
proxy.should_receive(:clear)
|
159
|
-
proxy.replace([item])
|
160
|
-
end
|
161
|
-
|
162
|
-
it "concats the other onto self" do
|
163
|
-
other = [item]
|
164
|
-
proxy.should_receive(:concat).with(other)
|
165
|
-
proxy.replace(other)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
context "#unshift" do
|
170
|
-
let(:proxy_with_item) { proxy << 'other' }
|
171
|
-
|
172
|
-
it "adds the item to the front of the collection" do
|
173
|
-
proxy_with_item.unshift(item)
|
174
|
-
proxy_with_item[0].should == item
|
175
|
-
end
|
176
|
-
|
177
|
-
context "when the item is not a MongoDoc::Document" do
|
178
|
-
let(:other_item) {'not a doc'}
|
179
|
-
|
180
|
-
it "does not register a save observer" do
|
181
|
-
root.should_not_receive(:register_save_observer)
|
182
|
-
proxy_with_item.unshift(other_item)
|
183
|
-
end
|
184
|
-
|
185
|
-
it "does not set the root" do
|
186
|
-
other_item.should_not_receive(:_root=)
|
187
|
-
proxy_with_item.unshift(other_item)
|
188
|
-
end
|
189
|
-
|
190
|
-
it "adds the item to the front of the collection" do
|
191
|
-
proxy_with_item.unshift(other_item)
|
192
|
-
proxy_with_item[0].should == other_item
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
context "when the item is a MongoDoc::Document" do
|
197
|
-
let(:new_item) { CollectionProxyTest.new }
|
198
|
-
|
199
|
-
it "registers a save observer" do
|
200
|
-
root.should_receive(:register_save_observer)
|
201
|
-
proxy_with_item.unshift(new_item)
|
202
|
-
end
|
203
|
-
|
204
|
-
it "sets the root" do
|
205
|
-
proxy_with_item.unshift(new_item)
|
206
|
-
new_item._root.should == root
|
207
|
-
end
|
208
|
-
|
209
|
-
it "adds the item to the front of the collection" do
|
210
|
-
proxy_with_item.unshift(new_item)
|
211
|
-
proxy_with_item[0].should == new_item
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
context "#build" do
|
217
|
-
let(:name) {'built'}
|
218
|
-
|
219
|
-
it "adds a built item to the collection" do
|
220
|
-
proxy.build({:name => name}).last.name.should == name
|
221
|
-
end
|
222
|
-
|
223
|
-
it "registers a save observer" do
|
224
|
-
root.should_receive(:register_save_observer)
|
225
|
-
proxy.build({:name => name})
|
226
|
-
end
|
227
|
-
|
228
|
-
it "sets the root" do
|
229
|
-
proxy.build({:name => name})
|
230
|
-
proxy.last._root.should == root
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "MongoDoc::Associations::DocumentProxy" do
|
4
|
-
class Parent
|
5
|
-
include MongoDoc::Document
|
6
|
-
end
|
7
|
-
|
8
|
-
class Child
|
9
|
-
include MongoDoc::Document
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:parent) { Parent.new }
|
13
|
-
let(:name) {'association_name'}
|
14
|
-
|
15
|
-
subject do
|
16
|
-
MongoDoc::Associations::DocumentProxy.new(:assoc_name => name, :root => parent, :parent => parent, :assoc_class => Child)
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "#build" do
|
20
|
-
it "#build builds a new object" do
|
21
|
-
Child.should === subject.build({})
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "delegated to the document" do
|
26
|
-
%w(id to_bson).each do |method|
|
27
|
-
it "delegates #{method} to the document" do
|
28
|
-
subject.stub(:document => stub)
|
29
|
-
subject.document.should_receive(method)
|
30
|
-
subject.send(method)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
%w(_modifier_path= _selector_path=).each do |setter|
|
36
|
-
describe "##{setter}" do
|
37
|
-
it "delegates to the document with our assoc name" do
|
38
|
-
subject.stub(:document => stub)
|
39
|
-
subject.document.should_receive(setter).with("new.path.#{name}")
|
40
|
-
MongoDoc::Associations::ProxyBase.stub(:is_document?).and_return(true)
|
41
|
-
subject.send("#{setter}", 'new.path')
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,181 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe MongoDoc::Associations::HashProxy do
|
4
|
-
class HashProxyTest
|
5
|
-
include MongoDoc::Document
|
6
|
-
|
7
|
-
attr_accessor :name
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:name) { 'embed_hash_name' }
|
11
|
-
let(:root) { HashProxyTest.new }
|
12
|
-
let(:proxy) { MongoDoc::Associations::HashProxy.new(:assoc_name => name, :assoc_class => HashProxyTest, :root => root, :parent => root) }
|
13
|
-
let(:item) { HashProxyTest.new }
|
14
|
-
let(:other_item) {[1,2]}
|
15
|
-
|
16
|
-
%w(_modifier_path= _selector_path=).each do |setter|
|
17
|
-
describe "##{setter}" do
|
18
|
-
it "delegates to the document with our assoc name and the key" do
|
19
|
-
document = stub
|
20
|
-
proxy.stub(:hash).and_return(:key => document)
|
21
|
-
document.should_receive(setter).with("new.path.#{name}.key")
|
22
|
-
MongoDoc::Associations::ProxyBase.stub(:is_document?).and_return(true)
|
23
|
-
proxy.send("#{setter}", 'new.path')
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "#[]=" do
|
29
|
-
it "adds the item to the hash" do
|
30
|
-
proxy['new'] = item
|
31
|
-
proxy['new'].should == item
|
32
|
-
end
|
33
|
-
|
34
|
-
context "key names must be a string or symbol constrained by BSON element name" do
|
35
|
-
['$invalid', 'in.valid', :_id, 'query', 1, Object.new].each do |name|
|
36
|
-
it "#{name} is invalid" do
|
37
|
-
expect do
|
38
|
-
proxy[name] = other_item
|
39
|
-
end.to raise_error(MongoDoc::InvalidEmbeddedHashKey)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
[:key, 'key'].each do |name|
|
44
|
-
it "#{name} is a valid name" do
|
45
|
-
expect do
|
46
|
-
proxy[name] = other_item
|
47
|
-
end.to_not raise_error(MongoDoc::InvalidEmbeddedHashKey)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context "when the item is not a MongoDoc::Document" do
|
53
|
-
|
54
|
-
it "does not register a save observer" do
|
55
|
-
root.should_not_receive(:register_save_observer)
|
56
|
-
proxy['new'] = other_item
|
57
|
-
end
|
58
|
-
|
59
|
-
it "does not set the root" do
|
60
|
-
other_item.should_not_receive(:_root=)
|
61
|
-
proxy['new'] = other_item
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "when the item is a MongoDoc::Document" do
|
66
|
-
it "registers a save observer" do
|
67
|
-
root.should_receive(:register_save_observer)
|
68
|
-
proxy['new'] = item
|
69
|
-
end
|
70
|
-
|
71
|
-
it "sets the root" do
|
72
|
-
proxy['new'] = item
|
73
|
-
item._root.should == root
|
74
|
-
end
|
75
|
-
|
76
|
-
it "adds the item through a document proxy" do
|
77
|
-
proxy['new'] = item
|
78
|
-
MongoDoc::Associations::DocumentProxy.should === proxy['new']
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context "#merge!" do
|
84
|
-
context "when the key value is not a MongoDoc::Document" do
|
85
|
-
|
86
|
-
it "does not register a save observer" do
|
87
|
-
root.should_not_receive(:register_save_observer)
|
88
|
-
proxy.merge!(:new => other_item)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "does not set the root" do
|
92
|
-
other_item.should_not_receive(:_root=)
|
93
|
-
proxy.merge!(:new => other_item)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context "when the key value is a MongoDoc::Document" do
|
98
|
-
it "registers a save observer" do
|
99
|
-
root.should_receive(:register_save_observer)
|
100
|
-
proxy.merge!(:new => item)
|
101
|
-
end
|
102
|
-
|
103
|
-
it "sets the root" do
|
104
|
-
proxy.merge!(:new => item)
|
105
|
-
item._root.should == root
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
context "with a block" do
|
110
|
-
it "calls into the block" do
|
111
|
-
proxy.merge!(:new => other_item) {|k, v1, v2| @result = v2}
|
112
|
-
@result.should == other_item
|
113
|
-
end
|
114
|
-
|
115
|
-
context "when the key value is not a MongoDoc::Document" do
|
116
|
-
|
117
|
-
it "does not register a save observer" do
|
118
|
-
root.should_not_receive(:register_save_observer)
|
119
|
-
proxy.merge!(:new => other_item) {|k, v1, v2| v2}
|
120
|
-
end
|
121
|
-
|
122
|
-
it "does not set the root" do
|
123
|
-
other_item.should_not_receive(:_root=)
|
124
|
-
proxy.merge!(:new => other_item) {|k, v1, v2| v2}
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
context "when the key value is a MongoDoc::Document" do
|
129
|
-
it "registers a save observer" do
|
130
|
-
root.should_receive(:register_save_observer)
|
131
|
-
proxy.merge!(:new => item) {|k, v1, v2| v2}
|
132
|
-
end
|
133
|
-
|
134
|
-
it "sets the root" do
|
135
|
-
proxy.merge!(:new => item) {|k, v1, v2| v2}
|
136
|
-
item._root.should == root
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
context "#replace" do
|
143
|
-
it "clears any existing data" do
|
144
|
-
proxy.should_receive(:clear)
|
145
|
-
proxy.replace(:new => other_item)
|
146
|
-
end
|
147
|
-
|
148
|
-
context "when the key value is not a MongoDoc::Document" do
|
149
|
-
|
150
|
-
it "does not register a save observer" do
|
151
|
-
root.should_not_receive(:register_save_observer)
|
152
|
-
proxy.replace(:new => other_item)
|
153
|
-
end
|
154
|
-
|
155
|
-
it "does not set the root" do
|
156
|
-
other_item.should_not_receive(:_root=)
|
157
|
-
proxy.replace(:new => other_item)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
context "when the key value is a MongoDoc::Document" do
|
162
|
-
it "registers a save observer" do
|
163
|
-
root.should_receive(:register_save_observer)
|
164
|
-
proxy.replace(:new => item)
|
165
|
-
end
|
166
|
-
|
167
|
-
it "sets the root" do
|
168
|
-
proxy.replace(:new => item)
|
169
|
-
item._root.should == root
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
end
|
174
|
-
|
175
|
-
context "#build" do
|
176
|
-
it "builds an object of the collection class from the hash attrs" do
|
177
|
-
name = 'built'
|
178
|
-
proxy.build(:key, {:name => name}).name.should == name
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "MongoDoc::Associations::ProxyBase" do
|
4
|
-
class ProxyBaseTest
|
5
|
-
include MongoDoc::Associations::ProxyBase
|
6
|
-
end
|
7
|
-
|
8
|
-
let(:_assoc_class) { 'ClassOfAssociation' }
|
9
|
-
let(:_assoc_name) { 'name_of_association' }
|
10
|
-
let(:_root) { 'root of document' }
|
11
|
-
let(:path) { 'root.parent' }
|
12
|
-
|
13
|
-
subject do
|
14
|
-
ProxyBaseTest.new({ :path => path, :assoc_class => _assoc_class, :assoc_name => _assoc_name, :root => _root })
|
15
|
-
end
|
16
|
-
|
17
|
-
%w(_assoc_class _assoc_name _modifier_path _root _selector_path).each do |attr|
|
18
|
-
it "defines #{attr}" do
|
19
|
-
should respond_to(attr)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "#initialize" do
|
24
|
-
%w(_assoc_class _assoc_name _root).each do |attr|
|
25
|
-
its(attr) { should == send(attr) }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#_modifier_path" do
|
30
|
-
its(:_modifier_path) { should == path + '.' + _assoc_name }
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "#_modifier_path=" do
|
34
|
-
it "sets the modifier path to the path + '.' + the assoc name" do
|
35
|
-
subject._modifier_path = 'new_path'
|
36
|
-
subject._modifier_path.should == "new_path.#{_assoc_name}"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "#_selector_path" do
|
41
|
-
its(:_selector_path) { should == path + '.' + _assoc_name }
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "#_selector_path=" do
|
45
|
-
it "sets the selector path to the path + '.' + the assoc name" do
|
46
|
-
subject._selector_path = 'new_path'
|
47
|
-
subject._selector_path.should == "new_path.#{_assoc_name}"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe ".is_document" do
|
52
|
-
class TestIsDocument
|
53
|
-
include MongoDoc::Document
|
54
|
-
end
|
55
|
-
|
56
|
-
it "returns false for any non-Document" do
|
57
|
-
MongoDoc::Associations::ProxyBase.is_document?(Object.new).should be_false
|
58
|
-
end
|
59
|
-
|
60
|
-
it "returns true for any Document" do
|
61
|
-
MongoDoc::Associations::ProxyBase.is_document?(TestIsDocument.new).should be_true
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "#attach" do
|
66
|
-
class AttachDocument
|
67
|
-
include MongoDoc::Document
|
68
|
-
end
|
69
|
-
|
70
|
-
let(:doc) { AttachDocument.new }
|
71
|
-
let(:object) { Object.new }
|
72
|
-
let(:proxy) { ProxyBaseTest.new(:assoc_class => _assoc_class, :assoc_name => _assoc_name, :root => _root) }
|
73
|
-
|
74
|
-
it "returns the attached object" do
|
75
|
-
proxy.send(:attach, object).should == object
|
76
|
-
end
|
77
|
-
|
78
|
-
context "when a Document" do
|
79
|
-
it "attaches the Document" do
|
80
|
-
proxy.should_receive(:attach_document)
|
81
|
-
proxy.send(:attach, doc)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context "when not a Document" do
|
86
|
-
it "does not attach the Document" do
|
87
|
-
proxy.should_not_receive(:attach_document)
|
88
|
-
proxy.send(:attach, object)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|