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.
- checksums.yaml +4 -4
- data/.gitignore +28 -0
- data/.rspec +0 -1
- data/Gemfile +1 -10
- data/Rakefile +3 -27
- data/VERSION +1 -1
- data/activefacts-api.gemspec +35 -95
- data/lib/activefacts/api/version.rb +5 -0
- data/lib/activefacts/tracer.rb +13 -9
- metadata +23 -68
- data/spec/constellation/constellation_spec.rb +0 -577
- data/spec/constellation/instance_index_spec.rb +0 -91
- data/spec/constellation/instance_spec.rb +0 -441
- data/spec/fact_type/role_values_spec.rb +0 -439
- data/spec/fact_type/roles_spec.rb +0 -283
- data/spec/fixtures/tax.rb +0 -45
- data/spec/identification_scheme/identification_spec.rb +0 -420
- data/spec/identification_scheme/identity_change_spec.rb +0 -119
- data/spec/identification_scheme/identity_supertype_change_spec.rb +0 -63
- data/spec/metadata_spec.rb +0 -267
- data/spec/object_type/entity_type/entity_type_spec.rb +0 -102
- data/spec/object_type/entity_type/multipart_identification_spec.rb +0 -82
- data/spec/object_type/value_type/autocounter_spec.rb +0 -87
- data/spec/object_type/value_type/date_time_spec.rb +0 -38
- data/spec/object_type/value_type/guid_spec.rb +0 -71
- data/spec/object_type/value_type/numeric_spec.rb +0 -63
- data/spec/object_type/value_type/value_type_spec.rb +0 -124
- data/spec/simplecov_helper.rb +0 -9
- data/spec/spec_helper.rb +0 -13
- data/spec/support/reduce_exceptions_helper.rb +0 -29
@@ -1,102 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# ActiveFacts tests: Entity classes in the Runtime API
|
3
|
-
# Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
|
4
|
-
#
|
5
|
-
|
6
|
-
describe "Entity Type class definitions" do
|
7
|
-
before :each do
|
8
|
-
Object.send :remove_const, :Mod if Object.const_defined?("Mod")
|
9
|
-
module Mod
|
10
|
-
class Name < String
|
11
|
-
value_type
|
12
|
-
end
|
13
|
-
class LegalEntity
|
14
|
-
end
|
15
|
-
class Person < LegalEntity
|
16
|
-
identified_by :name
|
17
|
-
one_to_one :name, :class => Name
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should respond_to verbalise" do
|
23
|
-
Mod::Person.respond_to?(:verbalise).should be true
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should not pollute the superclass" do
|
27
|
-
Mod::LegalEntity.respond_to?(:verbalise).should_not be true
|
28
|
-
Class.respond_to?(:verbalise).should_not be true
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should return a string from verbalise" do
|
32
|
-
v = Mod::Person.verbalise
|
33
|
-
v.should_not be_nil
|
34
|
-
v.should_not =~ /REVISIT/
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should respond_to vocabulary" do
|
38
|
-
Mod::Person.respond_to?(:vocabulary).should be true
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should return the parent module as the vocabulary" do
|
42
|
-
vocabulary = Mod::Person.vocabulary
|
43
|
-
vocabulary.should == Mod
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should return a vocabulary that knows about this object_type" do
|
47
|
-
vocabulary = Mod::Person.vocabulary
|
48
|
-
vocabulary.respond_to?(:object_type).should be true
|
49
|
-
vocabulary.object_type.has_key?("Person").should be_truthy
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should respond to all_role()" do
|
53
|
-
Mod::Person.respond_to?(:all_role).should be true
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should contain only the added role definition" do
|
57
|
-
Mod::Person.all_role.size.should == 1
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should return the role definition" do
|
61
|
-
# Check the role definition may be accessed by passing an index:
|
62
|
-
Mod::Person.all_role(0).should be_nil
|
63
|
-
|
64
|
-
role = Mod::Person.all_role(:name)
|
65
|
-
role.should_not be_nil
|
66
|
-
|
67
|
-
role = Mod::Person.all_role("name")
|
68
|
-
role.should_not be_nil
|
69
|
-
|
70
|
-
# Check the role definition may be accessed by indexing the returned hash:
|
71
|
-
role = Mod::Person.all_role[:name]
|
72
|
-
role.should_not be_nil
|
73
|
-
|
74
|
-
# Check the role definition array by .include?
|
75
|
-
Mod::Person.all_role.include?(:name).should be true
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should fail on a ValueType" do
|
79
|
-
lambda{
|
80
|
-
class SomeClass < String
|
81
|
-
identified_by :foo
|
82
|
-
end
|
83
|
-
}.should raise_error(ActiveFacts::API::InvalidEntityException)
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should return the identifying roles" do
|
87
|
-
Mod::Person.identifying_role_names.should == [:name]
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should prevent a role name from matching a object_type that exists unless that object_type is the counterpart" do
|
91
|
-
proc do
|
92
|
-
module Mod
|
93
|
-
class LegalEntity
|
94
|
-
end
|
95
|
-
class Bad
|
96
|
-
identified_by :name
|
97
|
-
has_one :name, :class => LegalEntity
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end.should raise_error(ActiveFacts::API::CrossVocabularyRoleException)
|
101
|
-
end
|
102
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'activefacts/api'
|
2
|
-
|
3
|
-
module TestMultiPartIdentifierModule
|
4
|
-
class ParentId < AutoCounter
|
5
|
-
value_type
|
6
|
-
end
|
7
|
-
|
8
|
-
class Parent
|
9
|
-
identified_by :parent_id
|
10
|
-
one_to_one :parent_id
|
11
|
-
end
|
12
|
-
|
13
|
-
class Position < Int
|
14
|
-
value_type
|
15
|
-
end
|
16
|
-
|
17
|
-
class Child
|
18
|
-
identified_by :parent, :position
|
19
|
-
has_one :parent
|
20
|
-
has_one :position
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "Multi-part identifiers" do
|
25
|
-
before :each do
|
26
|
-
@c = ActiveFacts::API::Constellation.new(TestMultiPartIdentifierModule)
|
27
|
-
@p = @c.Parent(:new)
|
28
|
-
@c0 = @c.Child(@p, 0)
|
29
|
-
@c2 = @c.Child(@p, 2)
|
30
|
-
@c1 = @c.Child(@p, 1)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should allow children to be found in the instance index" do
|
34
|
-
pv = @p.identifying_role_values
|
35
|
-
@c.Child[[pv, 0]].should == @c0
|
36
|
-
@c.Child[[pv, 1]].should == @c1
|
37
|
-
@c.Child[[pv, 2]].should == @c2
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should sort child keys in the instance index" do
|
41
|
-
pending "Key sorting is not supported on this index" unless @c.Child.sort
|
42
|
-
@c.Child.keys.should == [[[@p.parent_id], 0], [[@p.parent_id], 1], [[@p.parent_id], 2]]
|
43
|
-
@c.Child.map{|k, c| c.position}.should == [@c0.position, @c1.position, @c2.position]
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should index children in the parent's RoleValues" do
|
47
|
-
@p.all_child.size.should == 3
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should allow children to be found in the instance index by the whole key" do
|
51
|
-
@c.Child[[[@p.parent_id], 0]].should == @c0
|
52
|
-
@c.Child[[[@p.parent_id], 1]].should == @c1
|
53
|
-
@c.Child[[[@p.parent_id], 2]].should == @c2
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should sort children in the parent's RoleValues" do
|
57
|
-
pending "Key sorting is not supported in this version" if @p.all_child.instance_variable_get("@a").kind_of? Array
|
58
|
-
@p.all_child.to_a[0].should == @c0
|
59
|
-
@p.all_child.to_a[1].should == @c1
|
60
|
-
@p.all_child.to_a[2].should == @c2
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should allow children to be found in an identifying partner's RoleValues by the residual key" do
|
64
|
-
@p.all_child[0].should == @c0
|
65
|
-
@p.all_child[1].should == @c1
|
66
|
-
@p.all_child[2].should == @c2
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should use the correct residual key for each child in an identifying partner's RoleValues" do
|
70
|
-
if @p.all_child.instance_variable_get("@a").kind_of? Array
|
71
|
-
pending "Key sorting is not supported in this version"
|
72
|
-
end
|
73
|
-
|
74
|
-
@p.all_child.keys[0].should == [0]
|
75
|
-
@p.all_child.keys[1].should == [1]
|
76
|
-
@p.all_child.keys[2].should == [2]
|
77
|
-
|
78
|
-
# @p.all_child.keys[0].should == [[@p.parent_id], 0]
|
79
|
-
# @p.all_child.keys[1].should == [[@p.parent_id], 1]
|
80
|
-
# @p.all_child.keys[2].should == [[@p.parent_id], 2]
|
81
|
-
end
|
82
|
-
end
|
@@ -1,87 +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 "AutoCounter Value Type instances" do
|
7
|
-
before :each do
|
8
|
-
Object.send :remove_const, :Mod if Object.const_defined?("Mod")
|
9
|
-
module Mod
|
10
|
-
class ThingId < AutoCounter
|
11
|
-
value_type
|
12
|
-
end
|
13
|
-
class Thing
|
14
|
-
identified_by :thing_id
|
15
|
-
one_to_one :thing_id
|
16
|
-
end
|
17
|
-
class Ordinal < Int
|
18
|
-
value_type
|
19
|
-
end
|
20
|
-
class ThingFacet
|
21
|
-
identified_by :thing, :ordinal
|
22
|
-
has_one :thing
|
23
|
-
has_one :ordinal
|
24
|
-
end
|
25
|
-
end
|
26
|
-
@constellation = ActiveFacts::API::Constellation.new(Mod)
|
27
|
-
@thing = @constellation.Thing(:new)
|
28
|
-
@thing_id = @constellation.ThingId(:new)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should respond to verbalise" do
|
32
|
-
@thing_id.respond_to?(:verbalise).should be true
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should verbalise correctly" do
|
36
|
-
@thing_id.verbalise.should =~ /ThingId 'new_[0-9]+'/
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should respond to constellation" do
|
40
|
-
@thing_id.respond_to?(:constellation).should be true
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should respond to its roles" do
|
44
|
-
@thing_id.respond_to?(:thing).should be true
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should allow prevent invalid role assignment" do
|
48
|
-
lambda {
|
49
|
-
@thing.thing_id = "foo"
|
50
|
-
}.should raise_error(ArgumentError)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should not allow its value to be re-assigned" do
|
54
|
-
lambda {
|
55
|
-
@thing.thing_id.assign(3)
|
56
|
-
}.should_not raise_error
|
57
|
-
lambda {
|
58
|
-
@thing.thing_id.assign(4)
|
59
|
-
#@thing.thing_id.assign(@thing_id)
|
60
|
-
}.should raise_error(ArgumentError)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should allow an existing counter to be re-used" do
|
64
|
-
@new_thing = @constellation.Thing(@thing_id)
|
65
|
-
@new_thing.thing_id.to_s.should == @thing_id.to_s
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should return the ValueType in response to .class()" do
|
69
|
-
@thing_id.class.vocabulary.should == Mod
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should not allow a counter to be cloned" do
|
73
|
-
lambda {
|
74
|
-
@thing_id.clone
|
75
|
-
}.should raise_error(RuntimeError)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should allow an existing counter-identified object to be re-used" do
|
79
|
-
thing = @constellation.Thing(:new)
|
80
|
-
facets = []
|
81
|
-
facets << @constellation.ThingFacet(thing, 0)
|
82
|
-
facets << @constellation.ThingFacet(thing, 1)
|
83
|
-
facets[0].thing.should be_eql(facets[1].thing)
|
84
|
-
facets[0].thing.thing_id.should be_eql(facets[1].thing.thing_id)
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# ActiveFacts tests: Value instances in the Runtime API
|
3
|
-
# Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
|
4
|
-
#
|
5
|
-
require 'activefacts/api'
|
6
|
-
|
7
|
-
describe Date do
|
8
|
-
it "should construct with no arguments" do
|
9
|
-
proc {
|
10
|
-
@d = Date.new()
|
11
|
-
}.should_not raise_error
|
12
|
-
@d.year.should == -4712
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should construct with a nil argument" do
|
16
|
-
proc {
|
17
|
-
@d = Date.new_instance(nil, nil)
|
18
|
-
}.should_not raise_error
|
19
|
-
@d.year.should == -4712
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should construct with a full arguments" do
|
23
|
-
proc {
|
24
|
-
@d = Date.civil(2012, 10, 31)
|
25
|
-
}.should_not raise_error
|
26
|
-
@d.to_s.should == "2012-10-31"
|
27
|
-
end
|
28
|
-
|
29
|
-
=begin
|
30
|
-
it "should be encodable in JSON" do
|
31
|
-
proc {
|
32
|
-
@d = Date.new(2012, 10, 31)
|
33
|
-
@d.to_json.should == "REVISIT"
|
34
|
-
}.should_not raise_error
|
35
|
-
end
|
36
|
-
=end
|
37
|
-
|
38
|
-
end
|
@@ -1,71 +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 "Guid Value Type instances" do
|
7
|
-
before :each do
|
8
|
-
Object.send :remove_const, :Mod if Object.const_defined?("Mod")
|
9
|
-
module Mod
|
10
|
-
class ThingId < Guid
|
11
|
-
value_type
|
12
|
-
end
|
13
|
-
class Thing
|
14
|
-
identified_by :thing_id
|
15
|
-
one_to_one :thing_id
|
16
|
-
end
|
17
|
-
class Ordinal < Int
|
18
|
-
value_type
|
19
|
-
end
|
20
|
-
class ThingFacet
|
21
|
-
identified_by :thing, :ordinal
|
22
|
-
has_one :thing
|
23
|
-
has_one :ordinal
|
24
|
-
end
|
25
|
-
end
|
26
|
-
@constellation = ActiveFacts::API::Constellation.new(Mod)
|
27
|
-
@thing = @constellation.Thing(:new)
|
28
|
-
@thing_id = @constellation.ThingId(:new)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should respond to verbalise" do
|
32
|
-
@thing_id.respond_to?(:verbalise).should be true
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should verbalise correctly" do
|
36
|
-
@thing_id.verbalise.should =~ /ThingId '[-0-9a-f]{36}'/i
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should respond to constellation" do
|
40
|
-
@thing_id.respond_to?(:constellation).should be true
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should respond to its roles" do
|
44
|
-
@thing_id.respond_to?(:thing).should be true
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should allow prevent invalid role assignment" do
|
48
|
-
lambda {
|
49
|
-
@thing.thing_id = "foo"
|
50
|
-
}.should raise_error(ArgumentError)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should allow an existing guid to be re-used" do
|
54
|
-
@new_thing = @constellation.Thing(@thing_id)
|
55
|
-
@new_thing.thing_id.should == @thing_id
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should return the ValueType in response to .class()" do
|
59
|
-
@thing_id.class.vocabulary.should == Mod
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should allow an existing guid-identified object to be re-used" do
|
63
|
-
thing = @constellation.Thing(:new)
|
64
|
-
facets = []
|
65
|
-
facets << @constellation.ThingFacet(thing, 0)
|
66
|
-
facets << @constellation.ThingFacet(thing, 1)
|
67
|
-
facets[0].thing.should be_eql(facets[1].thing)
|
68
|
-
facets[0].thing.thing_id.should be_eql(facets[1].thing.thing_id)
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
@@ -1,63 +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 Int do
|
7
|
-
before :each do
|
8
|
-
@i = Int.new(1)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should be encodable in JSON" do
|
12
|
-
@i.to_json.should == "1"
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should behave like an Integer" do
|
16
|
-
1.should == @i
|
17
|
-
@i.should == 1
|
18
|
-
@i.to_s.should == "1"
|
19
|
-
@i.should eql 1
|
20
|
-
@i.should be_an Integer
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should also know that it's a delegator" do
|
24
|
-
@i.is_a?(SimpleDelegator).should be true
|
25
|
-
@i.is_a?(Int).should be true
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe Real do
|
30
|
-
before :each do
|
31
|
-
@r = Real.new(1.0)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should be encodable in JSON" do
|
35
|
-
@r.to_json.should == "1.0"
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should behave like a Float" do
|
39
|
-
1.0.should == @r
|
40
|
-
@r.should == 1.0
|
41
|
-
@r.to_s.should == "1.0"
|
42
|
-
@r.eql?(1.0).should be true
|
43
|
-
@r.is_a?(Float).should be true
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should also know that it's a delegator" do
|
47
|
-
@r.is_a?(SimpleDelegator).should be true
|
48
|
-
@r.is_a?(Real).should be true
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe Decimal do
|
53
|
-
it "should still detect Decimal as the main class" do
|
54
|
-
bd = Decimal.new("98765432109876543.210")
|
55
|
-
bd.to_s("F").should == "98765432109876543.21"
|
56
|
-
bd.to_s("E").should == "0.9876543210987654321E17"
|
57
|
-
bd.to_s("3E").should =~ /0.987 654 321 098 765 432 1.*E17/
|
58
|
-
bd.to_s(3).should =~ /0.987 654 321 098 765 432 1.*E17/
|
59
|
-
bd.to_s("3F").should == "987 654 321 098 765 43.21"
|
60
|
-
bd.should be_a Decimal
|
61
|
-
bd.should be_a BigDecimal
|
62
|
-
end
|
63
|
-
end
|