dm-core 0.10.0 → 0.10.1
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/History.txt +25 -5
- data/Manifest.txt +1 -0
- data/README.txt +67 -23
- data/Rakefile +0 -2
- data/deps.rip +1 -1
- data/dm-core.gemspec +6 -6
- data/lib/dm-core/adapters/abstract_adapter.rb +3 -76
- data/lib/dm-core/adapters/data_objects_adapter.rb +8 -39
- data/lib/dm-core/associations/many_to_many.rb +28 -16
- data/lib/dm-core/associations/many_to_one.rb +1 -45
- data/lib/dm-core/associations/one_to_many.rb +1 -38
- data/lib/dm-core/associations/relationship.rb +43 -20
- data/lib/dm-core/collection.rb +33 -32
- data/lib/dm-core/model/property.rb +8 -8
- data/lib/dm-core/model/relationship.rb +10 -12
- data/lib/dm-core/property.rb +20 -85
- data/lib/dm-core/property_set.rb +8 -8
- data/lib/dm-core/query/conditions/comparison.rb +13 -71
- data/lib/dm-core/query/conditions/operation.rb +73 -47
- data/lib/dm-core/query/operator.rb +3 -45
- data/lib/dm-core/query/path.rb +5 -41
- data/lib/dm-core/query.rb +37 -108
- data/lib/dm-core/repository.rb +3 -79
- data/lib/dm-core/resource.rb +54 -49
- data/lib/dm-core/support/chainable.rb +0 -2
- data/lib/dm-core/support/equalizer.rb +23 -0
- data/lib/dm-core/types/object.rb +4 -4
- data/lib/dm-core/version.rb +1 -1
- data/lib/dm-core.rb +3 -11
- data/spec/public/model/relationship_spec.rb +4 -4
- data/spec/public/property_spec.rb +5 -449
- data/spec/public/sel_spec.rb +52 -2
- data/spec/public/shared/collection_shared_spec.rb +79 -26
- data/spec/public/shared/finder_shared_spec.rb +6 -6
- data/spec/public/shared/resource_shared_spec.rb +2 -2
- data/spec/semipublic/property_spec.rb +524 -9
- data/spec/semipublic/query_spec.rb +6 -6
- data/tasks/hoe.rb +2 -2
- metadata +24 -4
@@ -846,7 +846,7 @@ share_examples_for 'Finder Interface' do
|
|
846
846
|
end
|
847
847
|
end
|
848
848
|
|
849
|
-
describe 'with limit specified' do
|
849
|
+
describe 'with a limit specified' do
|
850
850
|
before :all do
|
851
851
|
@return = @resources = @articles.first(1)
|
852
852
|
end
|
@@ -882,7 +882,7 @@ share_examples_for 'Finder Interface' do
|
|
882
882
|
end
|
883
883
|
end
|
884
884
|
|
885
|
-
# describe 'with limit specified', 'after prepending to the collection' do
|
885
|
+
# describe 'with a limit specified', 'after prepending to the collection' do
|
886
886
|
# before :all do
|
887
887
|
# @return = @resources = @articles.unshift(@other).first(1)
|
888
888
|
# end
|
@@ -904,7 +904,7 @@ share_examples_for 'Finder Interface' do
|
|
904
904
|
# end
|
905
905
|
# end
|
906
906
|
|
907
|
-
describe 'with limit and query specified' do
|
907
|
+
describe 'with a limit and query specified' do
|
908
908
|
before :all do
|
909
909
|
@return = @resources = @articles.first(1, :content => 'Sample')
|
910
910
|
end
|
@@ -1222,7 +1222,7 @@ share_examples_for 'Finder Interface' do
|
|
1222
1222
|
# end
|
1223
1223
|
end
|
1224
1224
|
|
1225
|
-
describe 'with limit specified' do
|
1225
|
+
describe 'with a limit specified' do
|
1226
1226
|
before :all do
|
1227
1227
|
@return = @resources = @articles.last(1)
|
1228
1228
|
end
|
@@ -1258,7 +1258,7 @@ share_examples_for 'Finder Interface' do
|
|
1258
1258
|
end
|
1259
1259
|
end
|
1260
1260
|
|
1261
|
-
# describe 'with limit specified', 'after appending to the collection' do
|
1261
|
+
# describe 'with a limit specified', 'after appending to the collection' do
|
1262
1262
|
# before :all do
|
1263
1263
|
# @return = @resources = @articles.push(@other).last(1)
|
1264
1264
|
# end
|
@@ -1280,7 +1280,7 @@ share_examples_for 'Finder Interface' do
|
|
1280
1280
|
# end
|
1281
1281
|
# end
|
1282
1282
|
|
1283
|
-
describe 'with limit and query specified' do
|
1283
|
+
describe 'with a limit and query specified' do
|
1284
1284
|
before :all do
|
1285
1285
|
@return = @resources = @articles.last(1, :content => 'Sample')
|
1286
1286
|
end
|
@@ -237,8 +237,8 @@ share_examples_for 'A public Resource' do
|
|
237
237
|
@resource.should be_frozen
|
238
238
|
end
|
239
239
|
|
240
|
-
it
|
241
|
-
@resource.
|
240
|
+
it "should return true when calling #{method} on a destroyed resource" do
|
241
|
+
@resource.send(method).should be_true
|
242
242
|
end
|
243
243
|
|
244
244
|
it 'should remove object from persistent storage' do
|
@@ -1,13 +1,505 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
2
|
|
3
|
+
# class methods
|
4
|
+
describe DataMapper::Property do
|
5
|
+
before :all do
|
6
|
+
module ::Blog
|
7
|
+
class Article
|
8
|
+
include DataMapper::Resource
|
9
|
+
|
10
|
+
property :id, Serial
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.new' do
|
16
|
+
before :all do
|
17
|
+
@model = Blog::Article
|
18
|
+
@name = :title
|
19
|
+
@type = String
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'when provided no options' do
|
23
|
+
before :all do
|
24
|
+
@property = DataMapper::Property.new(@model, @name, @type)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should return a Property' do
|
28
|
+
@property.should be_kind_of(DataMapper::Property)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should set the model' do
|
32
|
+
@property.model.should equal(@model)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should set the type' do
|
36
|
+
@property.type.should equal(@type)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should set the options to an empty Hash' do
|
40
|
+
@property.options.should == {}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
[ :index, :unique_index, :unique, :lazy ].each do |attribute|
|
45
|
+
[ true, false, :title, [ :title ] ].each do |value|
|
46
|
+
describe "when provided #{(options = { attribute => value }).inspect}" do
|
47
|
+
before :all do
|
48
|
+
@property = DataMapper::Property.new(@model, @name, @type, options)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should return a Property' do
|
52
|
+
@property.should be_kind_of(DataMapper::Property)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should set the model' do
|
56
|
+
@property.model.should equal(@model)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should set the type' do
|
60
|
+
@property.type.should equal(@type)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should set the options to #{options.inspect}" do
|
64
|
+
@property.options.should == options
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
[ [], nil ].each do |value|
|
70
|
+
describe "when provided #{(invalid_options = { attribute => value }).inspect}" do
|
71
|
+
it 'should raise an exception' do
|
72
|
+
lambda {
|
73
|
+
DataMapper::Property.new(@model, @name, @type, invalid_options)
|
74
|
+
}.should raise_error(ArgumentError, "options[#{attribute.inspect}] must be either true, false, a Symbol or an Array of Symbols")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# instance methods
|
3
83
|
describe DataMapper::Property do
|
4
84
|
before :all do
|
5
85
|
module ::Blog
|
6
86
|
class Author
|
7
87
|
include DataMapper::Resource
|
8
88
|
|
9
|
-
property :
|
10
|
-
property :
|
89
|
+
property :id, Integer, :key => true
|
90
|
+
property :name, String
|
91
|
+
property :rating, Float
|
92
|
+
property :rate, BigDecimal
|
93
|
+
property :type, Class
|
94
|
+
property :alias, String
|
95
|
+
property :active, Boolean
|
96
|
+
property :deleted_at, Time
|
97
|
+
property :created_at, DateTime
|
98
|
+
property :created_on, Date
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
@model = Blog::Author
|
103
|
+
end
|
104
|
+
|
105
|
+
describe '#typecast' do
|
106
|
+
describe "when type is able to do typecasting on it's own" do
|
107
|
+
it 'delegates all the work to the type'
|
108
|
+
end
|
109
|
+
|
110
|
+
describe 'when value is nil' do
|
111
|
+
it 'returns value unchanged' do
|
112
|
+
@model.properties[:name].typecast(nil).should be(nil)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe 'when value is a Ruby primitive' do
|
117
|
+
it 'returns value unchanged' do
|
118
|
+
@model.properties[:id].typecast([3200, 2400]).should == [3200, 2400]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe 'when type primitive is a String' do
|
123
|
+
before :all do
|
124
|
+
@property = @model.properties[:name]
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'returns same value if a string' do
|
128
|
+
@value = '1.0'
|
129
|
+
@property.typecast(@value).should equal(@value)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe 'when type primitive is a Float' do
|
134
|
+
before :all do
|
135
|
+
@property = @model.properties[:rating]
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'returns same value if a float' do
|
139
|
+
@value = 24.0
|
140
|
+
@property.typecast(@value).should equal(@value)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'returns float representation of a zero string integer' do
|
144
|
+
@property.typecast('0').should eql(0.0)
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'returns float representation of a positive string integer' do
|
148
|
+
@property.typecast('24').should eql(24.0)
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'returns float representation of a negative string integer' do
|
152
|
+
@property.typecast('-24').should eql(-24.0)
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'returns float representation of a zero string float' do
|
156
|
+
@property.typecast('0.0').should eql(0.0)
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'returns float representation of a positive string float' do
|
160
|
+
@property.typecast('24.35').should eql(24.35)
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'returns float representation of a negative string float' do
|
164
|
+
@property.typecast('-24.35').should eql(-24.35)
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'returns float representation of a zero string float, with no leading digits' do
|
168
|
+
@property.typecast('.0').should eql(0.0)
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'returns float representation of a positive string float, with no leading digits' do
|
172
|
+
@property.typecast('.41').should eql(0.41)
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'returns float representation of a zero integer' do
|
176
|
+
@property.typecast(0).should eql(0.0)
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'returns float representation of a positive integer' do
|
180
|
+
@property.typecast(24).should eql(24.0)
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'returns float representation of a negative integer' do
|
184
|
+
@property.typecast(-24).should eql(-24.0)
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'returns float representation of a zero decimal' do
|
188
|
+
@property.typecast(BigDecimal('0.0')).should eql(0.0)
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'returns float representation of a positive decimal' do
|
192
|
+
@property.typecast(BigDecimal('24.35')).should eql(24.35)
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'returns float representation of a negative decimal' do
|
196
|
+
@property.typecast(BigDecimal('-24.35')).should eql(-24.35)
|
197
|
+
end
|
198
|
+
|
199
|
+
[ Object.new, true, '00.0', '0.', '-.0', 'string' ].each do |value|
|
200
|
+
it "does not typecast non-numeric value #{value.inspect}" do
|
201
|
+
@property.typecast(value).should equal(value)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe 'when type primitive is a Integer' do
|
207
|
+
before :all do
|
208
|
+
@property = @model.properties[:id]
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'returns same value if an integer' do
|
212
|
+
@value = 24
|
213
|
+
@property.typecast(@value).should equal(@value)
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'returns integer representation of a zero string integer' do
|
217
|
+
@property.typecast('0').should eql(0)
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'returns integer representation of a positive string integer' do
|
221
|
+
@property.typecast('24').should eql(24)
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'returns integer representation of a negative string integer' do
|
225
|
+
@property.typecast('-24').should eql(-24)
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'returns integer representation of a zero string float' do
|
229
|
+
@property.typecast('0.0').should eql(0)
|
230
|
+
end
|
231
|
+
|
232
|
+
it 'returns integer representation of a positive string float' do
|
233
|
+
@property.typecast('24.35').should eql(24)
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'returns integer representation of a negative string float' do
|
237
|
+
@property.typecast('-24.35').should eql(-24)
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'returns integer representation of a zero string float, with no leading digits' do
|
241
|
+
@property.typecast('.0').should eql(0)
|
242
|
+
end
|
243
|
+
|
244
|
+
it 'returns integer representation of a positive string float, with no leading digits' do
|
245
|
+
@property.typecast('.41').should eql(0)
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'returns integer representation of a zero float' do
|
249
|
+
@property.typecast(0.0).should eql(0)
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'returns integer representation of a positive float' do
|
253
|
+
@property.typecast(24.35).should eql(24)
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'returns integer representation of a negative float' do
|
257
|
+
@property.typecast(-24.35).should eql(-24)
|
258
|
+
end
|
259
|
+
|
260
|
+
it 'returns integer representation of a zero decimal' do
|
261
|
+
@property.typecast(BigDecimal('0.0')).should eql(0)
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'returns integer representation of a positive decimal' do
|
265
|
+
@property.typecast(BigDecimal('24.35')).should eql(24)
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'returns integer representation of a negative decimal' do
|
269
|
+
@property.typecast(BigDecimal('-24.35')).should eql(-24)
|
270
|
+
end
|
271
|
+
|
272
|
+
[ Object.new, true, '00.0', '0.', '-.0', 'string' ].each do |value|
|
273
|
+
it "does not typecast non-numeric value #{value.inspect}" do
|
274
|
+
@property.typecast(value).should equal(value)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
describe 'when type primitive is a BigDecimal' do
|
280
|
+
before :all do
|
281
|
+
@property = @model.properties[:rate]
|
282
|
+
end
|
283
|
+
|
284
|
+
it 'returns same value if a decimal' do
|
285
|
+
@value = BigDecimal('24.0')
|
286
|
+
@property.typecast(@value).should equal(@value)
|
287
|
+
end
|
288
|
+
|
289
|
+
it 'returns decimal representation of a zero string integer' do
|
290
|
+
@property.typecast('0').should eql(BigDecimal('0.0'))
|
291
|
+
end
|
292
|
+
|
293
|
+
it 'returns decimal representation of a positive string integer' do
|
294
|
+
@property.typecast('24').should eql(BigDecimal('24.0'))
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'returns decimal representation of a negative string integer' do
|
298
|
+
@property.typecast('-24').should eql(BigDecimal('-24.0'))
|
299
|
+
end
|
300
|
+
|
301
|
+
it 'returns decimal representation of a zero string float' do
|
302
|
+
@property.typecast('0.0').should eql(BigDecimal('0.0'))
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'returns decimal representation of a positive string float' do
|
306
|
+
@property.typecast('24.35').should eql(BigDecimal('24.35'))
|
307
|
+
end
|
308
|
+
|
309
|
+
it 'returns decimal representation of a negative string float' do
|
310
|
+
@property.typecast('-24.35').should eql(BigDecimal('-24.35'))
|
311
|
+
end
|
312
|
+
|
313
|
+
it 'returns decimal representation of a zero string float, with no leading digits' do
|
314
|
+
@property.typecast('.0').should eql(BigDecimal('0.0'))
|
315
|
+
end
|
316
|
+
|
317
|
+
it 'returns decimal representation of a positive string float, with no leading digits' do
|
318
|
+
@property.typecast('.41').should eql(BigDecimal('0.41'))
|
319
|
+
end
|
320
|
+
|
321
|
+
it 'returns decimal representation of a zero integer' do
|
322
|
+
@property.typecast(0).should eql(BigDecimal('0.0'))
|
323
|
+
end
|
324
|
+
|
325
|
+
it 'returns decimal representation of a positive integer' do
|
326
|
+
@property.typecast(24).should eql(BigDecimal('24.0'))
|
327
|
+
end
|
328
|
+
|
329
|
+
it 'returns decimal representation of a negative integer' do
|
330
|
+
@property.typecast(-24).should eql(BigDecimal('-24.0'))
|
331
|
+
end
|
332
|
+
|
333
|
+
it 'returns decimal representation of a zero float' do
|
334
|
+
@property.typecast(0.0).should eql(BigDecimal('0.0'))
|
335
|
+
end
|
336
|
+
|
337
|
+
it 'returns decimal representation of a positive float' do
|
338
|
+
@property.typecast(24.35).should eql(BigDecimal('24.35'))
|
339
|
+
end
|
340
|
+
|
341
|
+
it 'returns decimal representation of a negative float' do
|
342
|
+
@property.typecast(-24.35).should eql(BigDecimal('-24.35'))
|
343
|
+
end
|
344
|
+
|
345
|
+
[ Object.new, true, '00.0', '0.', '-.0', 'string' ].each do |value|
|
346
|
+
it "does not typecast non-numeric value #{value.inspect}" do
|
347
|
+
@property.typecast(value).should equal(value)
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
describe 'when type primitive is a DateTime' do
|
353
|
+
before :all do
|
354
|
+
@property = @model.properties[:created_at]
|
355
|
+
end
|
356
|
+
|
357
|
+
describe 'and value given as a hash with keys like :year, :month, etc' do
|
358
|
+
it 'builds a DateTime instance from hash values' do
|
359
|
+
result = @property.typecast(
|
360
|
+
'year' => '2006',
|
361
|
+
'month' => '11',
|
362
|
+
'day' => '23',
|
363
|
+
'hour' => '12',
|
364
|
+
'min' => '0',
|
365
|
+
'sec' => '0'
|
366
|
+
)
|
367
|
+
|
368
|
+
result.should be_kind_of(DateTime)
|
369
|
+
result.year.should eql(2006)
|
370
|
+
result.month.should eql(11)
|
371
|
+
result.day.should eql(23)
|
372
|
+
result.hour.should eql(12)
|
373
|
+
result.min.should eql(0)
|
374
|
+
result.sec.should eql(0)
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
describe 'and value is a string' do
|
379
|
+
it 'parses the string' do
|
380
|
+
@property.typecast('Dec, 2006').month.should == 12
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
it 'does not typecast non-datetime values' do
|
385
|
+
@property.typecast('not-datetime').should eql('not-datetime')
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
describe 'when type primitive is a Date' do
|
390
|
+
before :all do
|
391
|
+
@property = @model.properties[:created_on]
|
392
|
+
end
|
393
|
+
|
394
|
+
describe 'and value given as a hash with keys like :year, :month, etc' do
|
395
|
+
it 'builds a Date instance from hash values' do
|
396
|
+
result = @property.typecast(
|
397
|
+
'year' => '2007',
|
398
|
+
'month' => '3',
|
399
|
+
'day' => '25'
|
400
|
+
)
|
401
|
+
|
402
|
+
result.should be_kind_of(Date)
|
403
|
+
result.year.should eql(2007)
|
404
|
+
result.month.should eql(3)
|
405
|
+
result.day.should eql(25)
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
describe 'and value is a string' do
|
410
|
+
it 'parses the string' do
|
411
|
+
result = @property.typecast('Dec 20th, 2006')
|
412
|
+
result.month.should == 12
|
413
|
+
result.day.should == 20
|
414
|
+
result.year.should == 2006
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
it 'does not typecast non-date values' do
|
419
|
+
@property.typecast('not-date').should eql('not-date')
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
describe 'when type primitive is a Time' do
|
424
|
+
before :all do
|
425
|
+
@property = @model.properties[:deleted_at]
|
426
|
+
end
|
427
|
+
|
428
|
+
describe 'and value given as a hash with keys like :year, :month, etc' do
|
429
|
+
it 'builds a Time instance from hash values' do
|
430
|
+
result = @property.typecast(
|
431
|
+
'year' => '2006',
|
432
|
+
'month' => '11',
|
433
|
+
'day' => '23',
|
434
|
+
'hour' => '12',
|
435
|
+
'min' => '0',
|
436
|
+
'sec' => '0'
|
437
|
+
)
|
438
|
+
|
439
|
+
result.should be_kind_of(Time)
|
440
|
+
result.year.should eql(2006)
|
441
|
+
result.month.should eql(11)
|
442
|
+
result.day.should eql(23)
|
443
|
+
result.hour.should eql(12)
|
444
|
+
result.min.should eql(0)
|
445
|
+
result.sec.should eql(0)
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
describe 'and value is a string' do
|
450
|
+
it 'parses the string' do
|
451
|
+
result = @property.typecast('22:24')
|
452
|
+
result.hour.should eql(22)
|
453
|
+
result.min.should eql(24)
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
it 'does not typecast non-time values' do
|
458
|
+
pending 'Time#parse is too permissive' do
|
459
|
+
@property.typecast('not-time').should eql('not-time')
|
460
|
+
end
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
describe 'when type primitive is a Class' do
|
465
|
+
before :all do
|
466
|
+
@property = @model.properties[:type]
|
467
|
+
end
|
468
|
+
|
469
|
+
it 'returns same value if a class' do
|
470
|
+
@property.typecast(@model).should equal(@model)
|
471
|
+
end
|
472
|
+
|
473
|
+
it 'returns the class if found' do
|
474
|
+
@property.typecast(@model.name).should eql(@model)
|
475
|
+
end
|
476
|
+
|
477
|
+
it 'does not typecast non-class values' do
|
478
|
+
@property.typecast('NoClass').should eql('NoClass')
|
479
|
+
end
|
480
|
+
end
|
481
|
+
|
482
|
+
describe 'when type primitive is a Boolean' do
|
483
|
+
before :all do
|
484
|
+
@property = @model.properties[:active]
|
485
|
+
end
|
486
|
+
|
487
|
+
[ true, 'true', 'TRUE', '1', 1, 't', 'T' ].each do |value|
|
488
|
+
it "returns true when value is #{value.inspect}" do
|
489
|
+
@property.typecast(value).should be_true
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
[ false, 'false', 'FALSE', '0', 0, 'f', 'F' ].each do |value|
|
494
|
+
it "returns false when value is #{value.inspect}" do
|
495
|
+
@property.typecast(value).should be_false
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
[ 'string', 2, 1.0, BigDecimal('1.0'), DateTime.now, Time.now, Date.today, Class, Object.new, ].each do |value|
|
500
|
+
it "does not typecast value #{value.inspect}" do
|
501
|
+
@property.typecast(value).should equal(value)
|
502
|
+
end
|
11
503
|
end
|
12
504
|
end
|
13
505
|
end
|
@@ -15,29 +507,53 @@ describe DataMapper::Property do
|
|
15
507
|
describe '#valid?' do
|
16
508
|
describe 'when provided a valid value' do
|
17
509
|
it 'should return true' do
|
18
|
-
|
510
|
+
@model.properties[:name].valid?('Dan Kubb').should be_true
|
19
511
|
end
|
20
512
|
end
|
21
513
|
|
22
514
|
describe 'when provide an invalid value' do
|
23
515
|
it 'should return false' do
|
24
|
-
|
516
|
+
@model.properties[:name].valid?(1).should be_false
|
25
517
|
end
|
26
518
|
end
|
27
519
|
|
28
520
|
describe 'when provide a nil value when not nullable' do
|
29
521
|
it 'should return false' do
|
30
|
-
|
522
|
+
@model.properties[:id].valid?(nil).should be_false
|
31
523
|
end
|
32
524
|
end
|
33
525
|
|
34
526
|
describe 'when provide a nil value when nullable' do
|
35
527
|
it 'should return false' do
|
36
|
-
|
528
|
+
@model.properties[:alias].valid?(nil).should be_true
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
532
|
+
describe 'when type primitive is a Boolean' do
|
533
|
+
before do
|
534
|
+
@property = @model.properties[:active]
|
535
|
+
end
|
536
|
+
|
537
|
+
[ true, false ].each do |value|
|
538
|
+
it "returns true when value is #{value.inspect}" do
|
539
|
+
@property.valid?(value).should be_true
|
540
|
+
end
|
541
|
+
end
|
542
|
+
|
543
|
+
[ 'true', 'TRUE', '1', 1, 't', 'T', 'false', 'FALSE', '0', 0, 'f', 'F' ].each do |value|
|
544
|
+
it "returns false for #{value.inspect}" do
|
545
|
+
@property.valid?(value).should be_false
|
546
|
+
end
|
37
547
|
end
|
38
548
|
end
|
39
549
|
end
|
40
550
|
|
551
|
+
describe '#value' do
|
552
|
+
it 'returns value for core types'
|
553
|
+
|
554
|
+
it 'triggers dump operation for custom types'
|
555
|
+
end
|
556
|
+
|
41
557
|
describe 'override property definition in other repository' do
|
42
558
|
before(:all) do
|
43
559
|
module ::Blog
|
@@ -50,12 +566,11 @@ describe DataMapper::Property do
|
|
50
566
|
end
|
51
567
|
|
52
568
|
it 'should return property options in other repository' do
|
53
|
-
|
569
|
+
@model.properties(:other)[:name].options[:field].should == 'other_name'
|
54
570
|
end
|
55
571
|
|
56
572
|
it 'should return property options in default repository' do
|
57
|
-
|
573
|
+
@model.properties[:name].options[:field].should be_nil
|
58
574
|
end
|
59
575
|
end
|
60
|
-
|
61
576
|
end
|
@@ -757,8 +757,8 @@ describe DataMapper::Query do
|
|
757
757
|
|
758
758
|
it { @return.should be_kind_of(DataMapper::Query) }
|
759
759
|
|
760
|
-
it 'should set conditions to
|
761
|
-
@return.conditions.should
|
760
|
+
it 'should set conditions to nil by default' do
|
761
|
+
@return.conditions.should be_nil
|
762
762
|
end
|
763
763
|
|
764
764
|
it 'should be valid' do
|
@@ -1346,7 +1346,7 @@ describe DataMapper::Query do
|
|
1346
1346
|
@other = OpenStruct.new(
|
1347
1347
|
:repository => @query.repository,
|
1348
1348
|
:model => @query.model,
|
1349
|
-
:
|
1349
|
+
:sorted_fields => @query.sorted_fields,
|
1350
1350
|
:links => @query.links,
|
1351
1351
|
:conditions => @query.conditions,
|
1352
1352
|
:order => @query.order,
|
@@ -1368,7 +1368,7 @@ describe DataMapper::Query do
|
|
1368
1368
|
@other = OpenStruct.new(
|
1369
1369
|
:repository => @query.repository,
|
1370
1370
|
:model => @query.model,
|
1371
|
-
:
|
1371
|
+
:sorted_fields => @query.sorted_fields,
|
1372
1372
|
:links => @query.links,
|
1373
1373
|
:conditions => @query.conditions,
|
1374
1374
|
:order => @query.order,
|
@@ -1458,7 +1458,7 @@ describe DataMapper::Query do
|
|
1458
1458
|
@other = OpenStruct.new(
|
1459
1459
|
:repository => @query.repository,
|
1460
1460
|
:model => @query.model,
|
1461
|
-
:
|
1461
|
+
:sorted_fields => @query.sorted_fields,
|
1462
1462
|
:links => @query.links,
|
1463
1463
|
:conditions => @query.conditions,
|
1464
1464
|
:order => @query.order,
|
@@ -1534,7 +1534,7 @@ describe DataMapper::Query do
|
|
1534
1534
|
@model=User
|
1535
1535
|
@fields=[#<DataMapper::Property @model=User @name=:name>, #<DataMapper::Property @model=User @name=:citizenship>, #<DataMapper::Property @model=User @name=:referrer_name>]
|
1536
1536
|
@links=[]
|
1537
|
-
@conditions
|
1537
|
+
@conditions=nil
|
1538
1538
|
@order=[#<DataMapper::Query::Direction @target=#<DataMapper::Property @model=User @name=:name> @operator=:asc>]
|
1539
1539
|
@limit=3
|
1540
1540
|
@offset=0
|
data/tasks/hoe.rb
CHANGED
@@ -40,6 +40,6 @@ hoe = Hoe.spec(GEM_NAME) do
|
|
40
40
|
|
41
41
|
self.rubyforge_name = PROJECT_NAME
|
42
42
|
|
43
|
-
clean_globs |= %w[ {coverage,doc,log,tmp} **/*.{log,db} profile_results.* **/.DS_Store spec/db ]
|
44
|
-
extra_deps |= GEM_DEPENDENCIES
|
43
|
+
self.clean_globs |= %w[ {coverage,doc,log,tmp} **/*.{log,db} profile_results.* **/.DS_Store spec/db ]
|
44
|
+
self.extra_deps |= GEM_DEPENDENCIES
|
45
45
|
end
|