activefacts-api 1.8.1 → 1.8.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,45 +0,0 @@
1
- require 'activefacts/api'
2
-
3
- module Tax
4
-
5
- class Name < String
6
- value_type
7
- end
8
-
9
- class Person
10
- identified_by :name
11
- one_to_one :name
12
- end
13
-
14
- class Australian < Person
15
- end
16
-
17
- class TaxPayer < Person
18
- end
19
-
20
- class TFN < Int
21
- value_type
22
- end
23
-
24
- class AustralianTaxPayer < Australian
25
- supertypes TaxPayer
26
- identified_by :tfn
27
- one_to_one :tfn, :class => TFN # Capitalisation rules!
28
- end
29
-
30
- class YearNr < Int
31
- value_type
32
- end
33
-
34
- class Year
35
- identified_by :year_nr
36
- one_to_one :year_nr
37
- end
38
-
39
- class AustralianTaxReturn
40
- identified_by :australian_tax_payer, :year
41
- has_one :australian_tax_payer
42
- has_one :year
43
- end
44
-
45
- end
@@ -1,420 +0,0 @@
1
- #
2
- # ActiveFacts tests: Value instances in the Runtime API
3
- # Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
4
- #
5
-
6
- describe "An Entity Type" do
7
- before :all do
8
- module ModIS
9
- class Name < String
10
- value_type
11
- end
12
-
13
- class Number < Int
14
- value_type
15
- end
16
- end
17
- end
18
- before :each do
19
- @c = ActiveFacts::API::Constellation.new(ModIS)
20
- end
21
-
22
- describe "whose instances are identified by a single value role" do
23
- before :all do
24
- module ModIS
25
- class Business
26
- identified_by :name
27
- one_to_one :name
28
- end
29
- end
30
- end
31
-
32
- it "should fail if the role isn't one-to-one" do
33
- proc do
34
- module ModIS
35
- class Cat
36
- identified_by :name
37
- has_one :name
38
- end
39
- end
40
- end.should raise_error(ActiveFacts::API::InvalidIdentificationException)
41
- end
42
-
43
- describe "when asserted" do
44
- before :each do
45
- @bus = @c.Business
46
- @bus = @c.Business('Acme')
47
- @acme = @c.Name['Acme']
48
- end
49
-
50
- it "should return a new instance if not previously present" do
51
- @bus.should be_a(ModIS::Business)
52
- end
53
-
54
- it "should assert the identifying value" do
55
- @acme.should be_a(ModIS::Name)
56
- end
57
-
58
- it "should be found in the constellation using the value" do
59
- @c.Business[['Acme']].should == @bus
60
- @c.Business[[@acme]].should == @bus
61
- end
62
-
63
- it "should belong to the constellation" do
64
- @bus.constellation.should == @c
65
- end
66
-
67
- it "should be assigned to the value's counterpart role" do
68
- @acme.business.should == @bus
69
- end
70
-
71
- it "should return a previously-existing instance" do
72
- @c.Business[['Acme']].should == @bus
73
- @c.Business.size.should == 1
74
- end
75
- end
76
-
77
- describe "when the value is changed" do
78
- before :each do
79
- @fly = @c.Business('Fly')
80
- @bus = @c.Business('Acme')
81
- @acme = @c.Name['Acme']
82
- end
83
-
84
- it "should fail if the new value already exists" do
85
- proc do
86
- @fly.name = 'Acme'
87
- end.should raise_error(ActiveFacts::API::DuplicateIdentifyingValueException)
88
- end
89
-
90
- it "should not fail if the new value is self" do
91
- lambda { @bus.name = 'Acme' }.should_not raise_error
92
- end
93
-
94
- describe "to a previously-nonexistent value" do
95
- before :each do
96
- @bus.name = 'Bloggs'
97
- end
98
-
99
- it "should assert the new identifier" do
100
- @c.Name['Bloggs'].should be_a(ModIS::Name)
101
- end
102
-
103
- it "should allow the change" do
104
- @bus.name.should == 'Bloggs'
105
- @c.Business.size.should == 2
106
- end
107
-
108
- it "should be found under the new identifier" do
109
- @c.Business[['Bloggs']].should == @bus
110
- end
111
-
112
- it "should be in the constellation's index under the new identifier" do
113
- @c.Business.keys.should include ['Bloggs']
114
- end
115
-
116
- it "should be the counterpart of the new identifier" do
117
- @c.Name['Bloggs'].business.should == @bus
118
- end
119
-
120
- it "should not be found in the constellation using the old value" do
121
- @c.Business[['Acme']].should be_nil
122
- end
123
-
124
- it "the old value's back-reference is set to nil" do
125
- @acme.business.should be_nil
126
- end
127
-
128
- #describe "and the old identifying value plays no other roles" do
129
- # describe "and the player of the identifying role is not independent" do
130
- # it "should retract the previous value" do
131
- # pending "All value types default to independent" do
132
- # @c.Name['Acme'].should be_nil
133
- # end
134
- # end
135
- # end
136
- #end
137
-
138
- end
139
- end
140
-
141
- describe "when retracted" do
142
- before :each do
143
- @bus = @c.Business('Acme')
144
- @acme = @c.Name['Acme']
145
- end
146
-
147
- it "should disappear from the constellation" do
148
- @bus.retract
149
- @c.Business[['Acme']].should be_nil
150
- end
151
-
152
- describe "and the identifying value plays no other roles" do
153
- describe "and the player of the identifying role is not independent" do
154
- before :each do
155
- @bus.retract
156
- end
157
-
158
- #it "should retract the identifying value also" do
159
- # pending "All value types default to independent" do
160
- # @c.Name['Acme'].should be_nil
161
- # end
162
- #end
163
-
164
- it "should not appear as the value's counterpart role" do
165
- @acme.business.should be_nil
166
- end
167
- end
168
-
169
- describe "and the identifying value plays other roles" do
170
- before :all do
171
- module ModIS
172
- class Dog
173
- identified_by :name
174
- one_to_one :name
175
- end
176
- end
177
- end
178
- before :each do
179
- @c.Dog("Acme")
180
- @bus.retract
181
- end
182
-
183
- it "should retain the identifying value, but with a nil counterpart role" do
184
- @c.Name['Acme'].should == @acme
185
- @acme.business.should be_nil
186
- end
187
- end
188
- end
189
- end
190
- end
191
-
192
- describe "identified by two values" do
193
- before :all do
194
- module ModIS
195
- class Building
196
- identified_by :name
197
- one_to_one :name
198
- end
199
-
200
- class Room
201
- identified_by :building, :number
202
- has_one :building
203
- has_one :number
204
- end
205
-
206
- class OwnershipId < Int
207
- value_type
208
- end
209
-
210
- class Owner
211
- identified_by :ownership_id, :building
212
- has_one :ownership_id
213
- has_one :building
214
- end
215
-
216
- class OwnerRoom
217
- identified_by :owner, :room
218
- has_one :owner
219
- has_one :room
220
- end
221
- end
222
- end
223
-
224
- before :each do
225
- @c = ActiveFacts::API::Constellation.new(ModIS)
226
- end
227
-
228
- it "should fail if any role is one-to-one" do
229
- proc do
230
- module ModIS
231
- class Floor
232
- identified_by :building, :number
233
- has_one :building
234
- one_to_one :number # Error, invalid identifier
235
- end
236
- end
237
- end.should raise_error(ActiveFacts::API::InvalidIdentificationException)
238
- end
239
-
240
- describe "when asserted" do
241
- before :each do
242
- @b = @c.Building('Mackay')
243
- @mackay = @c.Name['Mackay']
244
- @r = @c.Room(@b, 101)
245
- @rn = @r.number
246
-
247
- @o = @c.Owner(1_001, @b)
248
- @or = @c.OwnerRoom(@o, @r)
249
- end
250
-
251
- it "should return a new instance if not previously present" do
252
- @r.should be_a(ModIS::Room)
253
- end
254
-
255
- it "should assert the identifying values" do
256
- @rn.should be_a(ModIS::Number)
257
- @c.Number[@rn.identifying_role_values].should == @rn # Yes
258
- @c.Number[101].should == @rn # No
259
- @c.Number[101].should be_eql 101 # No
260
- end
261
-
262
- it "should be found in the constellation using the value" do
263
- @c.Room[[@b.identifying_role_values, @rn.identifying_role_values]].should == @r
264
- @c.Room[[@b.identifying_role_values, 101]].should == @r
265
- @c.Room[[['Mackay'], 101]].should == @r
266
- end
267
-
268
- it "should belong to the constellation" do
269
- @r.constellation.should == @c
270
- end
271
-
272
- it "should be added to the values' counterpart roles" do
273
- @rn.all_room.to_a.should == [@r]
274
- @b.all_room.to_a.should == [@r]
275
- end
276
-
277
- it "should return a previously-existing instance" do
278
- @c.Room(@b, 101).should == @r
279
- @c.Room(['Mackay'], 101).should == @r
280
- @c.Room.size.should == 1
281
- end
282
- end
283
-
284
- describe "when the value is changed" do
285
- before :each do
286
- @b = @c.Building('Mackay')
287
- @mackay = @c.Name['Mackay']
288
- @r = @c.Room(@b, 101)
289
- @rn = @r.number
290
-
291
- @o = @c.Owner(1_001, @b)
292
- @or = @c.OwnerRoom(@o, @r)
293
- end
294
-
295
- it "should fail if the new value already exists" do
296
- @c.Room(@b, 102)
297
- lambda { @r.number = 102 }.should raise_error(ActiveFacts::API::DuplicateIdentifyingValueException)
298
- end
299
-
300
- describe "to a previously-nonexistent value" do
301
- before :each do
302
- @r.number = 103
303
- @new_number = @r.number
304
- end
305
-
306
- it "should assert the new identifier" do
307
- @new_number.should_not be_nil
308
- end
309
-
310
- it "should allow the change" do
311
- @r.number.should == @new_number
312
- @r.number.should be_eql(103)
313
- end
314
-
315
- it "should be found under the new identifier" do
316
- @c.Room[[@b.identifying_role_values, 103]].should == @r
317
- @c.Room[[['Mackay'], 101]].should be_nil
318
- end
319
-
320
- it "should be found under the new identifier even on deep associations" do
321
- # p @c.OwnerRoom.keys[0]
322
- # p @new_number
323
- # p [@o.identifying_role_values, @r.identifying_role_values]
324
- @c.OwnerRoom[[@o.identifying_role_values, @r.identifying_role_values]].should == @or
325
- @c.OwnerRoom[[[1_001, ['Mackay']], [['Mackay'], 103]]].should == @or
326
- @c.OwnerRoom[[[1_001, ['Mackay']], [['Mackay'], 101]]].should be_nil
327
- end
328
-
329
- it "should be in the constellation's index under the new identifier" do
330
- @c.Room(['Mackay'], @r.number).should_not be_nil
331
- end
332
-
333
- it "should be included in the counterparts of the new identifier roles" do
334
- @b.all_room.to_a.should == [@r]
335
- @new_number.all_room.to_a.should == [@r]
336
- end
337
-
338
- it "should not be found in the constellation using the old value" do
339
- @c.Room.keys[0].should_not == [['Mackay'],101]
340
- end
341
-
342
- it "the old value's back-reference is set to nil" do
343
- # @rn.all_room.should_not include @r
344
- @rn.all_room.to_a.should_not include @r
345
- end
346
-
347
- #describe "and the old identifying value plays no other roles" do
348
- # describe "and the player of the identifying role is not independent" do
349
- # it "should retract the previous value" do
350
- # pending "All value types default to independent" do
351
- # @c.Number[101].should be_nil
352
- # end
353
- # end
354
- # end
355
- #end
356
- end
357
- end
358
-
359
- =begin
360
- describe "when retracted" do
361
- it "should disappear from the constellation"
362
- describe "and the identifying value plays no other roles" do
363
- describe "and the player of the identifying role is not independent" do
364
- it "should retract the identifying value also"
365
- it "should not appear as the value's counterpart role"
366
- end
367
- describe "and the identifying value plays other roles" do
368
- it "should retain the identifying value, but with a nil counterpart role"
369
- end
370
- end
371
- end
372
- =end
373
-
374
- end
375
-
376
- =begin
377
- describe "which inherits its identification from a supertype" do
378
- describe "which also has a secondary supertype" do
379
- end
380
- end
381
-
382
- describe "which has a supertype that has separate identification" do
383
- before :each do
384
- module ModIS
385
- class Animal
386
- identified_by :number
387
- one_to_one :neumber
388
- end
389
- class Dog < Animal
390
- identified_by :name
391
- one_to_one :name
392
- end
393
- end
394
- end
395
-
396
- describe "when asserted" do
397
- describe "and both identifiers are new" do
398
- it "should be found using the respective identifiers"
399
- end
400
- describe "and only the supertype identifier is new" do
401
- it "should be rejected because of the duplicate subtype identifier"
402
- end
403
- describe "and only the subtype identifier is new" do
404
- it "should be rejected because of the duplicate supertype identifier"
405
- end
406
- end
407
-
408
- describe "when the subtype identifier is changed" do
409
- it "should fail if the new subtype value already exists"
410
- it "should allow the change if the new subtype value doesn't already exist"
411
- end
412
-
413
- describe "when the supertype identifier is changed" do
414
- it "should fail if the new supertype value already exists"
415
- it "should allow the change if the new supertype value doesn't already exist"
416
- end
417
-
418
- end
419
- =end
420
- end