dm-mongo-adapter 0.2.0.pre3 → 0.6.0
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/Gemfile +27 -0
- data/README.rdoc +16 -35
- data/Rakefile +6 -16
- data/VERSION.yml +2 -2
- data/dm-mongo-adapter.gemspec +100 -121
- data/lib/mongo_adapter.rb +19 -62
- data/lib/mongo_adapter/adapter.rb +49 -36
- data/lib/mongo_adapter/conditions.rb +0 -5
- data/lib/mongo_adapter/migrations.rb +17 -23
- data/lib/mongo_adapter/model.rb +3 -74
- data/lib/mongo_adapter/modifier.rb +1 -1
- data/lib/mongo_adapter/property/array.rb +10 -0
- data/lib/mongo_adapter/property/db_ref.rb +17 -0
- data/lib/mongo_adapter/property/hash.rb +27 -0
- data/lib/mongo_adapter/property/object_id.rb +47 -0
- data/lib/mongo_adapter/query.rb +42 -45
- data/lib/mongo_adapter/rails/storage.rb +15 -0
- data/lib/mongo_adapter/resource.rb +0 -130
- data/lib/mongo_adapter/support/class.rb +11 -0
- data/lib/mongo_adapter/support/date.rb +11 -0
- data/lib/mongo_adapter/support/date_time.rb +12 -0
- data/lib/mongo_adapter/support/object.rb +9 -0
- data/spec/legacy/adapter_spec.rb +9 -6
- data/spec/legacy/associations_spec.rb +37 -29
- data/spec/legacy/property_spec.rb +4 -3
- data/spec/legacy/sti_spec.rb +1 -2
- data/spec/lib/cleanup_models.rb +0 -1
- data/spec/public/aggregates_spec.rb +171 -0
- data/spec/public/model_spec.rb +8 -22
- data/spec/public/modifier_spec.rb +109 -0
- data/spec/public/properties/db_ref_spec.rb +17 -0
- data/spec/public/properties/object_id_spec.rb +15 -0
- data/spec/public/resource_spec.rb +2 -383
- data/spec/public/shared/object_id_shared_spec.rb +16 -39
- data/spec/spec_helper.rb +0 -4
- metadata +87 -117
- data/.gitignore +0 -9
- data/lib/mongo_adapter/embedded_model.rb +0 -187
- data/lib/mongo_adapter/embedded_resource.rb +0 -134
- data/lib/mongo_adapter/embedments/one_to_many.rb +0 -144
- data/lib/mongo_adapter/embedments/one_to_one.rb +0 -57
- data/lib/mongo_adapter/embedments/relationship.rb +0 -258
- data/lib/mongo_adapter/model/embedment.rb +0 -215
- data/lib/mongo_adapter/types/date.rb +0 -24
- data/lib/mongo_adapter/types/date_time.rb +0 -28
- data/lib/mongo_adapter/types/db_ref.rb +0 -65
- data/lib/mongo_adapter/types/discriminator.rb +0 -32
- data/lib/mongo_adapter/types/object_id.rb +0 -72
- data/lib/mongo_adapter/types/objects.rb +0 -31
- data/spec/legacy/embedded_resource_spec.rb +0 -157
- data/spec/legacy/embedments_spec.rb +0 -177
- data/spec/legacy/modifier_spec.rb +0 -81
- data/spec/public/embedded_collection_spec.rb +0 -61
- data/spec/public/embedded_resource_spec.rb +0 -220
- data/spec/public/model/embedment_spec.rb +0 -186
- data/spec/public/shared/model_embedments_spec.rb +0 -338
- data/spec/public/types/df_ref_spec.rb +0 -6
- data/spec/public/types/discriminator_spec.rb +0 -118
- data/spec/public/types/embedded_array_spec.rb +0 -55
- data/spec/public/types/embedded_hash_spec.rb +0 -83
- data/spec/public/types/object_id_spec.rb +0 -6
- data/spec/semipublic/embedded_model_spec.rb +0 -43
- data/spec/semipublic/model/embedment_spec.rb +0 -42
- data/spec/semipublic/resource_spec.rb +0 -70
@@ -1,220 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
describe DataMapper::Mongo::EmbeddedResource do
|
4
|
-
before(:all) do
|
5
|
-
class ::Address
|
6
|
-
include DataMapper::Mongo::EmbeddedResource
|
7
|
-
property :street, String
|
8
|
-
property :city, String, :field => 'conurbation'
|
9
|
-
end
|
10
|
-
|
11
|
-
class ::AddressWithDefault
|
12
|
-
include DataMapper::Mongo::EmbeddedResource
|
13
|
-
property :city, String, :default => 'Rock Ridge'
|
14
|
-
end
|
15
|
-
|
16
|
-
class ::User
|
17
|
-
include DataMapper::Mongo::Resource
|
18
|
-
property :id, ObjectID
|
19
|
-
embeds 1, :address, :model => Address
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
#
|
24
|
-
# attributes
|
25
|
-
#
|
26
|
-
|
27
|
-
describe 'attributes' do
|
28
|
-
before(:all) do
|
29
|
-
@address = Address.new(:street => 'Main Street', :city => 'Rock Ridge')
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should return a Hash' do
|
33
|
-
@address.attributes.should be_kind_of(Hash)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should use the property names when key_on=:name' do
|
37
|
-
@address.attributes(:name).should ==
|
38
|
-
{ :street => 'Main Street', :city => 'Rock Ridge' }
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should use the field names when key_on=:field' do
|
42
|
-
@address.attributes(:field).should ==
|
43
|
-
{ 'street' => 'Main Street', 'conurbation' => 'Rock Ridge' }
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should use the property instances when key_on=:property' do
|
47
|
-
@address.attributes(:property).should == {
|
48
|
-
Address.properties[:street] => 'Main Street',
|
49
|
-
Address.properties[:city] => 'Rock Ridge'
|
50
|
-
}
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
#
|
55
|
-
# dirty?
|
56
|
-
#
|
57
|
-
|
58
|
-
describe '#dirty?' do
|
59
|
-
describe 'on a new embedded resource' do
|
60
|
-
it 'should return false' do
|
61
|
-
Address.new.should_not be_dirty
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'should return true if an attribute has been changed' do
|
65
|
-
Address.new(:city => 'Rock Ridge').should be_dirty
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'should return false if a changed attribute has been saved' do
|
69
|
-
address = Address.new(:city => 'Rock Ridge')
|
70
|
-
|
71
|
-
lambda { User.create(:address => address) }.should \
|
72
|
-
change(address, :dirty?).to(false)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe 'on a persisted embedded resource' do
|
77
|
-
before(:each) do
|
78
|
-
user = User.create(:address => Address.new(:city => 'Rock Ridge'))
|
79
|
-
@address = user.address
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'should return false when no changes have been made' do
|
83
|
-
@address.should_not be_dirty
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'should return true if an attribute has been changed' do
|
87
|
-
@address.street = 'Main Street'
|
88
|
-
@address.should be_dirty
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'should return false if a changed attribute has been saved' do
|
92
|
-
@address.street = 'Main Street'
|
93
|
-
|
94
|
-
lambda { @address.parent.save }.should \
|
95
|
-
change(@address, :dirty?).to(false)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
#
|
101
|
-
# dirty_self?
|
102
|
-
#
|
103
|
-
|
104
|
-
describe '#dirty_self?' do
|
105
|
-
describe 'on a new embedded resource' do
|
106
|
-
it 'should return false if no changes have been made and no ' \
|
107
|
-
'properties have a default' do
|
108
|
-
Address.new.should_not be_dirty_self
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'should return true if no changes have been made, but a property ' \
|
112
|
-
'has a default' do
|
113
|
-
AddressWithDefault.new.should be_dirty_self
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'should return true if a change has been made' do
|
117
|
-
Address.new(:city => 'Rock Ridge').should be_dirty_self
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe 'on a persisited embedded resource' do
|
122
|
-
before(:each) do
|
123
|
-
user = User.create(:address => Address.new(:city => 'Rock Ridge'))
|
124
|
-
@address = user.address
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'should return false if no changes have been made' do
|
128
|
-
@address.should_not be_dirty_self
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'should return true if a change has been made' do
|
132
|
-
@address.street = 'Main Street'
|
133
|
-
@address.should be_dirty_self
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
#
|
139
|
-
# parent?
|
140
|
-
#
|
141
|
-
|
142
|
-
describe '#parent?' do
|
143
|
-
it 'should return true if the embedded resource has a parent' do
|
144
|
-
address = Address.new
|
145
|
-
address.parent = User.new
|
146
|
-
address.parent?.should be_true
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'should return false if the embedded resource has no parent' do
|
150
|
-
Address.new.parent?.should be_false
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
#
|
155
|
-
# new?
|
156
|
-
#
|
157
|
-
|
158
|
-
describe '#new?' do
|
159
|
-
it 'should return false if it has been persisted' do
|
160
|
-
user = User.create(:address => Address.new(:city => 'Rock Ridge'))
|
161
|
-
user.address.should_not be_new
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'should return true if its parent has not been persisted' do
|
165
|
-
user = User.new(:address => Address.new(:city => 'Rock Ridge'))
|
166
|
-
user.address.should be_new
|
167
|
-
end
|
168
|
-
|
169
|
-
it 'should return true if it has no parent' do
|
170
|
-
Address.new.should be_new
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
#
|
175
|
-
# saved?
|
176
|
-
#
|
177
|
-
|
178
|
-
describe '#saved?' do
|
179
|
-
it 'should return true if it has been persisted' do
|
180
|
-
user = User.create(:address => Address.new(:city => 'Rock Ridge'))
|
181
|
-
user.address.should be_saved
|
182
|
-
end
|
183
|
-
|
184
|
-
it 'should return false if its parent has not been persisted' do
|
185
|
-
user = User.new(:address => Address.new(:city => 'Rock Ridge'))
|
186
|
-
user.address.should_not be_saved
|
187
|
-
end
|
188
|
-
|
189
|
-
it 'should return false if it has no parent' do
|
190
|
-
Address.new.should_not be_saved
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
#
|
195
|
-
# save
|
196
|
-
#
|
197
|
-
|
198
|
-
describe '#save' do
|
199
|
-
it 'should raise MissingParentError if no parent is set' do
|
200
|
-
lambda { Address.new.save }.should raise_error(
|
201
|
-
DataMapper::Mongo::EmbeddedResource::MissingParentError)
|
202
|
-
end
|
203
|
-
|
204
|
-
it 'should clear the original attributes if the parent saved' do
|
205
|
-
user = User.new(:address => Address.new(:city => 'Rock Ridge'))
|
206
|
-
|
207
|
-
expectation = lambda { user.address.original_attributes.empty? }
|
208
|
-
lambda { user.address.save }.should change(&expectation).to(true)
|
209
|
-
end
|
210
|
-
|
211
|
-
it 'should not clear the original_attributes is the parent did not save' do
|
212
|
-
user = User.new(:address => Address.new(:city => 'Rock Ridge'))
|
213
|
-
user.stub!(:save).and_return(false)
|
214
|
-
|
215
|
-
expectation = lambda { user.address.original_attributes.empty? }
|
216
|
-
lambda { user.address.save }.should_not change(&expectation).to(true)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
end
|
@@ -1,186 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
2
|
-
|
3
|
-
describe DataMapper::Mongo::Embedments do
|
4
|
-
# Removes the Engine constant, runs the block, then redefines the Engine
|
5
|
-
# class.
|
6
|
-
def without_engine_defined
|
7
|
-
old_engine = ::Engine
|
8
|
-
Object.send(:remove_const, :Engine) if defined?(::Engine)
|
9
|
-
yield
|
10
|
-
Object.send(:const_set, :Engine, old_engine)
|
11
|
-
end
|
12
|
-
|
13
|
-
before(:all) do
|
14
|
-
class ::Car
|
15
|
-
include DataMapper::Mongo::Resource
|
16
|
-
property :id, ObjectID
|
17
|
-
property :name, String
|
18
|
-
end
|
19
|
-
|
20
|
-
class ::Engine
|
21
|
-
include DataMapper::Mongo::EmbeddedResource
|
22
|
-
property :name, String
|
23
|
-
end
|
24
|
-
|
25
|
-
class ::Door
|
26
|
-
include DataMapper::Mongo::EmbeddedResource
|
27
|
-
property :name, String
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def n
|
32
|
-
Car.n
|
33
|
-
end
|
34
|
-
|
35
|
-
it { Car.should respond_to(:embeds) }
|
36
|
-
it { Car.should respond_to(:embedments) }
|
37
|
-
|
38
|
-
describe '#embeds(1, ...)' do
|
39
|
-
before(:all) do
|
40
|
-
@model = Engine
|
41
|
-
@name = :engine
|
42
|
-
|
43
|
-
Car.embeds(1, :engine)
|
44
|
-
|
45
|
-
@car = Car.new(:name => 'Ford')
|
46
|
-
end
|
47
|
-
|
48
|
-
it_should_behave_like 'A singular embedment reader'
|
49
|
-
it_should_behave_like 'A singular embedment writer'
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '#embeds(n, ...)' do
|
53
|
-
before(:all) do
|
54
|
-
@model = Door
|
55
|
-
@name = :doors
|
56
|
-
|
57
|
-
Car.embeds(n, :doors)
|
58
|
-
@car = Car.new(:name => 'Ford')
|
59
|
-
end
|
60
|
-
|
61
|
-
it_should_behave_like 'A many embedment reader'
|
62
|
-
it_should_behave_like 'A many embedment writer'
|
63
|
-
end
|
64
|
-
|
65
|
-
describe '#embeds(n, :through ...)' do
|
66
|
-
it 'should raise an ArgumentError' do
|
67
|
-
pending ':through option not supported on embedments'
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe '#embeds(1..4)' do
|
72
|
-
before(:all) do
|
73
|
-
@model = Door
|
74
|
-
@name = :doors
|
75
|
-
|
76
|
-
Car.embeds(1..4, :doors)
|
77
|
-
@car = Car.new(:name => 'Ford')
|
78
|
-
end
|
79
|
-
|
80
|
-
it_should_behave_like 'A many embedment reader'
|
81
|
-
it_should_behave_like 'A many embedment writer'
|
82
|
-
end
|
83
|
-
|
84
|
-
describe '#embeds' do
|
85
|
-
describe 'when inferring the model from the name' do
|
86
|
-
it 'should set the relationship target model' do
|
87
|
-
Car.embeds(1, :engine)
|
88
|
-
Car.embedments[:engine].target_model.should == Engine
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'should set the relationship target model when it is not defined' do
|
92
|
-
without_engine_defined do
|
93
|
-
Car.embeds(1, :engine)
|
94
|
-
end
|
95
|
-
|
96
|
-
Car.embedments[:engine].target_model.should == Engine
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe 'when the third argument is a model' do
|
101
|
-
it 'should set the relationship target model' do
|
102
|
-
Car.embeds(1, :engine, Engine)
|
103
|
-
Car.embedments[:engine].target_model.should == Engine
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe 'when the third argument is a string' do
|
108
|
-
it 'should set the relationship target model' do
|
109
|
-
without_engine_defined do
|
110
|
-
Car.embeds(1, :engine, 'Engine')
|
111
|
-
end
|
112
|
-
|
113
|
-
Car.embedments[:engine].target_model.should == Engine
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'should raise NameError when given an invalid string' do
|
117
|
-
Car.embeds(1, :engine, 'DoesNotExist')
|
118
|
-
running = lambda { Car.embedments[:engine].target_model }
|
119
|
-
running.should raise_error(NameError)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
describe 'when a :model option is given' do
|
124
|
-
it 'should set the relationship target model when given a string' do
|
125
|
-
without_engine_defined do
|
126
|
-
Car.embeds(1, :engine, :model => 'Engine')
|
127
|
-
end
|
128
|
-
|
129
|
-
Car.embedments[:engine].target_model.should == Engine
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'should raise NameError when given an invalid string' do
|
133
|
-
Car.embeds(1, :engine, :model => 'DoesNotExist')
|
134
|
-
running = lambda { Car.embedments[:engine].target_model }
|
135
|
-
running.should raise_error(NameError)
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'should set the relationship target model when given a model' do
|
139
|
-
Car.embeds(1, :engine, :model => Engine)
|
140
|
-
Car.embedments[:engine].target_model.should == Engine
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
describe 'when no model is given' do
|
145
|
-
it 'should raise NameError' do
|
146
|
-
Car.embeds(1, :does_not_exist)
|
147
|
-
running = lambda { Car.embedments[:engine].target_model }
|
148
|
-
running.should raise_error(NameError)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'should raise an exception if a :through option is given' do
|
153
|
-
running = lambda { Car.embeds(1, Engine, :through => :engines) }
|
154
|
-
running.should raise_error(ArgumentError)
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'should raise an exception if a :remote_name option is given' do
|
158
|
-
running = lambda { Car.embeds(1, Engine, :remote_name => :engines) }
|
159
|
-
running.should raise_error(ArgumentError)
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'should raise an exception if a :via option is given' do
|
163
|
-
running = lambda { Car.embeds(1, Engine, :via => :engines) }
|
164
|
-
running.should raise_error(ArgumentError)
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'should raise an exception if a :inverse option is given' do
|
168
|
-
running = lambda { Car.embeds(1, Engine, :inverse => :parent) }
|
169
|
-
running.should raise_error(ArgumentError)
|
170
|
-
end
|
171
|
-
|
172
|
-
it 'should raise an exception if a :parent_key option is given' do
|
173
|
-
running = lambda { Car.embeds(1, Engine, :parent_key => :id) }
|
174
|
-
running.should raise_error(ArgumentError)
|
175
|
-
end
|
176
|
-
|
177
|
-
it 'should raise an exception if the cardinality is not understood' do
|
178
|
-
lambda { Car.embeds(n..n, :doors) }.should raise_error(ArgumentError)
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'should raise an exception if the minimum constraint is larger than the maximum' do
|
182
|
-
lambda { Car.embeds(2..1, :doors) }.should raise_error(ArgumentError)
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
end
|
@@ -1,338 +0,0 @@
|
|
1
|
-
# The share specs contained herein are very slightly modified versions of
|
2
|
-
# those found in dm-core/spec/public/model/relationship_spec.rb
|
3
|
-
|
4
|
-
share_examples_for 'A singular embedment reader' do
|
5
|
-
it { @car.should respond_to(@name) }
|
6
|
-
|
7
|
-
describe 'reader' do
|
8
|
-
describe 'when there is no associated resource' do
|
9
|
-
it 'should return nil when there is no query' do
|
10
|
-
@car.__send__(@name).should be_nil
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should return nil when there is a query' do
|
14
|
-
@car.__send__(@name, :name => '__nothing__').should be_nil
|
15
|
-
end
|
16
|
-
end # when there is no associated resource
|
17
|
-
|
18
|
-
describe 'when there is an associated resource' do
|
19
|
-
before(:all) do
|
20
|
-
@expected = @model.new
|
21
|
-
@car.__send__("#{@name}=", @expected)
|
22
|
-
end
|
23
|
-
|
24
|
-
describe 'without a query' do
|
25
|
-
it 'should return an EmbeddedResource' do
|
26
|
-
returned = @car.__send__(@name)
|
27
|
-
returned.should be_kind_of(DataMapper::Mongo::EmbeddedResource)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should return the correct EmbeddedResource' do
|
31
|
-
@car.__send__(@name).should == @expected
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe 'with a query' do
|
36
|
-
it 'should return a EmbeddedResource' do
|
37
|
-
returned = @car.__send__(@name, :name => @expected.name)
|
38
|
-
returned.should be_kind_of(DataMapper::Mongo::EmbeddedResource)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should return the correct EmbeddedResource' do
|
42
|
-
@car.__send__(@name, :name => @expected.name).should == @expected
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end # when there is an associated resource
|
46
|
-
|
47
|
-
end # reader
|
48
|
-
end # A singular embedment reader
|
49
|
-
|
50
|
-
share_examples_for 'A singular embedment writer' do
|
51
|
-
it { @car.should respond_to("#{@name}=") }
|
52
|
-
|
53
|
-
describe 'writer' do
|
54
|
-
describe 'when setting the wrong kind of target' do
|
55
|
-
it 'should raise an ArgumentError' do
|
56
|
-
calling = lambda { @car.__send__("#{@name}=", Object.new) }
|
57
|
-
calling.should raise_error(ArgumentError)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe 'when setting an EmbeddedResource' do
|
62
|
-
before(:all) do
|
63
|
-
@expected = @model.new
|
64
|
-
@return = @car.__send__("#{@name}=", @expected)
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'should return the expected EmbeddedResource' do
|
68
|
-
@return.should equal(@expected)
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'should set the EmbeddedResource' do
|
72
|
-
@car.__send__(@name).should equal(@expected)
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'should relate the associated EmbeddedResource' do
|
76
|
-
@expected.parent.should == @car
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'should persist the Resource' do
|
80
|
-
@car.save.should be_true
|
81
|
-
@car.model.get(*@car.key).__send__(@name).should == @expected
|
82
|
-
end
|
83
|
-
end # when setting an EmbeddedResource
|
84
|
-
|
85
|
-
describe 'when setting a Hash' do
|
86
|
-
before(:all) do
|
87
|
-
@expected = @model.new(:name => 'Name')
|
88
|
-
@return = @car.__send__("#{@name}=", { :name => 'Name' })
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'should return the expected EmbeddedResource' do
|
92
|
-
@return.should == @expected
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'should set the EmbeddedResource' do
|
96
|
-
@car.__send__(@name).should equal(@return)
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'should relate the associated EmbeddedResource' do
|
100
|
-
@car.__send__(@name).parent.should == @car
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'should persist the Resource' do
|
104
|
-
@car.save.should be_true
|
105
|
-
@car.model.get(*@car.key).__send__(@name).should == @expected
|
106
|
-
end
|
107
|
-
end # when setting a Hash
|
108
|
-
|
109
|
-
describe 'when setting nil' do
|
110
|
-
before(:all) do
|
111
|
-
@car.__send__("#{@name}=", @model.new)
|
112
|
-
@return = @car.__send__("#{@name}=", nil)
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'should return nil' do
|
116
|
-
@return.should be_nil
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'should set nil' do
|
120
|
-
@car.__send__(@name).should be_nil
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'should persist as nil' do
|
124
|
-
@car.save.should be_true
|
125
|
-
@car.model.get(*@car.key).__send__(@name).should be_nil
|
126
|
-
end
|
127
|
-
end # when setting nil
|
128
|
-
|
129
|
-
describe 'when changing the EmbeddedResource' do
|
130
|
-
before(:all) do
|
131
|
-
@car.__send__("#{@name}=", @model.new)
|
132
|
-
@return = @car.__send__("#{@name}=", @expected = @model.new)
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'should return the expected EmbeddedResource' do
|
136
|
-
@return.should equal(@expected)
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'should set the EmbeddedResource' do
|
140
|
-
@car.__send__(@name).should equal(@return)
|
141
|
-
end
|
142
|
-
|
143
|
-
it 'should relate the associated EmbeddedResource' do
|
144
|
-
@car.__send__(@name).parent.should == @car
|
145
|
-
end
|
146
|
-
|
147
|
-
it 'should persist the Resource' do
|
148
|
-
@car.save.should be_true
|
149
|
-
@car.model.get(*@car.key).__send__(@name).should == @expected
|
150
|
-
end
|
151
|
-
end # when changing the EmbeddedResource
|
152
|
-
|
153
|
-
end # writer
|
154
|
-
end # A singular embedment writer
|
155
|
-
|
156
|
-
share_examples_for 'A many embedment reader' do
|
157
|
-
it { @car.should respond_to(@name) }
|
158
|
-
|
159
|
-
describe 'reader' do
|
160
|
-
describe 'when there are no child resources and the source is saved' do
|
161
|
-
before(:all) do
|
162
|
-
@car.save.should be_true
|
163
|
-
@return = @car.__send__(@name)
|
164
|
-
end
|
165
|
-
|
166
|
-
it 'should return a Collection' do
|
167
|
-
@return.should be_kind_of(
|
168
|
-
DataMapper::Mongo::Embedments::OneToMany::Collection)
|
169
|
-
end
|
170
|
-
|
171
|
-
it 'should return an empty Collection' do
|
172
|
-
@return.should be_empty
|
173
|
-
end
|
174
|
-
end # when there is no child resource and the source is saved
|
175
|
-
|
176
|
-
describe 'when there are no child resources and the source is not saved' do
|
177
|
-
before(:all) do
|
178
|
-
@return = @car.__send__(@name)
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'should return a Collection' do
|
182
|
-
@return.should be_kind_of(
|
183
|
-
DataMapper::Mongo::Embedments::OneToMany::Collection)
|
184
|
-
end
|
185
|
-
|
186
|
-
it 'should return an empty Collection' do
|
187
|
-
@return.should be_empty
|
188
|
-
end
|
189
|
-
end # when there is no child resource and the source is not save
|
190
|
-
|
191
|
-
describe 'when there is a child resource' do
|
192
|
-
before(:all) do
|
193
|
-
@expected = @model.new
|
194
|
-
@car.__send__("#{@name}=", [ @expected ])
|
195
|
-
@return = @car.__send__(@name)
|
196
|
-
end
|
197
|
-
|
198
|
-
it 'should return a Collection' do
|
199
|
-
@return.should be_kind_of(
|
200
|
-
DataMapper::Mongo::Embedments::OneToMany::Collection)
|
201
|
-
end
|
202
|
-
|
203
|
-
it 'should return the expected resources' do
|
204
|
-
@return.should == [ @expected ]
|
205
|
-
end
|
206
|
-
end # when there is a child resource
|
207
|
-
|
208
|
-
end # reader
|
209
|
-
end # A many embedment reader
|
210
|
-
|
211
|
-
share_examples_for 'A many embedment writer' do
|
212
|
-
it { @car.should respond_to("#{@name}=") }
|
213
|
-
|
214
|
-
describe 'writer' do
|
215
|
-
describe 'when setting an Array of the wrong kind of target' do
|
216
|
-
it 'should raise an ArgumentError' do
|
217
|
-
calling = lambda { @car.__send__("#{@name}=", [Object.new]) }
|
218
|
-
calling.should raise_error(ArgumentError)
|
219
|
-
end
|
220
|
-
end # when setting an Array of the wrong kind of target
|
221
|
-
|
222
|
-
describe 'when setting an Array of EmbeddedResources' do
|
223
|
-
before(:all) do
|
224
|
-
@expected = [ @model.new ]
|
225
|
-
@return = @car.__send__("#{@name}=", @expected)
|
226
|
-
end
|
227
|
-
|
228
|
-
it 'should return the expected Collection' do
|
229
|
-
@return.should == @expected
|
230
|
-
end
|
231
|
-
|
232
|
-
it 'should set the Collection' do
|
233
|
-
@car.__send__(@name).should == @expected
|
234
|
-
@car.__send__(@name).zip(@expected) do |value, expected|
|
235
|
-
value.should equal(expected)
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
it 'should relate the associated Collection' do
|
240
|
-
@expected.each { |resource| resource.parent.should == @car }
|
241
|
-
end
|
242
|
-
|
243
|
-
it 'should persist the Collection' do
|
244
|
-
@car.save.should be_true
|
245
|
-
@car.model.get(*@car.key).__send__(@name).should == @expected
|
246
|
-
end
|
247
|
-
|
248
|
-
it 'should persist the associated EmbeddedResources' do
|
249
|
-
@car.save.should be_true
|
250
|
-
@expected.each { |resource| resource.should be_saved }
|
251
|
-
end
|
252
|
-
end # when setting an Array of EmbeddedResources
|
253
|
-
|
254
|
-
describe 'when setting an Array of Hashes' do
|
255
|
-
before(:all) do
|
256
|
-
@expected = [ @model.new(:name => 'Name') ]
|
257
|
-
@return = @car.__send__("#{@name}=", [{ :name => 'Name' }])
|
258
|
-
end
|
259
|
-
|
260
|
-
it 'should return the expected Collection' do
|
261
|
-
@return.should == @expected
|
262
|
-
end
|
263
|
-
|
264
|
-
it 'should set the Collection' do
|
265
|
-
@car.__send__(@name).should == @expected
|
266
|
-
@car.__send__(@name).zip(@expected) do |value, expected|
|
267
|
-
value.should == expected
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
it 'should relate the associated Collection' do
|
272
|
-
@return.each { |resource| resource.parent.should == @car }
|
273
|
-
end
|
274
|
-
|
275
|
-
it 'should persist the Collection' do
|
276
|
-
@car.save.should be_true
|
277
|
-
@car.model.get(*@car.key).__send__(@name).should == @expected
|
278
|
-
end
|
279
|
-
|
280
|
-
it 'should persist the associated EmbeddedResources' do
|
281
|
-
@car.save.should be_true
|
282
|
-
@return.each { |resource| resource.should be_saved }
|
283
|
-
end
|
284
|
-
end # when setting an Array of Hashes
|
285
|
-
|
286
|
-
describe 'when setting an empty collection' do
|
287
|
-
before :all do
|
288
|
-
@car.__send__("#{@name}=", [ @model.new ])
|
289
|
-
@return = @car.__send__("#{@name}=", [])
|
290
|
-
end
|
291
|
-
|
292
|
-
it 'should return a Collection' do
|
293
|
-
@return.should be_kind_of(
|
294
|
-
DataMapper::Mongo::Embedments::OneToMany::Collection)
|
295
|
-
end
|
296
|
-
|
297
|
-
it 'should set a empty Collection' do
|
298
|
-
@car.__send__(@name).should be_empty
|
299
|
-
end
|
300
|
-
|
301
|
-
it 'should persist as an empty collection' do
|
302
|
-
@car.save.should be_true
|
303
|
-
@car.model.get(*@car.key).__send__(@name).should be_empty
|
304
|
-
end
|
305
|
-
end # when setting an empty collection
|
306
|
-
|
307
|
-
describe 'when changing an associated collection' do
|
308
|
-
before(:all) do
|
309
|
-
@car.__send__("#{@name}=", [ @model.new ])
|
310
|
-
@expected = [ @model.new ]
|
311
|
-
@return = @car.__send__("#{@name}=", @expected)
|
312
|
-
end
|
313
|
-
|
314
|
-
it 'should return the expected Resource' do
|
315
|
-
@return.should == @expected
|
316
|
-
end
|
317
|
-
|
318
|
-
it 'should set the Resource' do
|
319
|
-
@car.__send__(@name).should == @expected
|
320
|
-
end
|
321
|
-
|
322
|
-
it 'should relate the associated Resource' do
|
323
|
-
@expected.each { |resource| resource.parent.should == @car }
|
324
|
-
end
|
325
|
-
|
326
|
-
it 'should persist the Resource' do
|
327
|
-
@car.save.should be_true
|
328
|
-
@car.model.get(*@car.key).__send__(@name).should == @expected
|
329
|
-
end
|
330
|
-
|
331
|
-
it 'should persist the associated Resource' do
|
332
|
-
@car.save.should be_true
|
333
|
-
@expected.each { |resource| resource.should be_saved }
|
334
|
-
end
|
335
|
-
end # when setting an associated collection
|
336
|
-
|
337
|
-
end #writer
|
338
|
-
end # A many embedment writer
|