datamapper-dm-core 0.9.11 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +17 -14
- data/.gitignore +3 -1
- data/FAQ +6 -5
- data/History.txt +5 -39
- data/Manifest.txt +67 -76
- data/QUICKLINKS +1 -1
- data/README.txt +21 -15
- data/Rakefile +16 -15
- data/SPECS +2 -29
- data/TODO +1 -1
- data/dm-core.gemspec +11 -15
- data/lib/dm-core/adapters/abstract_adapter.rb +182 -185
- data/lib/dm-core/adapters/data_objects_adapter.rb +482 -534
- data/lib/dm-core/adapters/in_memory_adapter.rb +90 -69
- data/lib/dm-core/adapters/mysql_adapter.rb +22 -115
- data/lib/dm-core/adapters/oracle_adapter.rb +249 -0
- data/lib/dm-core/adapters/postgres_adapter.rb +7 -173
- data/lib/dm-core/adapters/sqlite3_adapter.rb +4 -97
- data/lib/dm-core/adapters/yaml_adapter.rb +116 -0
- data/lib/dm-core/adapters.rb +135 -16
- data/lib/dm-core/associations/many_to_many.rb +372 -90
- data/lib/dm-core/associations/many_to_one.rb +220 -73
- data/lib/dm-core/associations/one_to_many.rb +319 -255
- data/lib/dm-core/associations/one_to_one.rb +66 -53
- data/lib/dm-core/associations/relationship.rb +560 -158
- data/lib/dm-core/collection.rb +1104 -381
- data/lib/dm-core/core_ext/kernel.rb +12 -0
- data/lib/dm-core/core_ext/symbol.rb +10 -0
- data/lib/dm-core/identity_map.rb +4 -34
- data/lib/dm-core/migrations.rb +1283 -0
- data/lib/dm-core/model/descendant_set.rb +81 -0
- data/lib/dm-core/model/hook.rb +45 -0
- data/lib/dm-core/model/is.rb +32 -0
- data/lib/dm-core/model/property.rb +248 -0
- data/lib/dm-core/model/relationship.rb +335 -0
- data/lib/dm-core/model/scope.rb +90 -0
- data/lib/dm-core/model.rb +570 -369
- data/lib/dm-core/property.rb +753 -280
- data/lib/dm-core/property_set.rb +141 -98
- data/lib/dm-core/query/conditions/comparison.rb +814 -0
- data/lib/dm-core/query/conditions/operation.rb +247 -0
- data/lib/dm-core/query/direction.rb +43 -0
- data/lib/dm-core/query/operator.rb +42 -0
- data/lib/dm-core/query/path.rb +102 -0
- data/lib/dm-core/query/sort.rb +45 -0
- data/lib/dm-core/query.rb +974 -492
- data/lib/dm-core/repository.rb +147 -107
- data/lib/dm-core/resource.rb +644 -429
- data/lib/dm-core/spec/adapter_shared_spec.rb +294 -0
- data/lib/dm-core/spec/data_objects_adapter_shared_spec.rb +106 -0
- data/lib/dm-core/support/chainable.rb +20 -0
- data/lib/dm-core/support/deprecate.rb +12 -0
- data/lib/dm-core/support/equalizer.rb +23 -0
- data/lib/dm-core/support/logger.rb +13 -0
- data/lib/dm-core/{naming_conventions.rb → support/naming_conventions.rb} +6 -6
- data/lib/dm-core/transaction.rb +333 -92
- data/lib/dm-core/type.rb +98 -60
- data/lib/dm-core/types/boolean.rb +1 -1
- data/lib/dm-core/types/discriminator.rb +34 -20
- data/lib/dm-core/types/object.rb +7 -4
- data/lib/dm-core/types/paranoid_boolean.rb +11 -9
- data/lib/dm-core/types/paranoid_datetime.rb +11 -9
- data/lib/dm-core/types/serial.rb +3 -3
- data/lib/dm-core/types/text.rb +3 -4
- data/lib/dm-core/version.rb +1 -1
- data/lib/dm-core.rb +106 -110
- data/script/performance.rb +102 -109
- data/script/profile.rb +169 -38
- data/spec/lib/adapter_helpers.rb +105 -0
- data/spec/lib/collection_helpers.rb +18 -0
- data/spec/lib/counter_adapter.rb +34 -0
- data/spec/lib/pending_helpers.rb +27 -0
- data/spec/lib/rspec_immediate_feedback_formatter.rb +53 -0
- data/spec/public/associations/many_to_many_spec.rb +193 -0
- data/spec/public/associations/many_to_one_spec.rb +73 -0
- data/spec/public/associations/one_to_many_spec.rb +77 -0
- data/spec/public/associations/one_to_one_spec.rb +156 -0
- data/spec/public/collection_spec.rb +65 -0
- data/spec/public/model/relationship_spec.rb +924 -0
- data/spec/public/model_spec.rb +159 -0
- data/spec/public/property_spec.rb +829 -0
- data/spec/public/resource_spec.rb +71 -0
- data/spec/public/sel_spec.rb +44 -0
- data/spec/public/setup_spec.rb +145 -0
- data/spec/public/shared/association_collection_shared_spec.rb +317 -0
- data/spec/public/shared/collection_shared_spec.rb +1723 -0
- data/spec/public/shared/finder_shared_spec.rb +1619 -0
- data/spec/public/shared/resource_shared_spec.rb +924 -0
- data/spec/public/shared/sel_shared_spec.rb +112 -0
- data/spec/public/transaction_spec.rb +129 -0
- data/spec/public/types/discriminator_spec.rb +130 -0
- data/spec/semipublic/adapters/abstract_adapter_spec.rb +30 -0
- data/spec/semipublic/adapters/in_memory_adapter_spec.rb +12 -0
- data/spec/semipublic/adapters/mysql_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/oracle_adapter_spec.rb +194 -0
- data/spec/semipublic/adapters/postgres_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/sqlite3_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/yaml_adapter_spec.rb +12 -0
- data/spec/semipublic/associations/many_to_one_spec.rb +53 -0
- data/spec/semipublic/associations/relationship_spec.rb +194 -0
- data/spec/semipublic/associations_spec.rb +177 -0
- data/spec/semipublic/collection_spec.rb +142 -0
- data/spec/semipublic/property_spec.rb +61 -0
- data/spec/semipublic/query/conditions_spec.rb +528 -0
- data/spec/semipublic/query/path_spec.rb +443 -0
- data/spec/semipublic/query_spec.rb +2626 -0
- data/spec/semipublic/resource_spec.rb +47 -0
- data/spec/semipublic/shared/resource_shared_spec.rb +126 -0
- data/spec/spec.opts +3 -1
- data/spec/spec_helper.rb +80 -57
- data/tasks/ci.rb +19 -31
- data/tasks/dm.rb +43 -48
- data/tasks/doc.rb +8 -11
- data/tasks/gemspec.rb +5 -5
- data/tasks/hoe.rb +15 -16
- data/tasks/install.rb +8 -10
- metadata +72 -93
- data/lib/dm-core/associations/relationship_chain.rb +0 -81
- data/lib/dm-core/associations.rb +0 -207
- data/lib/dm-core/auto_migrations.rb +0 -105
- data/lib/dm-core/dependency_queue.rb +0 -32
- data/lib/dm-core/hook.rb +0 -11
- data/lib/dm-core/is.rb +0 -16
- data/lib/dm-core/logger.rb +0 -232
- data/lib/dm-core/migrations/destructive_migrations.rb +0 -17
- data/lib/dm-core/migrator.rb +0 -29
- data/lib/dm-core/scope.rb +0 -58
- data/lib/dm-core/support/array.rb +0 -13
- data/lib/dm-core/support/assertions.rb +0 -8
- data/lib/dm-core/support/errors.rb +0 -23
- data/lib/dm-core/support/kernel.rb +0 -11
- data/lib/dm-core/support/symbol.rb +0 -41
- data/lib/dm-core/support.rb +0 -7
- data/lib/dm-core/type_map.rb +0 -80
- data/lib/dm-core/types.rb +0 -19
- data/script/all +0 -4
- data/spec/integration/association_spec.rb +0 -1382
- data/spec/integration/association_through_spec.rb +0 -203
- data/spec/integration/associations/many_to_many_spec.rb +0 -449
- data/spec/integration/associations/many_to_one_spec.rb +0 -163
- data/spec/integration/associations/one_to_many_spec.rb +0 -188
- data/spec/integration/auto_migrations_spec.rb +0 -413
- data/spec/integration/collection_spec.rb +0 -1073
- data/spec/integration/data_objects_adapter_spec.rb +0 -32
- data/spec/integration/dependency_queue_spec.rb +0 -46
- data/spec/integration/model_spec.rb +0 -197
- data/spec/integration/mysql_adapter_spec.rb +0 -85
- data/spec/integration/postgres_adapter_spec.rb +0 -731
- data/spec/integration/property_spec.rb +0 -253
- data/spec/integration/query_spec.rb +0 -514
- data/spec/integration/repository_spec.rb +0 -61
- data/spec/integration/resource_spec.rb +0 -513
- data/spec/integration/sqlite3_adapter_spec.rb +0 -352
- data/spec/integration/sti_spec.rb +0 -273
- data/spec/integration/strategic_eager_loading_spec.rb +0 -156
- data/spec/integration/transaction_spec.rb +0 -75
- data/spec/integration/type_spec.rb +0 -275
- data/spec/lib/logging_helper.rb +0 -18
- data/spec/lib/mock_adapter.rb +0 -27
- data/spec/lib/model_loader.rb +0 -100
- data/spec/lib/publicize_methods.rb +0 -28
- data/spec/models/content.rb +0 -16
- data/spec/models/vehicles.rb +0 -34
- data/spec/models/zoo.rb +0 -48
- data/spec/unit/adapters/abstract_adapter_spec.rb +0 -133
- data/spec/unit/adapters/adapter_shared_spec.rb +0 -15
- data/spec/unit/adapters/data_objects_adapter_spec.rb +0 -632
- data/spec/unit/adapters/in_memory_adapter_spec.rb +0 -98
- data/spec/unit/adapters/postgres_adapter_spec.rb +0 -133
- data/spec/unit/associations/many_to_many_spec.rb +0 -32
- data/spec/unit/associations/many_to_one_spec.rb +0 -159
- data/spec/unit/associations/one_to_many_spec.rb +0 -393
- data/spec/unit/associations/one_to_one_spec.rb +0 -7
- data/spec/unit/associations/relationship_spec.rb +0 -71
- data/spec/unit/associations_spec.rb +0 -242
- data/spec/unit/auto_migrations_spec.rb +0 -111
- data/spec/unit/collection_spec.rb +0 -182
- data/spec/unit/data_mapper_spec.rb +0 -35
- data/spec/unit/identity_map_spec.rb +0 -126
- data/spec/unit/is_spec.rb +0 -80
- data/spec/unit/migrator_spec.rb +0 -33
- data/spec/unit/model_spec.rb +0 -321
- data/spec/unit/naming_conventions_spec.rb +0 -36
- data/spec/unit/property_set_spec.rb +0 -90
- data/spec/unit/property_spec.rb +0 -753
- data/spec/unit/query_spec.rb +0 -571
- data/spec/unit/repository_spec.rb +0 -93
- data/spec/unit/resource_spec.rb +0 -649
- data/spec/unit/scope_spec.rb +0 -142
- data/spec/unit/transaction_spec.rb +0 -493
- data/spec/unit/type_map_spec.rb +0 -114
- data/spec/unit/type_spec.rb +0 -119
@@ -0,0 +1,443 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
2
|
+
|
3
|
+
# class methods
|
4
|
+
describe DataMapper::Query::Path do
|
5
|
+
before :all do
|
6
|
+
class ::Author
|
7
|
+
include DataMapper::Resource
|
8
|
+
|
9
|
+
property :id, Serial
|
10
|
+
property :title, String
|
11
|
+
|
12
|
+
has n, :articles
|
13
|
+
end
|
14
|
+
|
15
|
+
class ::Article
|
16
|
+
include DataMapper::Resource
|
17
|
+
|
18
|
+
property :id, Serial
|
19
|
+
property :title, String
|
20
|
+
|
21
|
+
belongs_to :author
|
22
|
+
end
|
23
|
+
|
24
|
+
@relationship = Author.relationships[:articles]
|
25
|
+
@relationships = [ @relationship ]
|
26
|
+
@property = Article.properties[:title]
|
27
|
+
end
|
28
|
+
|
29
|
+
it { DataMapper::Query::Path.should respond_to(:new) }
|
30
|
+
|
31
|
+
describe '.new' do
|
32
|
+
describe 'when supplied an Array of Relationships' do
|
33
|
+
before do
|
34
|
+
@path = DataMapper::Query::Path.new(@relationships)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should return a Query::Path' do
|
38
|
+
@path.should be_kind_of(DataMapper::Query::Path)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should set Query::Path#relationships' do
|
42
|
+
@path.relationships.should eql(@relationships)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should copy the relationships' do
|
46
|
+
@path.relationships.should_not equal(@relationships)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'when supplied an Array of Relationships and a Property Symbol name' do
|
51
|
+
before do
|
52
|
+
@path = DataMapper::Query::Path.new(@relationships, @property.name)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should return a Query::Path' do
|
56
|
+
@path.should be_kind_of(DataMapper::Query::Path)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should set Query::Path#relationships' do
|
60
|
+
@path.relationships.should eql(@relationships)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should copy the relationships' do
|
64
|
+
@path.relationships.should_not equal(@relationships)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should set Query::Path#property' do
|
68
|
+
@path.property.should equal(@property)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe 'when supplied an unknown property' do
|
73
|
+
it 'should raise an error' do
|
74
|
+
lambda { DataMapper::Query::Path.new(@relationships, :unknown) }.should raise_error(ArgumentError, "Unknown property 'unknown' in Article")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# instance methods
|
81
|
+
describe DataMapper::Query::Path do
|
82
|
+
before :all do
|
83
|
+
class ::Author
|
84
|
+
include DataMapper::Resource
|
85
|
+
|
86
|
+
property :id, Serial
|
87
|
+
property :title, String
|
88
|
+
|
89
|
+
has n, :articles
|
90
|
+
end
|
91
|
+
|
92
|
+
class ::Article
|
93
|
+
include DataMapper::Resource
|
94
|
+
|
95
|
+
property :id, Serial
|
96
|
+
property :title, String
|
97
|
+
|
98
|
+
belongs_to :author
|
99
|
+
end
|
100
|
+
|
101
|
+
@relationship = Author.relationships[:articles]
|
102
|
+
@relationships = [ @relationship ]
|
103
|
+
@property = Article.properties[:title]
|
104
|
+
|
105
|
+
@path = DataMapper::Query::Path.new(@relationships)
|
106
|
+
end
|
107
|
+
|
108
|
+
it { @path.should respond_to(:==) }
|
109
|
+
|
110
|
+
describe '#==' do
|
111
|
+
describe 'when other Query::Path is the same' do
|
112
|
+
before do
|
113
|
+
@other = @path
|
114
|
+
|
115
|
+
@return = @path == @other
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should return true' do
|
119
|
+
@return.should be_true
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe 'when other Query::Path does not respond to #relationships' do
|
124
|
+
before do
|
125
|
+
class << @other = @path.dup
|
126
|
+
undef_method :relationships
|
127
|
+
end
|
128
|
+
|
129
|
+
@return = @path == @other
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should return false' do
|
133
|
+
@return.should be_false
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe 'when other Query::Path does not respond to #property' do
|
138
|
+
before do
|
139
|
+
class << @other = @path.dup
|
140
|
+
undef_method :property
|
141
|
+
end
|
142
|
+
|
143
|
+
@return = @path == @other
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'should return false' do
|
147
|
+
@return.should be_false
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe 'when other Query::Path has different relationships' do
|
152
|
+
before do
|
153
|
+
@other = DataMapper::Query::Path.new([ Article.relationships[:author] ])
|
154
|
+
|
155
|
+
@return = @path == @other
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'should return false' do
|
159
|
+
@return.should be_false
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe 'when other Query::Path has different properties' do
|
164
|
+
before do
|
165
|
+
@other = DataMapper::Query::Path.new(@path.relationships, :title)
|
166
|
+
|
167
|
+
@return = @path == @other
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should return false' do
|
171
|
+
@return.should be_false
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe 'when other Query::Path has the same relationship and property' do
|
176
|
+
before do
|
177
|
+
@other = DataMapper::Query::Path.new(@path.relationships, @path.property)
|
178
|
+
|
179
|
+
@return = @path == @other
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'should return true' do
|
183
|
+
@return.should be_true
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
it { @path.should respond_to(:eql?) }
|
189
|
+
|
190
|
+
describe '#eql?' do
|
191
|
+
describe 'when other Query::Path is the same' do
|
192
|
+
before do
|
193
|
+
@other = @path
|
194
|
+
|
195
|
+
@return = @path.eql?(@other)
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'should return true' do
|
199
|
+
@return.should be_true
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
describe 'when other Object is not an instance of Query::Path' do
|
204
|
+
before do
|
205
|
+
class MyQueryPath < DataMapper::Query::Path; end
|
206
|
+
|
207
|
+
@other = MyQueryPath.new(@path.relationships, @path.property)
|
208
|
+
|
209
|
+
@return = @path.eql?(@other)
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'should return false' do
|
213
|
+
@return.should be_false
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe 'when other Query::Path has different relationships' do
|
218
|
+
before do
|
219
|
+
@other = DataMapper::Query::Path.new([ Article.relationships[:author] ])
|
220
|
+
|
221
|
+
@return = @path.eql?(@other)
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'should return false' do
|
225
|
+
@return.should be_false
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
describe 'when other Query::Path has different properties' do
|
230
|
+
before do
|
231
|
+
@other = DataMapper::Query::Path.new(@path.relationships, :title)
|
232
|
+
|
233
|
+
@return = @path.eql?(@other)
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'should return false' do
|
237
|
+
@return.should be_false
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
describe 'when other Query::Path has the same relationship and property' do
|
242
|
+
before do
|
243
|
+
@other = DataMapper::Query::Path.new(@path.relationships, @path.property)
|
244
|
+
|
245
|
+
@return = @path.eql?(@other)
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'should return true' do
|
249
|
+
@return.should be_true
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
it { @path.should respond_to(:model) }
|
255
|
+
|
256
|
+
describe '#model' do
|
257
|
+
it 'should return a Model' do
|
258
|
+
@path.model.should be_kind_of(DataMapper::Model)
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'should return expected value' do
|
262
|
+
@path.model.should eql(Article)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
it { @path.should respond_to(:property) }
|
267
|
+
|
268
|
+
describe '#property' do
|
269
|
+
describe 'when no property is defined' do
|
270
|
+
it 'should return nil' do
|
271
|
+
@path.property.should be_nil
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
describe 'when a property is defined' do
|
276
|
+
before do
|
277
|
+
@path = @path.class.new(@path.relationships, @property.name)
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'should return a Property' do
|
281
|
+
@path.property.should be_kind_of(DataMapper::Property)
|
282
|
+
end
|
283
|
+
|
284
|
+
it 'should return expected value' do
|
285
|
+
@path.property.should eql(@property)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
it { @path.should respond_to(:relationships) }
|
291
|
+
|
292
|
+
describe '#relationships' do
|
293
|
+
it 'should return an Array' do
|
294
|
+
@path.relationships.should be_kind_of(Array)
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'should return expected value' do
|
298
|
+
@path.relationships.should eql(@relationships)
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
it { @path.should respond_to(:respond_to?) }
|
303
|
+
|
304
|
+
describe '#respond_to?' do
|
305
|
+
describe 'when supplied a method name provided by the parent class' do
|
306
|
+
before do
|
307
|
+
@return = @path.respond_to?(:class)
|
308
|
+
end
|
309
|
+
|
310
|
+
it 'should return true' do
|
311
|
+
@return.should be_true
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
describe 'when supplied a method name provided by the property' do
|
316
|
+
before do
|
317
|
+
@path = @path.class.new(@path.relationships, @property.name)
|
318
|
+
|
319
|
+
@return = @path.respond_to?(:instance_variable_name)
|
320
|
+
end
|
321
|
+
|
322
|
+
it 'should return true' do
|
323
|
+
@return.should be_true
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
describe 'when supplied a method name referring to a relationship' do
|
328
|
+
before do
|
329
|
+
@return = @path.respond_to?(:author)
|
330
|
+
end
|
331
|
+
|
332
|
+
it 'should return true' do
|
333
|
+
@return.should be_true
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
describe 'when supplied a method name referring to a property' do
|
338
|
+
before do
|
339
|
+
@return = @path.respond_to?(:title)
|
340
|
+
end
|
341
|
+
|
342
|
+
it 'should return true' do
|
343
|
+
@return.should be_true
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
describe 'when supplied an unknown method name' do
|
348
|
+
before do
|
349
|
+
@return = @path.respond_to?(:unknown)
|
350
|
+
end
|
351
|
+
|
352
|
+
it 'should return false' do
|
353
|
+
@return.should be_false
|
354
|
+
end
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
it { @path.should respond_to(:repository_name) }
|
359
|
+
|
360
|
+
describe '#repository_name' do
|
361
|
+
it 'should return a Symbol' do
|
362
|
+
@path.repository_name.should be_kind_of(Symbol)
|
363
|
+
end
|
364
|
+
|
365
|
+
it 'should return expected value' do
|
366
|
+
@path.repository_name.should eql(:default)
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
describe '#method_missing' do
|
371
|
+
describe 'when supplied a method name provided by the parent class' do
|
372
|
+
before do
|
373
|
+
@return = @path.class
|
374
|
+
end
|
375
|
+
|
376
|
+
it 'should return the expected value' do
|
377
|
+
@return.should eql(DataMapper::Query::Path)
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
describe 'when supplied a method name provided by the property' do
|
382
|
+
before do
|
383
|
+
@path = @path.class.new(@path.relationships, @property.name)
|
384
|
+
|
385
|
+
@return = @path.instance_variable_name
|
386
|
+
end
|
387
|
+
|
388
|
+
it 'should return the expected value' do
|
389
|
+
@return.should eql('@title')
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
describe 'when supplied a method name referring to a relationship' do
|
394
|
+
before do
|
395
|
+
@return = @path.author
|
396
|
+
end
|
397
|
+
|
398
|
+
it 'should return a Query::Path' do
|
399
|
+
@return.should be_kind_of(DataMapper::Query::Path)
|
400
|
+
end
|
401
|
+
|
402
|
+
it 'should return the expected value' do
|
403
|
+
@return.should eql(DataMapper::Query::Path.new([ @relationship, Article.relationships[:author] ]))
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
describe 'when supplied a method name referring to a property' do
|
408
|
+
before do
|
409
|
+
@return = @path.title
|
410
|
+
end
|
411
|
+
|
412
|
+
it 'should return a Query::Path' do
|
413
|
+
@return.should be_kind_of(DataMapper::Query::Path)
|
414
|
+
end
|
415
|
+
|
416
|
+
it 'should return the expected value' do
|
417
|
+
@return.should eql(DataMapper::Query::Path.new(@relationships, :title))
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
describe 'when supplied an unknown method name' do
|
422
|
+
it 'should raise an error' do
|
423
|
+
lambda { @path.unknown }.should raise_error(NoMethodError, "undefined property or relationship 'unknown' on Article")
|
424
|
+
end
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
((DataMapper::Query::Conditions::Comparison.slugs | [ :not ]) - [ :eql, :in ]).each do |slug|
|
429
|
+
describe "##{slug}" do
|
430
|
+
before do
|
431
|
+
@return = @path.send(slug)
|
432
|
+
end
|
433
|
+
|
434
|
+
it 'should return a Query::Operator' do
|
435
|
+
@return.should be_kind_of(DataMapper::Query::Operator)
|
436
|
+
end
|
437
|
+
|
438
|
+
it 'should return expected value' do
|
439
|
+
@return.should eql(DataMapper::Query::Operator.new(@path, slug))
|
440
|
+
end
|
441
|
+
end
|
442
|
+
end
|
443
|
+
end
|