activefacts-api 0.8.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,124 @@
1
+ #
2
+ # ActiveFacts tests: Roles of object_type classes in the Runtime API
3
+ # Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
4
+ #
5
+ require 'activefacts/api'
6
+
7
+ describe "Roles" do
8
+ before :each do
9
+ Object.send :remove_const, :Mod if Object.const_defined?("Mod")
10
+ module Mod
11
+ class Name < String
12
+ value_type
13
+ end
14
+ class LegalEntity
15
+ identified_by :name
16
+ has_one :name
17
+ end
18
+ class Contract
19
+ identified_by :first, :second
20
+ has_one :first, :class => LegalEntity
21
+ has_one :second, :class => LegalEntity
22
+ end
23
+ class Person < LegalEntity
24
+ # identified_by # No identifier needed, inherit from superclass
25
+ # New identifier:
26
+ identified_by :family, :given
27
+ has_one :family, :class => Name
28
+ has_one :given, :class => Name
29
+ has_one :related_to, :class => LegalEntity
30
+ end
31
+ end
32
+ # print "object_type: "; p Mod.object_type
33
+ end
34
+
35
+ it "should associate a role name with a matching existing object_type" do
36
+ module Mod
37
+ class Existing1 < String
38
+ value_type
39
+ has_one :name
40
+ end
41
+ end
42
+ role = Mod::Existing1.roles(:name)
43
+ role.should_not be_nil
44
+ role.counterpart_object_type.should == Mod::Name
45
+ end
46
+
47
+ it "should inject the respective role name into the matching object_type" do
48
+ module Mod
49
+ class Existing1 < String
50
+ value_type
51
+ has_one :name
52
+ end
53
+ end
54
+ Mod::Name.roles(:all_existing1).should_not be_nil
55
+ Mod::LegalEntity.roles(:all_contract_as_first).should_not be_nil
56
+ end
57
+
58
+ it "should associate a role name with a matching object_type after it's created" do
59
+ module Mod
60
+ class Existing2 < String
61
+ value_type
62
+ has_one :given_name
63
+ end
64
+ end
65
+ # print "Mod::Existing2.roles = "; p Mod::Existing2.roles
66
+ r = Mod::Existing2.roles(:given_name)
67
+ r.should_not be_nil
68
+ Symbol.should === r.counterpart_object_type
69
+ module Mod
70
+ class GivenName < String
71
+ value_type
72
+ end
73
+ end
74
+ # puts "Should resolve now:"
75
+ r = Mod::Existing2.roles(:given_name)
76
+ r.should_not be_nil
77
+ r.counterpart_object_type.should == Mod::GivenName
78
+ end
79
+
80
+ it "should handle subtyping a value type" do
81
+ module Mod
82
+ class FamilyName < Name
83
+ value_type
84
+ one_to_one :patriarch, :class => Person
85
+ end
86
+ end
87
+ r = Mod::FamilyName.roles(:patriarch)
88
+ r.should_not be_nil
89
+ r.counterpart_object_type.should == Mod::Person
90
+ r.counterpart_object_type.roles(:family_name_as_patriarch).counterpart_object_type.should == Mod::FamilyName
91
+ end
92
+
93
+ it "should instantiate the matching object_type on assignment" do
94
+ c = ActiveFacts::API::Constellation.new(Mod)
95
+ bloggs = c.LegalEntity("Bloggs")
96
+ acme = c.LegalEntity("Acme, Inc")
97
+ contract = c.Contract("Bloggs", acme)
98
+ #contract = c.Contract("Bloggs", "Acme, Inc")
99
+ contract.first.should == bloggs
100
+ contract.second.should == acme
101
+ end
102
+
103
+ it "should append the counterpart into the respective role array in the matching object_type" do
104
+ foo = Mod::Name.new("Foo")
105
+ le = Mod::LegalEntity.new(foo)
106
+ le.respond_to?(:name).should be_true
107
+ name = le.name
108
+ name.respond_to?(:all_legal_entity).should be_true
109
+
110
+ #pending
111
+ Array(name.all_legal_entity).should === [le]
112
+ end
113
+
114
+ it "should instantiate subclasses sensibly" do
115
+ c = ActiveFacts::API::Constellation.new(Mod)
116
+ bloggs = c.LegalEntity("Bloggs & Co")
117
+ #pending
118
+ p = c.Person("Fred", "Bloggs")
119
+ p.related_to = "Bloggs & Co"
120
+ p.related_to.should be_is_a(Mod::LegalEntity)
121
+ bloggs.object_id.should == p.related_to.object_id
122
+ end
123
+
124
+ end
@@ -0,0 +1,114 @@
1
+ #
2
+ # ActiveFacts tests: Value types in the Runtime API
3
+ # Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
4
+ #
5
+ require 'activefacts/api'
6
+
7
+ describe "Value Type class definitions" do
8
+ before :each do
9
+ Object.send :remove_const, :Mod if Object.const_defined?("Mod")
10
+ module Mod
11
+ class Name < String
12
+ value_type
13
+ has_one :name
14
+ end
15
+ class Year < Int
16
+ value_type
17
+ has_one :name
18
+ end
19
+ class Weight < Real
20
+ value_type
21
+ has_one :name
22
+ end
23
+ end
24
+
25
+ @classes = [Mod::Name, Mod::Year,Mod::Weight]
26
+ @attrs = [:name, :name, :name]
27
+
28
+ end
29
+
30
+ it "should respond_to verbalise" do
31
+ @classes.each { |klass|
32
+ klass.respond_to?(:verbalise).should be_true
33
+ }
34
+ end
35
+
36
+ it "should not pollute the value class" do
37
+ @classes.each { |klass|
38
+ klass.superclass.respond_to?(:verbalise).should_not be_true
39
+ }
40
+ end
41
+
42
+ it "should return a string from verbalise" do
43
+ @classes.each { |klass|
44
+ v = klass.verbalise
45
+ v.should_not be_nil
46
+ v.should_not =~ /REVISIT/
47
+ }
48
+ end
49
+
50
+ it "should respond_to vocabulary" do
51
+ @classes.each { |klass|
52
+ klass.respond_to?(:vocabulary).should be_true
53
+ }
54
+ end
55
+
56
+ it "should return the parent module as the vocabulary" do
57
+ @classes.each { |klass|
58
+ vocabulary = klass.vocabulary
59
+ vocabulary.should == Mod
60
+ }
61
+ end
62
+
63
+ it "should return a vocabulary that knows about this object_type" do
64
+ @classes.each { |klass|
65
+ vocabulary = klass.vocabulary
66
+ vocabulary.respond_to?(:object_type).should be_true
67
+ vocabulary.object_type.has_key?(klass.basename).should be_true
68
+ }
69
+ end
70
+
71
+ it "should respond to roles()" do
72
+ @classes.each { |klass|
73
+ klass.respond_to?(:roles).should be_true
74
+ }
75
+ end
76
+
77
+ it "should contain only the added role definitions" do
78
+ Mod::Name.roles.size.should == 4
79
+ (@classes-[Mod::Name]).each { |klass|
80
+ klass.roles.size.should == 1
81
+ }
82
+ end
83
+
84
+ it "should return the role definition" do
85
+ # Check the role definition may not be accessed by passing an index:
86
+ Mod::Name.roles(0).should be_nil
87
+
88
+ @classes.zip(@attrs).each { |pair|
89
+ klass, attr = *pair
90
+ role = klass.roles(attr)
91
+ role.should_not be_nil
92
+
93
+ role = klass.roles(attr.to_s)
94
+ role.should_not be_nil
95
+
96
+ # Check the role definition may be accessed by indexing the returned array:
97
+ role = klass.roles[attr]
98
+ role.should_not be_nil
99
+
100
+ # Check the role definition array by .include?
101
+ klass.roles.include?(attr).should be_true
102
+ }
103
+ end
104
+
105
+ # REVISIT: role value constraints
106
+
107
+ it "should fail on a non-ValueClass" do
108
+ lambda{
109
+ class NameNotString
110
+ value_type
111
+ end
112
+ }.should raise_error
113
+ end
114
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'activefacts/api'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activefacts-api
3
+ version: !ruby/object:Gem::Version
4
+ hash: 45
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 8
9
+ - 9
10
+ version: 0.8.9
11
+ platform: ruby
12
+ authors:
13
+ - Clifford Heath
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-08 00:00:00 +11:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 2
32
+ - 3
33
+ - 0
34
+ version: 2.3.0
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: bundler
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 23
46
+ segments:
47
+ - 1
48
+ - 0
49
+ - 0
50
+ version: 1.0.0
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: jeweler
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 7
62
+ segments:
63
+ - 1
64
+ - 5
65
+ - 2
66
+ version: 1.5.2
67
+ type: :development
68
+ version_requirements: *id003
69
+ description: |
70
+
71
+ The ActiveFacts API is a Ruby DSL for managing constellations of elementary facts.
72
+ Each fact is either existential (a value or an entity), characteristic (boolean) or
73
+ binary relational (A rel B). Relational facts are consistently co-referenced, so you
74
+ can traverse them efficiently in any direction. Each constellation maintains constraints
75
+ over the fact population.
76
+
77
+ email: clifford.heath@gmail.com
78
+ executables: []
79
+
80
+ extensions: []
81
+
82
+ extra_rdoc_files:
83
+ - LICENSE.txt
84
+ - README.rdoc
85
+ files:
86
+ - .document
87
+ - .rspec
88
+ - LICENSE.txt
89
+ - README.rdoc
90
+ - Rakefile
91
+ - VERSION
92
+ - lib/activefacts/api.rb
93
+ - lib/activefacts/api/constellation.rb
94
+ - lib/activefacts/api/entity.rb
95
+ - lib/activefacts/api/instance.rb
96
+ - lib/activefacts/api/instance_index.rb
97
+ - lib/activefacts/api/numeric.rb
98
+ - lib/activefacts/api/object_type.rb
99
+ - lib/activefacts/api/role.rb
100
+ - lib/activefacts/api/role_proxy.rb
101
+ - lib/activefacts/api/role_values.rb
102
+ - lib/activefacts/api/standard_types.rb
103
+ - lib/activefacts/api/support.rb
104
+ - lib/activefacts/api/value.rb
105
+ - lib/activefacts/api/vocabulary.rb
106
+ - spec/api/autocounter_spec.rb
107
+ - spec/api/constellation_spec.rb
108
+ - spec/api/entity_type_spec.rb
109
+ - spec/api/instance_spec.rb
110
+ - spec/api/roles_spec.rb
111
+ - spec/api/value_type_spec.rb
112
+ - spec/spec_helper.rb
113
+ has_rdoc: true
114
+ homepage: http://github.com/cjheath/activefacts-api
115
+ licenses:
116
+ - MIT
117
+ post_install_message:
118
+ rdoc_options: []
119
+
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ hash: 3
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ hash: 3
137
+ segments:
138
+ - 0
139
+ version: "0"
140
+ requirements: []
141
+
142
+ rubyforge_project:
143
+ rubygems_version: 1.3.7
144
+ signing_key:
145
+ specification_version: 3
146
+ summary: A semantic modeling and query language (CQL) and application runtime (the Constellation API)
147
+ test_files:
148
+ - spec/api/autocounter_spec.rb
149
+ - spec/api/constellation_spec.rb
150
+ - spec/api/entity_type_spec.rb
151
+ - spec/api/instance_spec.rb
152
+ - spec/api/roles_spec.rb
153
+ - spec/api/value_type_spec.rb
154
+ - spec/spec_helper.rb