lore 0.4.8 → 0.9.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/Manifest.txt +16 -7
- data/README.rdoc +91 -0
- data/benchmark/benchmark.sql +11 -0
- data/benchmark/results.txt +28 -0
- data/benchmark/select.rb +352 -0
- data/lib/lore.rb +22 -8
- data/lib/lore/adapters/context.rb +64 -0
- data/lib/lore/adapters/postgres-pr.rb +6 -0
- data/lib/lore/adapters/postgres-pr/connection.rb +93 -0
- data/lib/lore/adapters/postgres-pr/result.rb +63 -0
- data/lib/lore/{types.rb → adapters/postgres-pr/types.rb} +36 -0
- data/lib/lore/adapters/postgres.rb +24 -0
- data/lib/lore/adapters/postgres/connection.rb +81 -0
- data/lib/lore/adapters/postgres/result.rb +82 -0
- data/lib/lore/adapters/postgres/types.rb +91 -0
- data/lib/lore/bits.rb +18 -0
- data/lib/lore/cache/abstract_entity_cache.rb +2 -1
- data/lib/lore/cache/cacheable.rb +12 -177
- data/lib/lore/cache/memcache_entity_cache.rb +89 -0
- data/lib/lore/cache/memory_entity_cache.rb +77 -0
- data/lib/lore/cache/mmap_entity_cache.rb +2 -2
- data/lib/lore/cache/mmap_entity_cache_bork.rb +86 -0
- data/lib/lore/clause.rb +107 -35
- data/lib/lore/{exception → exceptions}/ambiguous_attribute.rb +2 -2
- data/lib/lore/{exception → exceptions}/cache_exception.rb +1 -1
- data/lib/lore/exceptions/database_exception.rb +16 -0
- data/lib/lore/{exception/invalid_parameter.rb → exceptions/invalid_field.rb} +7 -4
- data/lib/lore/exceptions/unknown_type.rb +18 -0
- data/lib/lore/exceptions/validation_failure.rb +71 -0
- data/lib/lore/gui/form_generator.rb +109 -60
- data/lib/lore/gui/lore_model_select_field.rb +1 -0
- data/lib/lore/migration.rb +84 -25
- data/lib/lore/model.rb +3 -18
- data/lib/lore/{aspect.rb → model/aspect.rb} +0 -0
- data/lib/lore/model/associations.rb +225 -0
- data/lib/lore/model/attribute_settings.rb +233 -0
- data/lib/lore/model/filters.rb +34 -0
- data/lib/lore/model/mockable.rb +62 -0
- data/lib/lore/{model_factory.rb → model/model_factory.rb} +68 -39
- data/lib/lore/model/model_instance.rb +382 -0
- data/lib/lore/{model_shortcuts.rb → model/model_shortcuts.rb} +7 -0
- data/lib/lore/model/polymorphic.rb +53 -0
- data/lib/lore/model/prepare.rb +97 -0
- data/lib/lore/model/table_accessor.rb +1016 -0
- data/lib/lore/query.rb +71 -0
- data/lib/lore/query_shortcuts.rb +43 -11
- data/lib/lore/strategies/table_delete.rb +115 -0
- data/lib/lore/strategies/table_insert.rb +146 -0
- data/lib/lore/strategies/table_select.rb +299 -0
- data/lib/lore/strategies/table_update.rb +155 -0
- data/lib/lore/validation/parameter_validator.rb +85 -26
- data/lib/lore/validation/type_validator.rb +34 -78
- data/{custom_models.rb → lore-0.9.2.gem} +0 -0
- data/lore.gemspec +26 -17
- data/spec/clause.rb +37 -0
- data/spec/fixtures/blank_models.rb +37 -0
- data/{test/model.rb → spec/fixtures/models.rb} +64 -41
- data/spec/fixtures/polymorphic_models.rb +68 -0
- data/spec/model_associations.rb +86 -0
- data/spec/model_create.rb +47 -0
- data/spec/model_definition.rb +151 -0
- data/spec/model_delete.rb +31 -0
- data/spec/model_inheritance.rb +50 -0
- data/spec/model_polymorphic.rb +85 -0
- data/spec/model_select.rb +101 -0
- data/spec/model_select_eager.rb +42 -0
- data/spec/model_union_select.rb +33 -0
- data/spec/model_update.rb +45 -0
- data/spec/model_validation.rb +20 -0
- data/spec/spec_db.sql +808 -0
- data/spec/spec_env.rb +19 -0
- data/spec/spec_helpers.rb +77 -0
- metadata +93 -82
- data/lib/lore/README.txt +0 -84
- data/lib/lore/behaviours/lockable.rb +0 -55
- data/lib/lore/behaviours/movable.rb +0 -72
- data/lib/lore/behaviours/paginated.rb +0 -31
- data/lib/lore/behaviours/versioned.rb +0 -36
- data/lib/lore/connection.rb +0 -152
- data/lib/lore/exception/invalid_klass_parameters.rb +0 -63
- data/lib/lore/exception/unknown_typecode.rb +0 -19
- data/lib/lore/result.rb +0 -119
- data/lib/lore/symbol.rb +0 -58
- data/lib/lore/table_accessor.rb +0 -1790
- data/lib/lore/table_deleter.rb +0 -116
- data/lib/lore/table_inserter.rb +0 -170
- data/lib/lore/table_instance.rb +0 -389
- data/lib/lore/table_selector.rb +0 -285
- data/lib/lore/table_updater.rb +0 -157
- data/lib/lore/validation.rb +0 -65
- data/lib/lore/validation/message.rb +0 -60
- data/lib/lore/validation/reason.rb +0 -52
- data/lore_test.log +0 -2366
- data/test/README +0 -31
- data/test/custom_models.rb +0 -18
- data/test/env.rb +0 -5
- data/test/prepare.rb +0 -37
- data/test/tc_aspect.rb +0 -58
- data/test/tc_cache.rb +0 -83
- data/test/tc_clause.rb +0 -104
- data/test/tc_deep_inheritance.rb +0 -49
- data/test/tc_factory.rb +0 -57
- data/test/tc_filter.rb +0 -37
- data/test/tc_form.rb +0 -32
- data/test/tc_model.rb +0 -140
- data/test/tc_prepare.rb +0 -44
- data/test/tc_refined_query.rb +0 -88
- data/test/tc_table_accessor.rb +0 -267
- data/test/tc_thread.rb +0 -100
- data/test/test_db.sql +0 -400
- data/test/test_lore.rb +0 -50
data/test/README
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
How to run tests
|
|
3
|
-
|
|
4
|
-
- Create (empty) database test:
|
|
5
|
-
|
|
6
|
-
$ createdb test
|
|
7
|
-
|
|
8
|
-
- Create user 'lore' with password 'lore23'
|
|
9
|
-
(change this in trunk/lore.rb, if you want to)
|
|
10
|
-
|
|
11
|
-
$shell: createuser lore
|
|
12
|
-
$shell: ...
|
|
13
|
-
$shell: psql test
|
|
14
|
-
$psql/test: ALTER USER lore WITH PASSWORD 'lore23';
|
|
15
|
-
$psql/test: \q
|
|
16
|
-
|
|
17
|
-
- Insert test schema into database:
|
|
18
|
-
$shell: psql test < test/test_db.sql
|
|
19
|
-
|
|
20
|
-
- Run tests. No test should fail except those
|
|
21
|
-
saying they are supposed to (printing something like
|
|
22
|
-
'This will fail')
|
|
23
|
-
|
|
24
|
-
It's best to redirect STDERR to a file.
|
|
25
|
-
|
|
26
|
-
$shell: ruby test/ts_lore.rb 2>test.log
|
|
27
|
-
|
|
28
|
-
- Check the logfile in case you are interested in
|
|
29
|
-
the kinky details.
|
|
30
|
-
|
|
31
|
-
|
data/test/custom_models.rb
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
require('lore/model')
|
|
3
|
-
|
|
4
|
-
module Some
|
|
5
|
-
module App
|
|
6
|
-
|
|
7
|
-
class New_Model < Lore::Model
|
|
8
|
-
table :new_model, :public
|
|
9
|
-
primary_key :model_id, :model_id_seq
|
|
10
|
-
has_attribute :name, Lore::Type.integer
|
|
11
|
-
has_attribute :created, Lore::Type.timestamp
|
|
12
|
-
has_attribute :model_id, Lore::Type.integer
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
data/test/env.rb
DELETED
data/test/prepare.rb
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
require 'test/unit'
|
|
3
|
-
require('./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
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
require 'test/unit'
|
|
3
|
-
|
|
4
|
-
require('./test/model')
|
|
5
|
-
|
|
6
|
-
module Lore
|
|
7
|
-
module Unit
|
|
8
|
-
|
|
9
|
-
class TC_Cache < Test::Unit::TestCase
|
|
10
|
-
|
|
11
|
-
def setup
|
|
12
|
-
m1 = Manufacturer.create( :name => 'BMW' )
|
|
13
|
-
m2 = Manufacturer.create( :name => 'Mercedes' )
|
|
14
|
-
m3 = Manufacturer.create( :name => 'Audi' )
|
|
15
|
-
|
|
16
|
-
ct1 = Car_Type.create( :name => 'Limousine' )
|
|
17
|
-
ct2 = Car_Type.create( :name => 'SUV' )
|
|
18
|
-
ct3 = Car_Type.create( :name => 'Cabrio' )
|
|
19
|
-
ct4 = Car_Type.create( :name => 'Boxter' )
|
|
20
|
-
|
|
21
|
-
c1 = Car.create(
|
|
22
|
-
:manuf_id => m2.manuf_id,
|
|
23
|
-
:name => 'SLK',
|
|
24
|
-
:num_seats => 2,
|
|
25
|
-
:maxspeed => 180,
|
|
26
|
-
:num_doors => 3,
|
|
27
|
-
:car_type_id => ct3.car_type_id
|
|
28
|
-
)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def teardown
|
|
32
|
-
Manufacturer.delete_all
|
|
33
|
-
Vehicle.delete_all
|
|
34
|
-
Car_Type.delete_all
|
|
35
|
-
Car.delete_all
|
|
36
|
-
Bike.delete_all
|
|
37
|
-
Owner.delete_all
|
|
38
|
-
Garage.delete_all
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def test_basic
|
|
42
|
-
Lore.enable_cache
|
|
43
|
-
Car.use_entity_cache Lore::Cache::Mmap_Entity_Cache
|
|
44
|
-
|
|
45
|
-
passed = true
|
|
46
|
-
org_name = Car.all.entity.name
|
|
47
|
-
20.times {
|
|
48
|
-
cached_inst = Car.all.entity
|
|
49
|
-
cached_name = cached_inst.name
|
|
50
|
-
passed = passed && (org_name == cached_name)
|
|
51
|
-
assert_equal(org_name, cached_name)
|
|
52
|
-
passed = passed && (!Lore.cache_enabled? || cached_inst.is_cached_entity?)
|
|
53
|
-
}
|
|
54
|
-
assert(passed, 'Cached value and original value differ (This will fail if caching is not configured, doing no harm)')
|
|
55
|
-
|
|
56
|
-
20.times {
|
|
57
|
-
cached_inst = Car.all.entity
|
|
58
|
-
cached_name = cached_inst.name
|
|
59
|
-
passed = passed && (org_name == cached_name)
|
|
60
|
-
assert_equal(org_name, cached_name)
|
|
61
|
-
cached_inst[:name] = 'Changed'
|
|
62
|
-
passed = passed && (cached_inst.name == 'Changed')
|
|
63
|
-
assert_equal(cached_inst.name, 'Changed')
|
|
64
|
-
cached_inst.commit
|
|
65
|
-
passed = passed && (!Lore.cache_enabled? || !cached_inst.is_cached_entity?)
|
|
66
|
-
}
|
|
67
|
-
Lore.disable_cache
|
|
68
|
-
assert(passed, 'Cached value and original value differ')
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def test_random_select
|
|
72
|
-
# Random selects must not be cached under any circumstances.
|
|
73
|
-
random_car = Car.select('*, random() as rand') { |rcar|
|
|
74
|
-
rcar.where(true)
|
|
75
|
-
rcar.order_by(:rand, :desc)
|
|
76
|
-
rcar.limit(1)
|
|
77
|
-
}.first
|
|
78
|
-
assert(!random_car.loaded_from_cache)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
data/test/tc_clause.rb
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
require 'test/unit'
|
|
3
|
-
require('./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
|
data/test/tc_deep_inheritance.rb
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
require 'test/unit'
|
|
3
|
-
require './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
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
require 'test/unit'
|
|
3
|
-
require './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
|