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.
Files changed (111) hide show
  1. data/Manifest.txt +16 -7
  2. data/README.rdoc +91 -0
  3. data/benchmark/benchmark.sql +11 -0
  4. data/benchmark/results.txt +28 -0
  5. data/benchmark/select.rb +352 -0
  6. data/lib/lore.rb +22 -8
  7. data/lib/lore/adapters/context.rb +64 -0
  8. data/lib/lore/adapters/postgres-pr.rb +6 -0
  9. data/lib/lore/adapters/postgres-pr/connection.rb +93 -0
  10. data/lib/lore/adapters/postgres-pr/result.rb +63 -0
  11. data/lib/lore/{types.rb → adapters/postgres-pr/types.rb} +36 -0
  12. data/lib/lore/adapters/postgres.rb +24 -0
  13. data/lib/lore/adapters/postgres/connection.rb +81 -0
  14. data/lib/lore/adapters/postgres/result.rb +82 -0
  15. data/lib/lore/adapters/postgres/types.rb +91 -0
  16. data/lib/lore/bits.rb +18 -0
  17. data/lib/lore/cache/abstract_entity_cache.rb +2 -1
  18. data/lib/lore/cache/cacheable.rb +12 -177
  19. data/lib/lore/cache/memcache_entity_cache.rb +89 -0
  20. data/lib/lore/cache/memory_entity_cache.rb +77 -0
  21. data/lib/lore/cache/mmap_entity_cache.rb +2 -2
  22. data/lib/lore/cache/mmap_entity_cache_bork.rb +86 -0
  23. data/lib/lore/clause.rb +107 -35
  24. data/lib/lore/{exception → exceptions}/ambiguous_attribute.rb +2 -2
  25. data/lib/lore/{exception → exceptions}/cache_exception.rb +1 -1
  26. data/lib/lore/exceptions/database_exception.rb +16 -0
  27. data/lib/lore/{exception/invalid_parameter.rb → exceptions/invalid_field.rb} +7 -4
  28. data/lib/lore/exceptions/unknown_type.rb +18 -0
  29. data/lib/lore/exceptions/validation_failure.rb +71 -0
  30. data/lib/lore/gui/form_generator.rb +109 -60
  31. data/lib/lore/gui/lore_model_select_field.rb +1 -0
  32. data/lib/lore/migration.rb +84 -25
  33. data/lib/lore/model.rb +3 -18
  34. data/lib/lore/{aspect.rb → model/aspect.rb} +0 -0
  35. data/lib/lore/model/associations.rb +225 -0
  36. data/lib/lore/model/attribute_settings.rb +233 -0
  37. data/lib/lore/model/filters.rb +34 -0
  38. data/lib/lore/model/mockable.rb +62 -0
  39. data/lib/lore/{model_factory.rb → model/model_factory.rb} +68 -39
  40. data/lib/lore/model/model_instance.rb +382 -0
  41. data/lib/lore/{model_shortcuts.rb → model/model_shortcuts.rb} +7 -0
  42. data/lib/lore/model/polymorphic.rb +53 -0
  43. data/lib/lore/model/prepare.rb +97 -0
  44. data/lib/lore/model/table_accessor.rb +1016 -0
  45. data/lib/lore/query.rb +71 -0
  46. data/lib/lore/query_shortcuts.rb +43 -11
  47. data/lib/lore/strategies/table_delete.rb +115 -0
  48. data/lib/lore/strategies/table_insert.rb +146 -0
  49. data/lib/lore/strategies/table_select.rb +299 -0
  50. data/lib/lore/strategies/table_update.rb +155 -0
  51. data/lib/lore/validation/parameter_validator.rb +85 -26
  52. data/lib/lore/validation/type_validator.rb +34 -78
  53. data/{custom_models.rb → lore-0.9.2.gem} +0 -0
  54. data/lore.gemspec +26 -17
  55. data/spec/clause.rb +37 -0
  56. data/spec/fixtures/blank_models.rb +37 -0
  57. data/{test/model.rb → spec/fixtures/models.rb} +64 -41
  58. data/spec/fixtures/polymorphic_models.rb +68 -0
  59. data/spec/model_associations.rb +86 -0
  60. data/spec/model_create.rb +47 -0
  61. data/spec/model_definition.rb +151 -0
  62. data/spec/model_delete.rb +31 -0
  63. data/spec/model_inheritance.rb +50 -0
  64. data/spec/model_polymorphic.rb +85 -0
  65. data/spec/model_select.rb +101 -0
  66. data/spec/model_select_eager.rb +42 -0
  67. data/spec/model_union_select.rb +33 -0
  68. data/spec/model_update.rb +45 -0
  69. data/spec/model_validation.rb +20 -0
  70. data/spec/spec_db.sql +808 -0
  71. data/spec/spec_env.rb +19 -0
  72. data/spec/spec_helpers.rb +77 -0
  73. metadata +93 -82
  74. data/lib/lore/README.txt +0 -84
  75. data/lib/lore/behaviours/lockable.rb +0 -55
  76. data/lib/lore/behaviours/movable.rb +0 -72
  77. data/lib/lore/behaviours/paginated.rb +0 -31
  78. data/lib/lore/behaviours/versioned.rb +0 -36
  79. data/lib/lore/connection.rb +0 -152
  80. data/lib/lore/exception/invalid_klass_parameters.rb +0 -63
  81. data/lib/lore/exception/unknown_typecode.rb +0 -19
  82. data/lib/lore/result.rb +0 -119
  83. data/lib/lore/symbol.rb +0 -58
  84. data/lib/lore/table_accessor.rb +0 -1790
  85. data/lib/lore/table_deleter.rb +0 -116
  86. data/lib/lore/table_inserter.rb +0 -170
  87. data/lib/lore/table_instance.rb +0 -389
  88. data/lib/lore/table_selector.rb +0 -285
  89. data/lib/lore/table_updater.rb +0 -157
  90. data/lib/lore/validation.rb +0 -65
  91. data/lib/lore/validation/message.rb +0 -60
  92. data/lib/lore/validation/reason.rb +0 -52
  93. data/lore_test.log +0 -2366
  94. data/test/README +0 -31
  95. data/test/custom_models.rb +0 -18
  96. data/test/env.rb +0 -5
  97. data/test/prepare.rb +0 -37
  98. data/test/tc_aspect.rb +0 -58
  99. data/test/tc_cache.rb +0 -83
  100. data/test/tc_clause.rb +0 -104
  101. data/test/tc_deep_inheritance.rb +0 -49
  102. data/test/tc_factory.rb +0 -57
  103. data/test/tc_filter.rb +0 -37
  104. data/test/tc_form.rb +0 -32
  105. data/test/tc_model.rb +0 -140
  106. data/test/tc_prepare.rb +0 -44
  107. data/test/tc_refined_query.rb +0 -88
  108. data/test/tc_table_accessor.rb +0 -267
  109. data/test/tc_thread.rb +0 -100
  110. data/test/test_db.sql +0 -400
  111. data/test/test_lore.rb +0 -50
@@ -1,37 +0,0 @@
1
-
2
- require 'test/unit'
3
- require './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
@@ -1,32 +0,0 @@
1
-
2
- require 'test/unit'
3
- require 'lore/gui/form_generator'
4
- require './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
@@ -1,140 +0,0 @@
1
-
2
- require 'test/unit'
3
- require './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
- :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_joined_attributes_order
59
-
60
- num_loops = 25
61
-
62
- Vehicle_Owner.delete_all
63
- owners = []
64
- vehicles = []
65
- for i in 0...num_loops do
66
- o = Owner.create(:name => "owner_#{i}")
67
- v = Vehicle.create(:name => 'Async', :maxspeed => 10*i,
68
- :num_seats => i,
69
- :manuf_id => i)
70
- j = Vehicle_Owner.create(:vehicle_id => v.id, :owner_id => o.id)
71
- owners << o
72
- vehicles << v
73
- end
74
- vo = Vehicle_Owner.find(num_loops).sort_by(:vehicle_id, :asc).entities
75
- for i in 0...vo.length do
76
- assert_equal(owners[i].id, vo[i].owner_id)
77
- assert_equal(vehicles[i].id, vo[i].vehicle_id)
78
- end
79
-
80
- join = Vehicle_Owner.select { |vo|
81
- vo.join(Vehicle).on(Vehicle_Owner.vehicle_id == Vehicle.id) { |v|
82
- v.join(Owner).on(Owner.owner_id == Vehicle_Owner.owner_id) { |o|
83
- o.where(true)
84
- o.limit(num_loops)
85
- o.order_by(:vehicle_id, :asc)
86
- }
87
- }
88
- }
89
- assert_equal(num_loops, join.length)
90
-
91
- for i in 0...join.length do
92
- fulljoin = join[i]
93
- assert_equal(owners[i].id, fulljoin.owner_id)
94
- assert_equal(vehicles[i].id, fulljoin.vehicle_id)
95
- end
96
-
97
- join_ids = Vehicle_Owner.select_values(:vehicle_id) { |vo|
98
- vo.join(Vehicle).on(Vehicle_Owner.vehicle_id == Vehicle.id) { |v|
99
- v.join(Owner).on(Owner.owner_id == Vehicle_Owner.owner_id) { |o|
100
- o.where(true)
101
- o.limit(num_loops)
102
- o.order_by(:vehicle_id, :asc)
103
- }
104
- }
105
- }
106
- for i in 0...join_ids.length do
107
- assert_equal(vehicles[i].id, join_ids[i])
108
- end
109
-
110
- end
111
-
112
- def test_create_with_inheritance
113
- car_type = Car_Type.create(:name => 'Temp')
114
- inst_attribs = {
115
- :num_seats => 5, :num_doors => 5,
116
- :maxspeed => 180, :name => 'Basic',
117
- :owner_id => 0, :manuf_id => 0,
118
- :car_type_id => car_type.car_type_id
119
- }
120
- car = Car.create(inst_attribs)
121
-
122
- car.name = 'Changed Name'
123
- assert_equal(car.name, 'Changed Name')
124
- # As Car is not derived from Car_Type but aggregating
125
- # it only, Car.name and Car_Type.name are not conflicting!
126
- # Updating a Car instance must not affect its aggregated
127
- # instances.
128
- assert_equal(car_type.name, 'Temp')
129
- assert(car.touched?)
130
- car.commit
131
- assert(!car.touched?)
132
-
133
- car.delete
134
- car_type.delete
135
- end
136
-
137
- end
138
-
139
- end
140
- end
@@ -1,44 +0,0 @@
1
-
2
- require 'test/unit'
3
-
4
- require('./test/model')
5
-
6
- module Lore
7
- module Unit
8
-
9
- Car.prepare(:by_id, Lore::Type.integer) { |a|
10
- a.where(Car.id == Lore::Clause.new('$1'))
11
- }
12
-
13
- class TC_Prepare < Test::Unit::TestCase
14
-
15
- def setup
16
- @org_units = Hash.new
17
- @org_units[:m] = Manufacturer.create( :name => 'PrepManufacturer' )
18
- @org_units[:t] = Car_Type.create( :name => 'PrepType' )
19
- @org_units[:c] = Car.create(
20
- :manuf_id => @org_units[:m].manuf_id,
21
- :name => 'SLK',
22
- :num_seats => 2,
23
- :maxspeed => 180,
24
- :num_doors => 3,
25
- :car_type_id => @org_units[:t].car_type_id
26
- )
27
- assert(@org_units[:c].instance_of?(Car))
28
- end
29
-
30
- def teardown
31
- @org_units.each_pair { |id,instance|
32
- instance.delete
33
- }
34
- end
35
-
36
- def test_basic
37
- co = Car.load(:id => @org_units[:c].id)
38
- cp = Car.by_id(@org_units[:c].id).first
39
- assert_equal(co, cp)
40
- end
41
-
42
- end
43
- end
44
- end
@@ -1,88 +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_Refined_Query < Test::Unit::TestCase
11
-
12
- def setup
13
- Car.delete_all
14
-
15
- Car.create(
16
- :manuf_id => 1,
17
- :name => 'SLK',
18
- :num_seats => 2,
19
- :maxspeed => 180,
20
- :num_doors => 3,
21
- :car_type_id => 1
22
- )
23
- Car.create(
24
- :manuf_id => 1,
25
- :name => 'SLK2',
26
- :num_seats => 2,
27
- :maxspeed => 180,
28
- :num_doors => 3,
29
- :car_type_id => 1
30
- )
31
- end
32
-
33
- def teardown
34
- Car.delete_all
35
- end
36
-
37
- def test_select_value
38
- manuf = Manufacturer.create( :name => 'Fiat' )
39
- ct = Car_Type.create( :name => 'Transporter' )
40
- c1 = Car.create(
41
- :manuf_id => manuf.manuf_id,
42
- :name => 'test_refined_1',
43
- :num_seats => 2,
44
- :maxspeed => 180,
45
- :num_doors => 3,
46
- :car_type_id => ct.car_type_id
47
- )
48
- c2 = Car.create(
49
- :manuf_id => manuf.manuf_id,
50
- :name => 'test_refined_2',
51
- :num_seats => 2,
52
- :maxspeed => 180,
53
- :num_doors => 3,
54
- :car_type_id => ct.car_type_id
55
- )
56
- u1 = Car.all(Car.name).with(Car.manuf_id == manuf.manuf_id).entities
57
- assert(u1.include?('test_refined_1'))
58
- assert(u1.include?('test_refined_2'))
59
- end
60
-
61
- def test_select_max
62
- max = Car.value_of.max(Car.id).to_i
63
- end
64
-
65
- def test_select_sum
66
- type = Car_Type.create(:name => 'temp')
67
- 7.times {
68
- Car.create(:manuf_id => 123,
69
- :num_seats => 5,
70
- :owner_id => 0,
71
- :name => 'SumMe',
72
- :car_type_id => type.car_type_id,
73
- :maxspeed => 120,
74
- :num_doors => 3)
75
-
76
- }
77
- sum = Car.value_of.sum(Car.num_seats).with(Car.manuf_id == 123).to_i
78
- end
79
-
80
- def test_inner_select
81
- inner = Manufacturer.all(Manufacturer.manuf_id).with(Manufacturer.name == 'Mercedes')
82
- u1 = Car.find(1).with(Car.manuf_id.in(inner)).entity
83
- end
84
-
85
- end
86
-
87
- end
88
- end
@@ -1,267 +0,0 @@
1
-
2
- require 'test/unit'
3
- require 'lore/table_accessor'
4
-
5
- module Lore
6
- module Unit
7
-
8
- class TC_Table_Accessor < Test::Unit::TestCase
9
-
10
- def setup
11
-
12
- Manufacturer.delete_all
13
- Vehicle.delete_all
14
- Car_Type.delete_all
15
- Car.delete_all
16
- Bike.delete_all
17
- Owner.delete_all
18
- Garage.delete_all
19
- Trailer.delete_all
20
- # Fill Lore:
21
- $units = Hash.new
22
- $units[:manufacturer] = Array.new
23
- $units[:car] = Array.new
24
- $units[:car_type] = Array.new
25
- $units[:bike] = Array.new
26
- $units[:garage] = Array.new
27
- $units[:owner] = Array.new
28
-
29
- m1 = Manufacturer.create( :name => 'BMW' )
30
- assert(m1.name == 'BMW')
31
- $units[:manufacturer] << m1
32
- m2 = Manufacturer.create( :name => 'Mercedes' )
33
- assert(m2.name == 'Mercedes')
34
- $units[:manufacturer] << m2
35
- m3 = Manufacturer.create( :name => 'Audi' )
36
- assert(m3.name == 'Audi')
37
- $units[:manufacturer] << m3
38
-
39
- ct1 = Car_Type.create( :name => 'Limousine' )
40
- $units[:car_type] << ct1
41
- ct2 = Car_Type.create( :name => 'SUV' )
42
- $units[:car_type] << ct2
43
- ct3 = Car_Type.create( :name => 'Cabrio' )
44
- $units[:car_type] << ct3
45
- ct4 = Car_Type.create( :name => 'Boxter' )
46
- $units[:car_type] << ct4
47
-
48
- c1 = Car.create(
49
- :manuf_id => m2.manuf_id,
50
- :name => 'SLK',
51
- :num_seats => 2,
52
- :maxspeed => 180,
53
- :num_doors => 3,
54
- :car_type_id => ct3.car_type_id
55
- )
56
- $units[:car] << c1
57
-
58
- o1 = Owner.create(:name => 'owner_1')
59
- $units[:owner] << o1
60
-
61
- end
62
-
63
- def teardown
64
- end
65
-
66
- def test_custom_join
67
-
68
- # Do not expand anything
69
- o1 = Owner.select { |o|
70
- o.join(Vehicle_Owner).using(:owner_id) { |vo|
71
- vo.join(Vehicle).on(Vehicle_Owner.vehicle_id == Vehicle.id) { |v|
72
- v.where true
73
- }
74
- }
75
- }
76
- # Expand Car by Vehicle automatically (Car.vehicle_id)
77
- Car.select { |c|
78
- c.join(Vehicle_Owner).on(Car.vehicle_id == Vehicle_Owner.vehicle_id) { |vo|
79
- vo.join(Owner).on(Vehicle_Owner.owner_id == Owner.owner_id) { |o|
80
- o.where true
81
- }
82
- }
83
- }
84
- # Expand Car by Vehicle automatically in a nested join
85
- Owner.select { |o|
86
- o.join(Vehicle_Owner).on(Vehicle_Owner.owner_id == Owner.owner_id) { |vo|
87
- vo.join(Car).on(Car.vehicle_id == Vehicle_Owner.vehicle_id) { |c|
88
- c.where true
89
- }
90
- }
91
- }
92
-
93
- end
94
-
95
- def test_ignore_params
96
- Car_Type.create( :name => 'Foo', :ignore => 'these', :params => 'please' )
97
- end
98
-
99
- def test_validation
100
-
101
- validation_failed = false
102
- begin
103
- failing_unit = Car_Type.create( :name => 'Van#2' ) # special chars
104
- rescue Lore::Exception::Invalid_Klass_Parameters => ikp
105
- validation_failed = true
106
- end
107
- assert(validation_failed, 'Invalid parameter passed validation')
108
-
109
- validation_failed = false
110
- begin
111
- failing_unit = Car_Type.create( :name => 'Li' ) # too short
112
- rescue Lore::Exception::Invalid_Klass_Parameters => ikp
113
- validation_failed = true
114
- end
115
- assert(validation_failed, 'Invalid parameter passed validation')
116
-
117
- # Test if validation works for inherited constraints:
118
- validation_failed = false
119
- begin
120
- Car.create(
121
- :manuf_id => $units[:manufacturer].first.manuf_id,
122
- :name => 'SLK! this will fail pass thanks to filtering',
123
- :num_seats => 2,
124
- :maxspeed => 180,
125
- :num_doors => 3,
126
- :car_type_id => $units[:car_type].first.car_type_id
127
- )
128
- rescue Lore::Exception::Invalid_Klass_Parameters => ikp
129
- validation_failed = true
130
- end
131
- assert(!validation_failed, 'Invalid parameter passed validation')
132
-
133
- end
134
-
135
- def test_select_variants
136
-
137
- car = $units[:car][0]
138
- car_id = car.id
139
-
140
- s1 = Car.select { |c|
141
- c.where(Car.id == car_id)
142
- c.limit(1)
143
- }.first
144
-
145
- s2 = Car.load(:id => car_id)
146
- s3 = Car.find(1).with(Car.id == car_id).entity
147
- s4 = Car.all_with(Car.id == car_id).entity
148
-
149
- assert(s1 == s2)
150
- assert(s1 == s3)
151
- assert(s1 == s4)
152
-
153
- end
154
-
155
- def test_aggregation_on_joined_models
156
- t = Trailer.create(:car_id => Car.create(:name => 'TrailerCar',
157
- :manuf_id => $units[:manufacturer].first.manuf_id,
158
- :num_seats => 2,
159
- :maxspeed => 120,
160
- :num_doors => 4,
161
- :car_type_id => $units[:car_type].first.car_type_id).id,
162
- :maxweight => 4000)
163
- tl = Trailer.select { |trailer|
164
- trailer.where(trailer.trailer_id == t.trailer_id)
165
- trailer.limit 1
166
- }.first
167
- assert_equal(t, tl)
168
- end
169
-
170
- def test_simple_create
171
- end
172
-
173
- def test_instance_compairison
174
- m1_a = Manufacturer.load({ :manuf_id => $units[:manufacturer][0].manuf_id })
175
- m1_b = Manufacturer.load({ :manuf_id => $units[:manufacturer][0].manuf_id })
176
- m2 = Manufacturer.load({ :manuf_id => $units[:manufacturer][1].manuf_id })
177
- assert(m1_a == m1_a)
178
- assert(m1_a == m1_b)
179
- assert(m1_a <=> m2)
180
-
181
- end
182
-
183
- def test_simple_load
184
- m1 = Manufacturer.load({ :manuf_id => $units[:manufacturer][0].manuf_id })
185
- assert(m1 == $units[:manufacturer][0])
186
- m2 = Manufacturer.load({ :manuf_id => $units[:manufacturer][1].manuf_id })
187
- assert(m2 == $units[:manufacturer][1])
188
- ct1 = Car_Type.load({ :car_type_id => $units[:car_type][0].car_type_id })
189
- assert(ct1 == $units[:car_type][0])
190
- ct2 = Car_Type.load({ :car_type_id => $units[:car_type][1].car_type_id })
191
- assert(ct2 == $units[:car_type][1])
192
- end
193
-
194
- def test_create_single_inherit
195
- m1 = Manufacturer.load({ :manuf_id => $units[:manufacturer][0].manuf_id })
196
- m2 = Manufacturer.load({ :manuf_id => $units[:manufacturer][1].manuf_id })
197
- ct1 = Car_Type.load({ :car_type_id => $units[:car_type][0].car_type_id })
198
- ct2 = Car_Type.load({ :car_type_id => $units[:car_type][1].car_type_id })
199
-
200
- c1 = Car.create(
201
- :manuf_id => m1.manuf_id,
202
- :name => '325M',
203
- :name => '325M',
204
- :num_seats => 5,
205
- :maxspeed => 180,
206
- :num_doors => 5,
207
- :car_type_id => ct1.car_type_id
208
- )
209
-
210
- assert(c1.manuf_id == m1.manuf_id)
211
-
212
- assert_equal(c1[Vehicle.name], '325m')
213
- assert_equal(c1[Car_Type.name], 'Limousine')
214
- assert_equal(c1.num_seats, '5')
215
- assert_equal('180km/h', c1.maxspeed, 'c1.maxspeed is ' << c1.maxspeed)
216
- assert_equal(c1.num_doors, '5')
217
- assert_equal(c1.car_type_id, ct1.car_type_id)
218
-
219
- end
220
-
221
- def test_inherited_has_a
222
- m1 = Manufacturer.load( :manuf_id => $units[:manufacturer][0].manuf_id )
223
- assert(m1.name == $units[:manufacturer][0].name)
224
- m2 = Manufacturer.load( :manuf_id => $units[:manufacturer][1].manuf_id )
225
- assert(m2.name == $units[:manufacturer][1].name)
226
- ct1 = Car_Type.load( :car_type_id => $units[:car_type][0].car_type_id )
227
- ct2 = Car_Type.load( :car_type_id => $units[:car_type][1].car_type_id )
228
-
229
- c1 = Car.create(
230
- :manuf_id => m1.manuf_id,
231
- Car.name.to_s => '318i',
232
- :num_seats => 5,
233
- :maxspeed => 180,
234
- :num_doors => 5,
235
- :owner_id => 1,
236
- :car_type_id => ct1.car_type_id
237
- )
238
- c1_s = Car.find(1).with(Car.name == '318i').entity
239
- assert_equal(c1.manufacturer_entity, m1)
240
- assert_equal(c1.car_type_id, ct1.car_type_id)
241
-
242
- c1.set_manufacturer_entity(m2)
243
- c1.commit
244
- c1.set_car_type_entity!(ct2)
245
-
246
- assert(c1.manufacturer_entity == m2)
247
- assert(c1.car_type_entity == ct2)
248
-
249
- c1_s = Car.find(1).with(Car.name == '318i').entity
250
-
251
- assert(c1_s.manufacturer_entity == m2)
252
- assert(c1_s.car_type_entity == ct2)
253
-
254
- assert(!c1_s.nil? && c1_s[Vehicle.name] == '318i')
255
-
256
- c1.delete
257
-
258
- end
259
-
260
- def test_create_multi_inherit
261
- end
262
-
263
- end
264
-
265
- end
266
- end
267
-