lore 0.4.2
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/LICENSE +19 -0
- data/README +74 -0
- data/aspect.rb +80 -0
- data/behaviours/lockable.rb +41 -0
- data/behaviours/movable.rb +54 -0
- data/behaviours/versioned.rb +24 -0
- data/benchmark.rb +193 -0
- data/bits.rb +52 -0
- data/cache/abstract_entity_cache.rb +82 -0
- data/cache/bits.rb +22 -0
- data/cache/cacheable.rb +202 -0
- data/cache/cached_entities.rb +116 -0
- data/cache/file_index.rb +35 -0
- data/cache/mmap_entity_cache.rb +67 -0
- data/clause.rb +528 -0
- data/connection.rb +155 -0
- data/custom_functions.sql +14 -0
- data/exception/ambiguous_attribute.rb +14 -0
- data/exception/cache_exception.rb +30 -0
- data/exception/invalid_klass_parameters.rb +63 -0
- data/exception/invalid_parameter.rb +42 -0
- data/exception/unknown_typecode.rb +19 -0
- data/file_index.sql +56 -0
- data/gui/erb_template.rb +79 -0
- data/gui/erb_template_helpers.rhtml +19 -0
- data/gui/form.rb +314 -0
- data/gui/form_element.rb +676 -0
- data/gui/form_generator.rb +151 -0
- data/gui/templates/button.rhtml +2 -0
- data/gui/templates/checkbox.rhtml +3 -0
- data/gui/templates/checkbox_row.rhtml +1 -0
- data/gui/templates/file.rhtml +2 -0
- data/gui/templates/file_readonly.rhtml +3 -0
- data/gui/templates/form_element.rhtml +5 -0
- data/gui/templates/form_element_horizontal.rhtml +3 -0
- data/gui/templates/form_element_listed.rhtml +8 -0
- data/gui/templates/form_table.rhtml +3 -0
- data/gui/templates/form_table_blank.rhtml +3 -0
- data/gui/templates/form_table_horizontal.rhtml +8 -0
- data/gui/templates/password.rhtml +2 -0
- data/gui/templates/password_readonly.rhtml +3 -0
- data/gui/templates/radio.rhtml +1 -0
- data/gui/templates/radio_row.rhtml +1 -0
- data/gui/templates/select.rhtml +23 -0
- data/gui/templates/text.rhtml +2 -0
- data/gui/templates/text_readonly.rhtml +3 -0
- data/gui/templates/textarea.rhtml +3 -0
- data/gui/templates/textarea_readonly.rhtml +4 -0
- data/lore.gemspec +40 -0
- data/lore.rb +94 -0
- data/migration.rb +48 -0
- data/model.rb +139 -0
- data/model_factory.rb +202 -0
- data/model_shortcuts.rb +16 -0
- data/query_shortcuts.rb +367 -0
- data/reserved_methods.txt +3 -0
- data/result.rb +100 -0
- data/symbol.rb +58 -0
- data/table_accessor.rb +1926 -0
- data/table_deleter.rb +115 -0
- data/table_inserter.rb +168 -0
- data/table_instance.rb +384 -0
- data/table_selector.rb +314 -0
- data/table_updater.rb +155 -0
- data/test/README +31 -0
- data/test/env.rb +5 -0
- data/test/lore_test.log +8218 -0
- data/test/model.rb +142 -0
- data/test/prepare.rb +37 -0
- data/test/tc_aspect.rb +58 -0
- data/test/tc_cache.rb +80 -0
- data/test/tc_clause.rb +104 -0
- data/test/tc_deep_inheritance.rb +49 -0
- data/test/tc_factory.rb +57 -0
- data/test/tc_filter.rb +37 -0
- data/test/tc_form.rb +32 -0
- data/test/tc_model.rb +86 -0
- data/test/tc_prepare.rb +45 -0
- data/test/tc_refined_query.rb +88 -0
- data/test/tc_table_accessor.rb +265 -0
- data/test/test.log +181 -0
- data/test/test_db.sql +400 -0
- data/test/ts_lore.rb +49 -0
- data/types.rb +55 -0
- data/validation/message.rb +60 -0
- data/validation/parameter_validator.rb +104 -0
- data/validation/reason.rb +54 -0
- data/validation/type_validator.rb +91 -0
- data/validation.rb +65 -0
- metadata +170 -0
data/test/model.rb
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require('lore/test/env')
|
|
4
|
+
require('lore/model')
|
|
5
|
+
|
|
6
|
+
Lore::Context.enter :test
|
|
7
|
+
|
|
8
|
+
module Lore
|
|
9
|
+
module Unit
|
|
10
|
+
|
|
11
|
+
NAME_FORMAT = { :format => /^([a-zA-Z_0-9])+$/, :length => 3..100, :mandatory => true }
|
|
12
|
+
|
|
13
|
+
class Manufacturer < Lore::Model
|
|
14
|
+
table :manufacturer, :public
|
|
15
|
+
primary_key :manuf_id, :manuf_id_seq
|
|
16
|
+
|
|
17
|
+
validates :name, NAME_FORMAT
|
|
18
|
+
|
|
19
|
+
use_label :name
|
|
20
|
+
|
|
21
|
+
cache_entities
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class Owner < Lore::Model
|
|
25
|
+
table :owner, :public
|
|
26
|
+
primary_key :owner_id, :owner_id_seq
|
|
27
|
+
|
|
28
|
+
validates :name, NAME_FORMAT
|
|
29
|
+
|
|
30
|
+
cache_entities
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class Vehicle < Lore::Model
|
|
34
|
+
table :vehicle, :public
|
|
35
|
+
primary_key :id, :vehicle_id_seq
|
|
36
|
+
|
|
37
|
+
has_a Manufacturer, :manuf_id
|
|
38
|
+
has_n Owner, :vehicle_id
|
|
39
|
+
|
|
40
|
+
validates :name, NAME_FORMAT
|
|
41
|
+
validates :maxspeed, :mandatory => true
|
|
42
|
+
validates :num_seats, :mandatory => true
|
|
43
|
+
|
|
44
|
+
add_input_filter(:name) { |name|
|
|
45
|
+
name.gsub(/[^a-zA-Z_0-9]/,'').downcase
|
|
46
|
+
}
|
|
47
|
+
add_input_filter(:maxspeed) { |m| m.to_s.gsub('km/h','') }
|
|
48
|
+
add_output_filter(:maxspeed) { |m| m << 'km/h' }
|
|
49
|
+
|
|
50
|
+
explicit :optional, :owner_id
|
|
51
|
+
|
|
52
|
+
# add_select_filter { |clause| clause & (Vehicle.deleted == 't') }
|
|
53
|
+
|
|
54
|
+
cache_entities
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
class Vehicle_Owner < Lore::Model
|
|
58
|
+
table :vehicle_owner, :public
|
|
59
|
+
primary_key :vehicle_id
|
|
60
|
+
primary_key :owner_id
|
|
61
|
+
# aggregates Vehicle, :vehicle_id
|
|
62
|
+
# aggregates Owner, :owner_id
|
|
63
|
+
# maps Vehicle, Owner
|
|
64
|
+
|
|
65
|
+
def get_owner()
|
|
66
|
+
Owner.find(1).with(Owner.owner_id == owner_id).entity
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
class Car_Type < Lore::Model
|
|
71
|
+
table :car_type, :public
|
|
72
|
+
primary_key :car_type_id, :car_type_id_seq
|
|
73
|
+
|
|
74
|
+
validates :name, NAME_FORMAT
|
|
75
|
+
|
|
76
|
+
use_label :name
|
|
77
|
+
|
|
78
|
+
cache_entities
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
class Car < Vehicle
|
|
82
|
+
table :car, :public
|
|
83
|
+
primary_key :id, :car_id_seq
|
|
84
|
+
|
|
85
|
+
is_a Vehicle, :vehicle_id
|
|
86
|
+
aggregates Car_Type, :car_type_id
|
|
87
|
+
|
|
88
|
+
validates :num_seats, :mandatory => true
|
|
89
|
+
validates :num_doors, :mandatory => true
|
|
90
|
+
|
|
91
|
+
add_input_filter(:maxspeed) { |m| m.to_s.gsub('km/h','') }
|
|
92
|
+
add_output_filter(:maxspeed) { |m| m << 'km/h' }
|
|
93
|
+
|
|
94
|
+
cache_entities
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
class Convertible < Car
|
|
98
|
+
table :convertible, :public
|
|
99
|
+
primary_key :id, :convertible_id_seq
|
|
100
|
+
is_a Car, :car_id
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
class Trailer < Lore::Model
|
|
104
|
+
table :trailer, :public
|
|
105
|
+
primary_key :trailer_id, :trailer_id_seq
|
|
106
|
+
|
|
107
|
+
aggregates Car, :car_id
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
class Bike < Vehicle
|
|
111
|
+
table :bike, :public
|
|
112
|
+
primary_key :bike_id, :bike_id_seq
|
|
113
|
+
|
|
114
|
+
is_a Vehicle, :vehicle_id
|
|
115
|
+
|
|
116
|
+
cache_entities
|
|
117
|
+
end
|
|
118
|
+
=begin
|
|
119
|
+
class Trike < Vehicle
|
|
120
|
+
table :trike, :public
|
|
121
|
+
primary_key :trike_id, :trike_id_seq
|
|
122
|
+
|
|
123
|
+
is_a Car, :car_id
|
|
124
|
+
is_a Bike, :bike_id
|
|
125
|
+
|
|
126
|
+
cache_entities
|
|
127
|
+
end
|
|
128
|
+
=end
|
|
129
|
+
class Garage < Lore::Model
|
|
130
|
+
table :garage, :public
|
|
131
|
+
primary_key :garage_id, :garage_id_seq
|
|
132
|
+
primary_key :vehicle_id
|
|
133
|
+
|
|
134
|
+
has_n Vehicle, :vehicle_id
|
|
135
|
+
|
|
136
|
+
cache_entities
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
|
data/test/prepare.rb
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require 'cuba'
|
|
4
|
+
require 'lore'
|
|
5
|
+
require 'lore/connection'
|
|
6
|
+
|
|
7
|
+
Lore::Context.enter :aurita
|
|
8
|
+
|
|
9
|
+
Cuba.import_imp_model :wiki, :article
|
|
10
|
+
|
|
11
|
+
include Cuba::Wiki
|
|
12
|
+
|
|
13
|
+
STDERR.puts '----------------------------------------'
|
|
14
|
+
|
|
15
|
+
Article.all.entities
|
|
16
|
+
|
|
17
|
+
Article.select { |art|
|
|
18
|
+
art.join(User_Group).using(:user_group_id) { |a|
|
|
19
|
+
a.where((Article.content_id > '100') & (Article.title == 'foo') |
|
|
20
|
+
(Article.content_id < '200') & (Article.title <=> 'bar') & (Article.published == 't'))
|
|
21
|
+
a.limit(10)
|
|
22
|
+
a.order_by(Article.article_id, :desc)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
STDERR.puts '----------------------------------------'
|
|
27
|
+
|
|
28
|
+
=begin
|
|
29
|
+
Article.prepare(:by_id, Lore::Type.integer) { |a|
|
|
30
|
+
a.where(Article.article_id == Lore::Clause.new('$1'))
|
|
31
|
+
}
|
|
32
|
+
2.times do
|
|
33
|
+
p Article.find(1).with(Article.article_id == '1001').entity.article_id
|
|
34
|
+
# Article.by_id(1001).first.article_id
|
|
35
|
+
end
|
|
36
|
+
=end
|
|
37
|
+
|
data/test/tc_aspect.rb
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require('lore/test/model')
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
module Lore
|
|
7
|
+
module Unit
|
|
8
|
+
|
|
9
|
+
# Extend Car by hooks:
|
|
10
|
+
class Car
|
|
11
|
+
def self.pre_create(attrib_hash)
|
|
12
|
+
attrib_hash[:aspect_pre_value] = 'ChangedPre'
|
|
13
|
+
end
|
|
14
|
+
def self.post_create(obj)
|
|
15
|
+
obj[:aspect_post_value] = 'ChangedPost'
|
|
16
|
+
end
|
|
17
|
+
def self.pre_commit(obj)
|
|
18
|
+
obj[:maxspeed] = 120
|
|
19
|
+
end
|
|
20
|
+
def self.post_commit(obj)
|
|
21
|
+
obj[:num_seats] = 5
|
|
22
|
+
end
|
|
23
|
+
def self.pre_delete(obj)
|
|
24
|
+
end
|
|
25
|
+
def self.post_delete()
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class TC_Aspect < Test::Unit::TestCase
|
|
30
|
+
|
|
31
|
+
def setup
|
|
32
|
+
@@ct = Car_Type.create(:name => 'Pickup')
|
|
33
|
+
@@ac = Car.create(:name => 'Foo',
|
|
34
|
+
:aspect_pre_value => 'WillChange',
|
|
35
|
+
:aspect_post_value => 'WillChange',
|
|
36
|
+
:maxspeed => 100,
|
|
37
|
+
:num_doors => 5,
|
|
38
|
+
:manuf_id => 1,
|
|
39
|
+
:num_seats => 4,
|
|
40
|
+
:car_type_id => @@ct.car_type_id)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_create
|
|
44
|
+
assert_equal(@@ac.aspect_pre_value, 'ChangedPre')
|
|
45
|
+
assert_equal(@@ac.aspect_post_value, 'ChangedPost')
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_update
|
|
49
|
+
@@ac[:name] = 'RedPickup'
|
|
50
|
+
@@ac.commit
|
|
51
|
+
assert_equal(@@ac.num_seats.to_s, '5')
|
|
52
|
+
assert_equal(@@ac.maxspeed.to_s, '120')
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
end
|
data/test/tc_cache.rb
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
|
|
4
|
+
require('lore/test/model')
|
|
5
|
+
require('lore/test/ts_lore')
|
|
6
|
+
|
|
7
|
+
module Lore
|
|
8
|
+
module Unit
|
|
9
|
+
|
|
10
|
+
class TC_Cache < Test::Unit::TestCase
|
|
11
|
+
|
|
12
|
+
def setup
|
|
13
|
+
m1 = Manufacturer.create( :name => 'BMW' )
|
|
14
|
+
m2 = Manufacturer.create( :name => 'Mercedes' )
|
|
15
|
+
m3 = Manufacturer.create( :name => 'Audi' )
|
|
16
|
+
|
|
17
|
+
ct1 = Car_Type.create( :name => 'Limousine' )
|
|
18
|
+
ct2 = Car_Type.create( :name => 'SUV' )
|
|
19
|
+
ct3 = Car_Type.create( :name => 'Cabrio' )
|
|
20
|
+
ct4 = Car_Type.create( :name => 'Boxter' )
|
|
21
|
+
|
|
22
|
+
c1 = Car.create(
|
|
23
|
+
:manuf_id => m2.manuf_id,
|
|
24
|
+
:name => 'SLK',
|
|
25
|
+
:num_seats => 2,
|
|
26
|
+
:maxspeed => 180,
|
|
27
|
+
:num_doors => 3,
|
|
28
|
+
:car_type_id => ct3.car_type_id
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def teardown
|
|
33
|
+
Manufacturer.delete_all
|
|
34
|
+
Vehicle.delete_all
|
|
35
|
+
Car_Type.delete_all
|
|
36
|
+
Car.delete_all
|
|
37
|
+
Bike.delete_all
|
|
38
|
+
Owner.delete_all
|
|
39
|
+
Garage.delete_all
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_basic
|
|
43
|
+
passed = true
|
|
44
|
+
org_name = Car.all.entity.name
|
|
45
|
+
20.times {
|
|
46
|
+
cached_inst = Car.all.entity
|
|
47
|
+
cached_name = cached_inst.name
|
|
48
|
+
passed = passed && (org_name == cached_name)
|
|
49
|
+
assert_equal(org_name, cached_name)
|
|
50
|
+
passed = passed && (!Lore.cache_enabled? || cached_inst.is_cached_entity?)
|
|
51
|
+
}
|
|
52
|
+
assert(passed, 'Cached value and original value differ (This will fail if caching is not configured, doing no harm)')
|
|
53
|
+
|
|
54
|
+
20.times {
|
|
55
|
+
cached_inst = Car.all.entity
|
|
56
|
+
cached_name = cached_inst.name
|
|
57
|
+
passed = passed && (org_name == cached_name)
|
|
58
|
+
assert_equal(org_name, cached_name)
|
|
59
|
+
cached_inst[:name] = 'Changed'
|
|
60
|
+
passed = passed && (cached_inst.name == 'Changed')
|
|
61
|
+
assert_equal(cached_inst.name, 'Changed')
|
|
62
|
+
cached_inst.commit
|
|
63
|
+
passed = passed && (!Lore.cache_enabled? || !cached_inst.is_cached_entity?)
|
|
64
|
+
}
|
|
65
|
+
assert(passed, 'Cached value and original value differ')
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_random_select
|
|
69
|
+
# Random selects must not be cached under any circumstances.
|
|
70
|
+
random_car = Car.select('*, random() as rand') { |rcar|
|
|
71
|
+
rcar.where(true)
|
|
72
|
+
rcar.order_by(:rand, :desc)
|
|
73
|
+
rcar.limit(1)
|
|
74
|
+
}.first
|
|
75
|
+
assert(!random_car.loaded_from_cache)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
data/test/tc_clause.rb
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require('lore/test/model')
|
|
4
|
+
require('lore/clause')
|
|
5
|
+
|
|
6
|
+
module Lore
|
|
7
|
+
module Unit
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TC_Clause < Test::Unit::TestCase
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def clean(query)
|
|
15
|
+
return query.gsub("\n",'').gsub("\t",' ').gsub(/(\s+)/,' ')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
public
|
|
19
|
+
|
|
20
|
+
def setup
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def teardown
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_models
|
|
27
|
+
assert(Car.table_name == 'public.car')
|
|
28
|
+
assert(Vehicle.table_name == 'public.vehicle')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_attribte_clauses
|
|
32
|
+
assert(Car.vehicle_id.to_s == 'public.car.vehicle_id', 'clause failed: ' << Car.vehicle_id.to_s)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_inherited_attributes
|
|
36
|
+
# Attribute only in derived model:
|
|
37
|
+
assert_equal('public.car.vehicle_id', Car.vehicle_id.to_s)
|
|
38
|
+
# Attribute in both base and derived model (default to derived model):
|
|
39
|
+
assert_equal('public.car.id', Car.id.to_s)
|
|
40
|
+
# Attribute only in base model (redirect to base model attribute);
|
|
41
|
+
assert_equal('public.vehicle.name', Car.name.to_s)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_logic
|
|
45
|
+
|
|
46
|
+
(Car.name == 'foo') & (Car.vehicle_id == '23')
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_operators
|
|
51
|
+
s1 = Car.name == Vehicle.name
|
|
52
|
+
s1_sql = 'public.vehicle.name = public.vehicle.name'
|
|
53
|
+
assert(clean(s1.to_s) == s1_sql, s1.to_s + ' != ' << s1_sql)
|
|
54
|
+
|
|
55
|
+
s2 = Car.name.not_in(
|
|
56
|
+
Vehicle.select(Vehicle.name) { |v| v.where(v.id == 1) }
|
|
57
|
+
)
|
|
58
|
+
s2_sql = "public.vehicle.name NOT IN (SELECT public.vehicle.name FROM public.vehicle WHERE public.vehicle.id = '1' ) "
|
|
59
|
+
assert_equal(clean(s2.to_s), s2_sql)
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_select_value
|
|
64
|
+
ct = Car_Type.create( :name => 'Pickup' )
|
|
65
|
+
Car.create(
|
|
66
|
+
:manuf_id => 1,
|
|
67
|
+
:name => 'SLK',
|
|
68
|
+
:num_seats => 2,
|
|
69
|
+
:maxspeed => 180,
|
|
70
|
+
:num_doors => 3,
|
|
71
|
+
:car_type_id => ct.car_type_id
|
|
72
|
+
)
|
|
73
|
+
latest_car = Car.create(
|
|
74
|
+
:manuf_id => 1,
|
|
75
|
+
:name => 'SLK2',
|
|
76
|
+
:num_seats => 2,
|
|
77
|
+
:maxspeed => 180,
|
|
78
|
+
:num_doors => 3,
|
|
79
|
+
:car_type_id => ct.car_type_id
|
|
80
|
+
)
|
|
81
|
+
all_car_names = Car.all(Car.name).entities
|
|
82
|
+
assert(all_car_names.include?('slk'))
|
|
83
|
+
assert(all_car_names.include?('slk2'))
|
|
84
|
+
assert_equal Car.value_of.max(Car.vehicle_id).to_i, latest_car.vehicle_id.to_i
|
|
85
|
+
assert_equal Car.value_of.max(Car.vehicle_id).to_i, Car.value_of.max('public.vehicle.id').to_i
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def test_ranges
|
|
90
|
+
Car.select { |c|
|
|
91
|
+
c.where(c.id.in([1,2,3,4]))
|
|
92
|
+
}
|
|
93
|
+
Car.select { |c|
|
|
94
|
+
c.where(c.id.in(1..4))
|
|
95
|
+
}
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def test_having
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require 'lore/test/model'
|
|
4
|
+
require 'lore/symbol'
|
|
5
|
+
|
|
6
|
+
module Lore
|
|
7
|
+
module Unit
|
|
8
|
+
|
|
9
|
+
class TC_Deep_Inheritancei < Test::Unit::TestCase
|
|
10
|
+
|
|
11
|
+
def test_create
|
|
12
|
+
|
|
13
|
+
Manufacturer.delete_all
|
|
14
|
+
Vehicle.delete_all
|
|
15
|
+
Car.delete_all
|
|
16
|
+
Car_Type.delete_all
|
|
17
|
+
|
|
18
|
+
m = Manufacturer.create(:name => 'temp')
|
|
19
|
+
o = Owner.create(:name => 'temp')
|
|
20
|
+
ct = Car_Type.create(:name => 'temp')
|
|
21
|
+
|
|
22
|
+
# Make sure vehicle and car ids differ by at
|
|
23
|
+
# least 1:
|
|
24
|
+
v = Vehicle.create(:manuf_id => m.id,
|
|
25
|
+
:owner_id => o.id,
|
|
26
|
+
:name => 'temp',
|
|
27
|
+
:num_seats => 2,
|
|
28
|
+
:num_doors => 5,
|
|
29
|
+
:maxspeed => 190)
|
|
30
|
+
|
|
31
|
+
v.delete
|
|
32
|
+
c = Convertible.create(:color => 'red',
|
|
33
|
+
:manuf_id => m.id,
|
|
34
|
+
:owner_id => o.id,
|
|
35
|
+
:name => 'convertible1',
|
|
36
|
+
:num_seats => 2,
|
|
37
|
+
:num_doors => 5,
|
|
38
|
+
:maxspeed => 190,
|
|
39
|
+
:car_type_id => ct.id)
|
|
40
|
+
c.delete
|
|
41
|
+
m.delete
|
|
42
|
+
o.delete
|
|
43
|
+
ct.delete
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
end
|
data/test/tc_factory.rb
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require 'lore/test/model'
|
|
4
|
+
require 'lore/model_factory'
|
|
5
|
+
require 'lore/gui/form_generator'
|
|
6
|
+
|
|
7
|
+
module Lore
|
|
8
|
+
module Unit
|
|
9
|
+
|
|
10
|
+
class TC_Factory < Test::Unit::TestCase
|
|
11
|
+
|
|
12
|
+
public
|
|
13
|
+
|
|
14
|
+
def setup
|
|
15
|
+
begin
|
|
16
|
+
Model_Factory.drop_model(Some::App::New_Model)
|
|
17
|
+
Model_Factory.drop_model(Some::App::Other_Model)
|
|
18
|
+
rescue ::Exception => excep
|
|
19
|
+
# ignore
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def teardown
|
|
24
|
+
Model_Factory.drop_model(Some::App::New_Model)
|
|
25
|
+
Model_Factory.drop_model(Some::App::Other_Model)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_simple
|
|
29
|
+
builder = Model_Factory.new('Some::App::New_Model')
|
|
30
|
+
builder.set_attributes(:model_id => { :type => Type.integer, :not_null => true },
|
|
31
|
+
:name => { :type => Type.integer, :not_null => true, :check => "name <> ''", :unique => true },
|
|
32
|
+
:created => { :type => Type.timestamp, :not_null => true, :default => 'now()' })
|
|
33
|
+
builder.add_primary_key(:key_name => 'model_pkey', :attribute => 'model_id')
|
|
34
|
+
builder.output_file = 'custom_models.rb'
|
|
35
|
+
builder.build_model_klass()
|
|
36
|
+
|
|
37
|
+
form_string = GUI::Form_Generator.new(Some::App::New_Model).generate.string
|
|
38
|
+
|
|
39
|
+
assert_equal(Some::App::New_Model.to_s, 'Some::App::New_Model')
|
|
40
|
+
|
|
41
|
+
builder = Model_Factory.new('Some::App::Other_Model')
|
|
42
|
+
builder.add_attribute('other_id_1', :type => Type.integer, :not_null => true)
|
|
43
|
+
builder.add_attribute('other_id_2', :type => Type.integer, :not_null => true)
|
|
44
|
+
builder.add_attribute('name', :type => Type.integer, :not_null => true, :check => "name <> ''", :unique => true)
|
|
45
|
+
builder.add_attribute('created', :type => Type.timestamp, :not_null => true, :default => 'now()')
|
|
46
|
+
builder.add_primary_key(:attribute => 'other_id_1', :key_name => 'id1')
|
|
47
|
+
builder.add_primary_key(:attribute => 'other_id_2', :key_name => 'id2')
|
|
48
|
+
builder.output_file = 'custom_models.rb'
|
|
49
|
+
builder.build_model_klass()
|
|
50
|
+
|
|
51
|
+
assert_equal(Some::App::Other_Model.to_s, 'Some::App::Other_Model')
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end # module
|
|
57
|
+
end # module
|
data/test/tc_filter.rb
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require 'lore/test/model'
|
|
4
|
+
|
|
5
|
+
module Lore
|
|
6
|
+
module Unit
|
|
7
|
+
|
|
8
|
+
class TC_Filter < Test::Unit::TestCase
|
|
9
|
+
|
|
10
|
+
public
|
|
11
|
+
|
|
12
|
+
def setup
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def teardown
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_simple
|
|
19
|
+
|
|
20
|
+
m1 = Manufacturer.create( :name => 'Dodge' )
|
|
21
|
+
ct1 = Car_Type.create( :name => 'VPenis' )
|
|
22
|
+
|
|
23
|
+
c1 = Car.create(
|
|
24
|
+
:manuf_id => m1.manuf_id,
|
|
25
|
+
:name => 'Viper',
|
|
26
|
+
:num_seats => 2,
|
|
27
|
+
:maxspeed => 230,
|
|
28
|
+
:num_doors => 3,
|
|
29
|
+
:car_type_id => ct1.car_type_id
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end # module
|
|
37
|
+
end # module
|
data/test/tc_form.rb
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require 'lore/gui/form_generator'
|
|
4
|
+
require 'lore/test/model'
|
|
5
|
+
|
|
6
|
+
module Lore
|
|
7
|
+
module Unit
|
|
8
|
+
|
|
9
|
+
class TC_Form < Test::Unit::TestCase
|
|
10
|
+
|
|
11
|
+
public
|
|
12
|
+
|
|
13
|
+
def setup
|
|
14
|
+
for count in (1..5) do
|
|
15
|
+
Manufacturer.create( :name => 'manufacturer_' << count.to_s)
|
|
16
|
+
Car_Type.create( :name => 'car_type_' << count.to_s)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def teardown
|
|
21
|
+
Manufacturer.delete_all
|
|
22
|
+
Car_Type.delete_all
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_simple
|
|
26
|
+
form = GUI::Form_Generator.new(Car).generate
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end # module
|
|
32
|
+
end # module
|
data/test/tc_model.rb
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require 'lore/test/model'
|
|
4
|
+
require 'lore/symbol'
|
|
5
|
+
|
|
6
|
+
module Lore
|
|
7
|
+
module Unit
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TC_Model < Test::Unit::TestCase
|
|
11
|
+
|
|
12
|
+
def setup
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def teardown
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_basic_attribs
|
|
19
|
+
|
|
20
|
+
assert(Car.table_name == 'public.car', 'Table name incorrect')
|
|
21
|
+
assert(Vehicle.table_name == 'public.vehicle', 'Table name incorrect')
|
|
22
|
+
|
|
23
|
+
assert(Car.get_is_a.has_key?(Vehicle.table_name))
|
|
24
|
+
assert(!(Car.get_is_a.has_key?(Car_Type.table_name)))
|
|
25
|
+
assert(Car.get_joins.has_key?(Car_Type.table_name))
|
|
26
|
+
|
|
27
|
+
assert(Car.get_has_a_klasses['public.vehicle.manuf_id'] == Manufacturer)
|
|
28
|
+
|
|
29
|
+
attribs = Car.get_attributes
|
|
30
|
+
types = Car.get_attribute_types
|
|
31
|
+
assert(attribs.has_key?('public.vehicle'))
|
|
32
|
+
assert(attribs.has_key?('public.car'))
|
|
33
|
+
assert(types.has_key?('public.vehicle'))
|
|
34
|
+
assert(types.has_key?('public.car'))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_aggregates
|
|
38
|
+
is_a_hierarchy = Car.get_is_a
|
|
39
|
+
# Car_Type is an aggregate, it must not be listed
|
|
40
|
+
# as base table:
|
|
41
|
+
assert(!is_a_hierarchy.keys_flat.include?('public.car_type'))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_create
|
|
45
|
+
v = Vehicle.create(:name => 'Async', :maxspeed => 100,
|
|
46
|
+
:owner_id => 0, :num_seats => 2,
|
|
47
|
+
:manuf_id => 0)
|
|
48
|
+
|
|
49
|
+
car_type = Car_Type.create(:name => 'Basic_Type')
|
|
50
|
+
assert_equal(car_type.name, 'Basic_Type')
|
|
51
|
+
v.delete
|
|
52
|
+
car_type.commit
|
|
53
|
+
ct = Car_Type.load(:car_type_id => car_type.car_type_id)
|
|
54
|
+
assert_equal(ct.name, 'Basic_Type')
|
|
55
|
+
ct.delete
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_create_with_inheritance
|
|
59
|
+
car_type = Car_Type.create(:name => 'Temp')
|
|
60
|
+
inst_attribs = {
|
|
61
|
+
:num_seats => 5, :num_doors => 5,
|
|
62
|
+
:maxspeed => 180, :name => 'Basic',
|
|
63
|
+
:owner_id => 0, :manuf_id => 0,
|
|
64
|
+
:car_type_id => car_type.car_type_id
|
|
65
|
+
}
|
|
66
|
+
car = Car.create(inst_attribs)
|
|
67
|
+
|
|
68
|
+
car.name = 'Changed Name'
|
|
69
|
+
assert_equal(car.name, 'Changed Name')
|
|
70
|
+
# As Car is not derived from Car_Type but aggregating
|
|
71
|
+
# it only, Car.name and Car_Type.name are not conflicting!
|
|
72
|
+
# Updating a Car instance must not affect its aggregated
|
|
73
|
+
# instances.
|
|
74
|
+
assert_equal(car_type.name, 'Temp')
|
|
75
|
+
assert(car.touched?)
|
|
76
|
+
car.commit
|
|
77
|
+
assert(!car.touched?)
|
|
78
|
+
|
|
79
|
+
car.delete
|
|
80
|
+
car_type.delete
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
end
|