Rubernate 0.1.5 → 0.1.6
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/README +1 -1
- data/lib/rubernate/callbacks.rb +17 -20
- data/lib/rubernate/impl/dbi_generic.rb +77 -50
- data/lib/rubernate/impl/dbi_mysql.rb +2 -2
- data/lib/rubernate/impl/dbi_oracle.rb +29 -3
- data/lib/rubernate/impl/dbi_pg.rb +2 -2
- data/lib/rubernate/impl/memory.rb +14 -12
- data/lib/rubernate/init/init_mysql.rb +2 -2
- data/lib/rubernate/init/init_oracle.rb +2 -2
- data/lib/rubernate/lazyload.rb +63 -0
- data/lib/rubernate/mixins.rb +6 -4
- data/lib/rubernate/persistent.rb +21 -21
- data/lib/rubernate/queries.rb +33 -11
- data/lib/rubernate/runtime.rb +49 -27
- data/lib/rubernate.rb +51 -33
- data/tests/config.rb +8 -5
- data/tests/rubernate/impl/dbi_generic_stub.rb +102 -35
- data/tests/rubernate/impl/dbi_oracle_test.rb +20 -0
- data/tests/rubernate/impl/memory_test.rb +16 -17
- data/tests/rubernate/rubernate_test.rb +352 -302
- metadata +3 -2
@@ -3,329 +3,379 @@ $:.unshift(File.expand_path('../..', __FILE__)) unless
|
|
3
3
|
|
4
4
|
require 'rubernate/fixtures'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
class Rubernate::RubernateTest < Test::Unit::TestCase
|
12
|
-
include FixtureClasses
|
13
|
-
include Rubernate
|
14
|
-
include Rubernate::DBI
|
15
|
-
|
16
|
-
def setup
|
17
|
-
@factory = Rubernate::Memory::Configuration.new
|
18
|
-
@runtime = @factory.create
|
19
|
-
Rubernate.configuration = @factory
|
20
|
-
Thread.current[:on_save] = Thread.current[:on_load] = nil
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_include
|
24
|
-
assert !C0.include?(Persistent)
|
25
|
-
assert C1.include?(Persistent)
|
26
|
-
assert C2.include?(Persistent)
|
27
|
-
assert C3.include?(Persistent)
|
28
|
-
assert !C0.new.kind_of?(Persistent)
|
29
|
-
assert C1.new.kind_of?(Persistent)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_properties
|
33
|
-
assert !C1.method_defined?(:p2)
|
34
|
-
assert C1.method_defined?(:p1)
|
35
|
-
assert C1.method_defined?(:p1=)
|
36
|
-
assert C2.method_defined?(:p2)
|
37
|
-
assert C2.method_defined?(:p2=)
|
38
|
-
assert C3.method_defined?(:p0)
|
39
|
-
assert C3.method_defined?(:p0=)
|
6
|
+
module Rubernate
|
7
|
+
# Make methods instantiate and modified visible for test purposes.
|
8
|
+
class Runtime
|
9
|
+
public :instantiate, :modified, :lazy_factory
|
40
10
|
end
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
assert
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
11
|
+
|
12
|
+
class RubernateTest < Test::Unit::TestCase
|
13
|
+
include FixtureClasses
|
14
|
+
include Rubernate
|
15
|
+
include Rubernate::DBI
|
16
|
+
|
17
|
+
def setup
|
18
|
+
@factory = Rubernate::Memory::Configuration.new
|
19
|
+
@runtime = @factory.create
|
20
|
+
Rubernate.configuration = @factory
|
21
|
+
Thread.current[:on_save] = Thread.current[:on_load] = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_include
|
25
|
+
assert !C0.include?(Persistent)
|
26
|
+
assert C1.include?(Persistent)
|
27
|
+
assert C2.include?(Persistent)
|
28
|
+
assert C3.include?(Persistent)
|
29
|
+
assert !C0.new.kind_of?(Persistent)
|
30
|
+
assert C1.new.kind_of?(Persistent)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_properties
|
34
|
+
assert !C1.method_defined?(:p2)
|
35
|
+
assert C1.method_defined?(:p1)
|
36
|
+
assert C1.method_defined?(:p1=)
|
37
|
+
assert C2.method_defined?(:p2)
|
38
|
+
assert C2.method_defined?(:p2=)
|
39
|
+
assert C3.method_defined?(:p0)
|
40
|
+
assert C3.method_defined?(:p0=)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_objects_eq
|
44
|
+
o1, o2, o3, o4 = C4.new(1), C4.new(1), C4.new(2), C1.new
|
45
|
+
assert_equal o1, o1
|
46
|
+
assert_equal o1, o2
|
47
|
+
assert_not_equal o1, o3
|
48
|
+
assert_not_equal o1, o4
|
49
|
+
assert_equal o4, o4
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_session
|
53
|
+
assert !Rubernate.session?
|
54
|
+
Rubernate.session{ assert Rubernate.runtime; assert Rubernate.session? }
|
55
|
+
Rubernate.session{ |runtime|
|
56
|
+
assert runtime
|
64
57
|
def runtime.close
|
65
|
-
Thread.current[:close_test] = '
|
66
|
-
end
|
67
|
-
def runtime.failed
|
68
|
-
Thread.current[:failed_test] = 'passed'
|
58
|
+
Thread.current[:close_test] = 'passed'
|
69
59
|
end
|
70
|
-
raise Rubernate::ObjectNotFoundException.new(1)
|
71
60
|
}
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
61
|
+
assert_equal 'passed', Thread.current[:close_test]
|
62
|
+
assert_raise(Rubernate::ObjectNotFoundException) {
|
63
|
+
Rubernate.session { |runtime|
|
64
|
+
assert runtime
|
65
|
+
def runtime.close
|
66
|
+
Thread.current[:close_test] = 'not_passed'
|
67
|
+
end
|
68
|
+
def runtime.failed
|
69
|
+
Thread.current[:failed_test] = 'passed'
|
70
|
+
end
|
71
|
+
raise Rubernate::ObjectNotFoundException.new(1)
|
72
|
+
}
|
73
|
+
}
|
74
|
+
assert_equal 'passed', Thread.current[:close_test]
|
75
|
+
assert_equal 'passed', Thread.current[:failed_test]
|
76
|
+
assert_raise(RuntimeError) {Rubernate.runtime}
|
77
|
+
end
|
81
78
|
|
82
|
-
|
83
|
-
|
79
|
+
def test_find_and_load
|
80
|
+
o1, o1.__peer, o1.p1 = C1.new, Peer.new, 'o1.p1'
|
81
|
+
o2, o2.__peer, o2.p1 = C2.new, Peer.new, o1
|
82
|
+
|
83
|
+
@runtime.create o1
|
84
|
+
@runtime.create o2
|
85
|
+
|
86
|
+
Rubernate.session { |runtime|
|
87
|
+
o2 = runtime.find_by_pk o2.primary_key
|
88
|
+
o1 = o2.p1
|
89
|
+
assert o1.equal?(runtime.find_by_pk(o1.primary_key))
|
90
|
+
runtime.find_by_pk o1.primary_key, true
|
91
|
+
assert_not_nil o1.__peer
|
92
|
+
}
|
93
|
+
end
|
84
94
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
runtime.
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
95
|
+
def test_ensure_loaded
|
96
|
+
o1, o1.p1 = C1.new, 'o1.p1'
|
97
|
+
o2, o2.p1 = C2.new, o1
|
98
|
+
|
99
|
+
@runtime.create o1
|
100
|
+
@runtime.create o2
|
101
|
+
|
102
|
+
Rubernate.session do |runtime|
|
103
|
+
o2 = runtime.find_by_pk o2.primary_key
|
104
|
+
o1 = o2.p1
|
105
|
+
assert_equal 'o1.p1', o1.p1
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_peer_creation
|
110
|
+
o = C1.new
|
111
|
+
assert_nil o.__peer
|
112
|
+
o.p1 = 'o.p1'
|
113
|
+
p = o.__peer
|
114
|
+
assert p
|
115
|
+
assert_equal 'o.p1', o.p1
|
116
|
+
assert p.equal?(o.__peer) # Peer must not be changed
|
117
|
+
end
|
97
118
|
|
98
|
-
|
99
|
-
|
119
|
+
def test_peer_assign
|
120
|
+
o = C1.new
|
121
|
+
l1, l2 = LazyLoader.new, LazyLoader.new
|
122
|
+
o.__peer = l1
|
123
|
+
o.__peer = l2
|
124
|
+
assert_equal l1, o.__peer
|
125
|
+
|
126
|
+
p1, p2 = Peer.new, Peer.new
|
127
|
+
o.__peer = p1
|
128
|
+
assert_equal p1, o.__peer
|
129
|
+
o.__peer = p2
|
130
|
+
assert_equal p2, o.__peer
|
131
|
+
o.__peer = l1
|
132
|
+
assert_equal p2, o.__peer
|
133
|
+
end
|
100
134
|
|
101
|
-
|
102
|
-
o2 = runtime.find_by_pk o2.primary_key
|
103
|
-
o1 = o2.p1
|
104
|
-
assert_equal 'o1.p1', o1.p1
|
105
|
-
}
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_attach
|
109
|
-
o1 = C1.new
|
110
|
-
Rubernate.session {|runtime|
|
111
|
-
runtime.attach o1
|
112
|
-
f1 = runtime.find_by_pk(o1.primary_key)
|
113
|
-
assert o1.equal?(f1)
|
114
|
-
}
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_equal
|
118
|
-
o1, o1.primary_key = C1.new, 1
|
119
|
-
o2, o2.primary_key = C1.new, 1
|
120
|
-
assert_equal o1, o2
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_ensure_attach
|
124
|
-
Rubernate.session {|runtime|
|
135
|
+
def test_attach
|
125
136
|
o1 = C1.new
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
137
|
+
Rubernate.session {|runtime|
|
138
|
+
runtime.attach o1
|
139
|
+
f1 = runtime.find_by_pk(o1.primary_key)
|
140
|
+
assert o1.equal?(f1)
|
141
|
+
}
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_equal
|
145
|
+
o1, o1.primary_key = C1.new, 1
|
146
|
+
o2, o2.primary_key = C1.new, 1
|
147
|
+
assert_equal o1, o2
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_ensure_attach
|
151
|
+
Rubernate.session {|runtime|
|
152
|
+
o1 = C1.new
|
153
|
+
runtime.attach o1
|
154
|
+
o1.p1 = 'o1.p1'
|
155
|
+
assert o1.__peer.dirty?
|
156
|
+
}
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_on_load
|
160
|
+
pk = Rubernate.session {o = C3.new.attach; o.primary_key}
|
161
|
+
assert_nil Thread.current[:on_load]
|
162
|
+
Rubernate.session {
|
163
|
+
o = find_by_pk pk
|
164
|
+
assert_not_nil Thread.current[:on_load]
|
165
|
+
}
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_on_load_session
|
169
|
+
pk = nil
|
170
|
+
Rubernate.session{|runtime| o = C3.new.attach; pk = o.primary_key}
|
171
|
+
Rubernate.session{|runtime|
|
172
|
+
o = runtime.find_by_pk pk
|
173
|
+
assert_equal o, Thread.current[:on_load]
|
174
|
+
}
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_on_save
|
178
|
+
o = nil
|
179
|
+
Rubernate.session{|runtime|
|
180
|
+
o = C3.new.attach
|
181
|
+
assert_nil Thread.current[:on_save]
|
182
|
+
o.p0 = 'o.p0'
|
183
|
+
}
|
184
|
+
assert_equal o, Thread.current[:on_save]
|
185
|
+
end
|
159
186
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
187
|
+
def test_attach_remove # TODO:...
|
188
|
+
Rubernate.session {
|
189
|
+
o = C1.new.attach
|
190
|
+
o.remove!
|
191
|
+
}
|
192
|
+
end
|
165
193
|
end
|
166
|
-
end
|
167
194
|
|
168
|
-
class
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
def test_peer_dirty
|
173
|
-
p = Peer.new
|
174
|
-
assert_equal false, p.dirty?
|
195
|
+
class PeerTest < Test::Unit::TestCase
|
196
|
+
include Rubernate
|
197
|
+
include FixtureClasses
|
175
198
|
|
176
|
-
|
177
|
-
|
199
|
+
def test_peer_dirty
|
200
|
+
p = Peer.new
|
201
|
+
assert_equal false, p.dirty?
|
202
|
+
|
203
|
+
p[:p1] = 'test'
|
204
|
+
assert p.dirty?
|
205
|
+
|
206
|
+
p.dirty = false
|
207
|
+
assert_equal false, p.dirty?
|
208
|
+
|
209
|
+
p[:p1] = nil
|
210
|
+
assert p.dirty?
|
211
|
+
end
|
178
212
|
|
179
|
-
|
180
|
-
|
213
|
+
def test_peer_dirty_array
|
214
|
+
peer = Peer.new
|
215
|
+
assert !peer.dirty?
|
216
|
+
peer[:a] = []
|
217
|
+
assert peer.dirty?
|
218
|
+
peer.dirty = false
|
219
|
+
peer[:a] << C4.new(1)
|
220
|
+
assert peer.dirty?
|
221
|
+
peer.dirty = false
|
222
|
+
assert !peer.dirty?
|
223
|
+
end
|
181
224
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
assert !peer.dirty?
|
225
|
-
end
|
226
|
-
|
227
|
-
def test_peer_container
|
228
|
-
a = [1]
|
229
|
-
a.extend Peer::Container
|
230
|
-
a.memorize!
|
231
|
-
assert_nil a.recall
|
232
|
-
a << 2
|
233
|
-
assert_not_nil a.recall
|
234
|
-
a.memorize!
|
235
|
-
assert_nil a.recall
|
236
|
-
a.collect! { |i| i * 2 }
|
237
|
-
assert_not_nil a.recall
|
238
|
-
assert_equal 4, a[1]
|
225
|
+
def test_peer_dirty_hash
|
226
|
+
peer = Peer.new
|
227
|
+
peer[:h] = {'key1' => 'value1'}
|
228
|
+
assert peer.dirty?
|
229
|
+
peer.dirty = false
|
230
|
+
assert !peer.dirty?
|
231
|
+
peer[:h]['key2'] = 'value2'
|
232
|
+
assert peer.dirty?
|
233
|
+
peer[:h]['key2'] = 'value2.1'
|
234
|
+
assert peer.dirty?
|
235
|
+
peer.dirty = false
|
236
|
+
peer[:h]['key2'] = nil
|
237
|
+
assert peer.dirty?
|
238
|
+
peer.dirty = false
|
239
|
+
peer[:h].delete 'key2'
|
240
|
+
assert peer.dirty?
|
241
|
+
end
|
242
|
+
|
243
|
+
def test_peer_dirty_hash2
|
244
|
+
peer = Peer.new
|
245
|
+
peer[:h] = {'key1' => C4.new(1)}
|
246
|
+
peer.dirty = false
|
247
|
+
peer[:h]['key1'] = C4.new 1
|
248
|
+
assert !peer.dirty?
|
249
|
+
peer.dirty = false
|
250
|
+
peer[:h] = {'key1' => C4.new(1)}
|
251
|
+
assert !peer.dirty?
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_peer_container
|
255
|
+
a = [1]
|
256
|
+
a.extend Peer::Container
|
257
|
+
a.memorize!
|
258
|
+
assert_nil a.recall
|
259
|
+
a << 2
|
260
|
+
assert_not_nil a.recall
|
261
|
+
a.memorize!
|
262
|
+
assert_nil a.recall
|
263
|
+
a.collect! { |i| i * 2 }
|
264
|
+
assert_not_nil a.recall
|
265
|
+
assert_equal 4, a[1]
|
266
|
+
end
|
239
267
|
end
|
240
|
-
end
|
241
268
|
|
242
|
-
class Rubernate::BaseRuntimeTest < Test::Unit::TestCase
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
269
|
+
class Rubernate::BaseRuntimeTest < Test::Unit::TestCase
|
270
|
+
include Rubernate
|
271
|
+
include FixtureClasses
|
272
|
+
|
273
|
+
def setup
|
274
|
+
@factory = Rubernate::Memory::Configuration.new
|
275
|
+
@runtime = @factory.create
|
276
|
+
Rubernate.configuration = @factory
|
277
|
+
Thread.current[:on_save] = Thread.current[:on_load] = nil
|
278
|
+
end
|
279
|
+
|
280
|
+
def test_instantiate
|
281
|
+
object = @runtime.instantiate 1, C1.name
|
282
|
+
assert object
|
283
|
+
assert_equal 1, object.primary_key
|
284
|
+
assert_equal C1, object.class
|
285
|
+
end
|
286
|
+
|
287
|
+
def test_instantiate_existing
|
288
|
+
o0 = @runtime.instantiate 1, C1.name
|
289
|
+
o1 = @runtime.instantiate 1, C1.name
|
263
290
|
|
264
|
-
|
265
|
-
|
266
|
-
|
291
|
+
assert o0.equal?(o1)
|
292
|
+
assert_equal o0, o1
|
293
|
+
end
|
267
294
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
295
|
+
def test_instantiate_by_finder
|
296
|
+
pk = nil
|
297
|
+
Rubernate.session do
|
298
|
+
o = C1.new.attach
|
299
|
+
pk = o.primary_key
|
300
|
+
o_ = find_by_pk pk
|
301
|
+
assert_equal o, o_
|
302
|
+
assert_equal o.object_id, o_.object_id
|
303
|
+
o__ = find_by_query('all')[0]
|
304
|
+
assert_equal o, o__
|
305
|
+
assert_equal o.object_id, o__.object_id
|
306
|
+
end
|
307
|
+
Rubernate.session do
|
308
|
+
o_ = find_by_pk pk
|
309
|
+
o__ = find_by_query('all')[0]
|
310
|
+
assert_equal o_, o__
|
311
|
+
assert_equal o_.object_id, o__.object_id
|
312
|
+
end
|
279
313
|
end
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
314
|
+
|
315
|
+
def test_instantiate_fake_class
|
316
|
+
@factory.database = {27 => ['NoSuchClass', {}]}
|
317
|
+
Rubernate.session do
|
318
|
+
o = find_by_pk 27
|
319
|
+
assert_equal DummyPersistent, o.class
|
320
|
+
assert_equal 27, o.primary_key
|
321
|
+
assert_raise(ObjectLoadError) {o.test}
|
322
|
+
end
|
285
323
|
end
|
286
|
-
end
|
287
324
|
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
325
|
+
def test_modified
|
326
|
+
Rubernate.session do |runtime|
|
327
|
+
assert_equal 0, runtime.modified.size
|
328
|
+
o, o.p1 = C1.new.attach, 'o.p1'
|
329
|
+
assert_equal [o], runtime.modified
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
def test_flush_modified_find
|
334
|
+
Rubernate.session do |runtime|
|
335
|
+
o1, o1.p1 = C1.new.attach, 'o1.p1'
|
336
|
+
assert_equal [o1], runtime.modified
|
337
|
+
runtime.find_by_query "all"
|
338
|
+
assert_equal 0, runtime.modified.size
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
def test_fluch_modified_close
|
343
|
+
Rubernate.session {|runtime| o, o.p1 = C1.new.attach, 'o.p1' }
|
344
|
+
Rubernate.session do |runtime|
|
345
|
+
o = * runtime.find_by_query("sql: all")
|
346
|
+
assert_equal 'o.p1', o.p1
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
def test_settings
|
351
|
+
assert Rubernate.settings
|
352
|
+
Rubernate.settings[:g_prop] = 'g0'
|
353
|
+
Rubernate.session do |runtime|
|
354
|
+
assert_equal 'g0', Rubernate.settings[:g_prop]
|
355
|
+
assert_equal 'g0', Rubernate.runtime.settings[:g_prop]
|
356
|
+
Rubernate.settings[:g_prop] = 'g1'
|
357
|
+
assert_equal 'g0', Rubernate.runtime.settings[:g_prop]
|
358
|
+
Rubernate.runtime.settings[:r_prop] = 'r0'
|
359
|
+
end
|
360
|
+
Rubernate.session do |runtime|
|
361
|
+
assert_equal 'g1', Rubernate.settings[:g_prop]
|
362
|
+
assert_equal 'g1', Rubernate.runtime.settings[:g_prop]
|
363
|
+
assert_nil Rubernate.runtime.settings[:r_prop]
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
def test_lazy_factory
|
368
|
+
Rubernate.settings[:lazy_load] = :collection
|
369
|
+
Rubernate.session do |rt|
|
370
|
+
lf = rt.lazy_factory
|
371
|
+
f1 = lf.create 1, :p
|
372
|
+
assert f1
|
373
|
+
f2 = lf.create 2, :p
|
374
|
+
f3 = lf.create 1, :p
|
375
|
+
assert_equal f1, f3
|
376
|
+
assert_not_equal f1, f2
|
377
|
+
assert f1.is_a?(ParamLazyLoader)
|
378
|
+
end
|
295
379
|
end
|
296
380
|
end
|
297
|
-
|
298
|
-
def test_modified
|
299
|
-
Rubernate.session {|runtime|
|
300
|
-
assert_equal 0, runtime.modified.size
|
301
|
-
o, o.p1 = C1.new.attach, 'o.p1'
|
302
|
-
assert_equal [o], runtime.modified
|
303
|
-
}
|
304
|
-
end
|
305
|
-
|
306
|
-
def test_ensure
|
307
|
-
o = C1.new
|
308
|
-
assert_nothing_raised() {o.p1}
|
309
|
-
o, o.peer = C1.new, nil
|
310
|
-
assert_raise(RuntimeError) {o.p1}
|
311
|
-
o, o.peer = C1.new, Peer.new
|
312
|
-
assert_nothing_raised() {o.p1}
|
313
|
-
end
|
314
|
-
|
315
|
-
def test_flush_modified_find
|
316
|
-
Rubernate.session {|runtime|
|
317
|
-
o1, o1.p1 = C1.new.attach, 'o1.p1'
|
318
|
-
assert_equal [o1], runtime.modified
|
319
|
-
runtime.find_by_query "all"
|
320
|
-
assert_equal 0, runtime.modified.size
|
321
|
-
}
|
322
|
-
end
|
323
|
-
|
324
|
-
def test_fluch_modified_close
|
325
|
-
Rubernate.session {|runtime| o, o.p1 = C1.new.attach, 'o.p1' }
|
326
|
-
Rubernate.session {|runtime|
|
327
|
-
o = * runtime.find_by_query("sql: all")
|
328
|
-
assert_equal 'o.p1', o.p1
|
329
|
-
}
|
330
|
-
end
|
331
|
-
end
|
381
|
+
end
|