transaction-simple 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (9) hide show
  1. data/ChangeLog +20 -0
  2. data/Changelog +20 -0
  3. data/Install +2 -0
  4. data/README +110 -0
  5. data/Rakefile +120 -0
  6. data/Readme +110 -0
  7. data/lib/transaction/simple.rb +591 -0
  8. data/tests/tests.rb +402 -0
  9. metadata +55 -0
@@ -0,0 +1,402 @@
1
+ $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
2
+
3
+ require 'transaction/simple'
4
+ require 'test/unit'
5
+
6
+ class Test__Transaction_Simple < Test::Unit::TestCase #:nodoc:
7
+ VALUE = "Now is the time for all good men to come to the aid of their country."
8
+
9
+ def setup
10
+ @value = VALUE.dup
11
+ @value.extend(Transaction::Simple)
12
+ end
13
+
14
+ def test_extended
15
+ assert_respond_to(@value, :start_transaction)
16
+ end
17
+
18
+ def test_started
19
+ assert_equal(false, @value.transaction_open?)
20
+ assert_nothing_raised { @value.start_transaction }
21
+ assert_equal(true, @value.transaction_open?)
22
+ end
23
+
24
+ def test_rewind
25
+ assert_equal(false, @value.transaction_open?)
26
+ assert_raises(Transaction::TransactionError) { @value.rewind_transaction }
27
+ assert_nothing_raised { @value.start_transaction }
28
+ assert_equal(true, @value.transaction_open?)
29
+ assert_nothing_raised { @value.gsub!(/men/, 'women') }
30
+ assert_not_equal(VALUE, @value)
31
+ assert_nothing_raised { @value.rewind_transaction }
32
+ assert_equal(true, @value.transaction_open?)
33
+ assert_equal(VALUE, @value)
34
+ end
35
+
36
+ def test_abort
37
+ assert_equal(false, @value.transaction_open?)
38
+ assert_raises(Transaction::TransactionError) { @value.abort_transaction }
39
+ assert_nothing_raised { @value.start_transaction }
40
+ assert_equal(true, @value.transaction_open?)
41
+ assert_nothing_raised { @value.gsub!(/men/, 'women') }
42
+ assert_not_equal(VALUE, @value)
43
+ assert_nothing_raised { @value.abort_transaction }
44
+ assert_equal(false, @value.transaction_open?)
45
+ assert_equal(VALUE, @value)
46
+ end
47
+
48
+ def test_commit
49
+ assert_equal(false, @value.transaction_open?)
50
+ assert_raises(Transaction::TransactionError) { @value.commit_transaction }
51
+ assert_nothing_raised { @value.start_transaction }
52
+ assert_equal(true, @value.transaction_open?)
53
+ assert_nothing_raised { @value.gsub!(/men/, 'women') }
54
+ assert_not_equal(VALUE, @value)
55
+ assert_equal(true, @value.transaction_open?)
56
+ assert_nothing_raised { @value.commit_transaction }
57
+ assert_equal(false, @value.transaction_open?)
58
+ assert_not_equal(VALUE, @value)
59
+ end
60
+
61
+ def test_multilevel
62
+ assert_equal(false, @value.transaction_open?)
63
+ assert_nothing_raised { @value.start_transaction }
64
+ assert_equal(true, @value.transaction_open?)
65
+ assert_nothing_raised { @value.gsub!(/men/, 'women') }
66
+ assert_equal(VALUE.gsub(/men/, 'women'), @value)
67
+ assert_equal(true, @value.transaction_open?)
68
+ assert_nothing_raised { @value.start_transaction }
69
+ assert_nothing_raised { @value.gsub!(/country/, 'nation-state') }
70
+ assert_nothing_raised { @value.commit_transaction }
71
+ assert_equal(VALUE.gsub(/men/, 'women').gsub(/country/, 'nation-state'), @value)
72
+ assert_equal(true, @value.transaction_open?)
73
+ assert_nothing_raised { @value.abort_transaction }
74
+ assert_equal(VALUE, @value)
75
+ end
76
+
77
+ def test_multilevel_named
78
+ assert_equal(false, @value.transaction_open?)
79
+ assert_raises(Transaction::TransactionError) { @value.transaction_name }
80
+ assert_nothing_raised { @value.start_transaction(:first) } # 1
81
+ assert_raises(Transaction::TransactionError) { @value.start_transaction(:first) }
82
+ assert_equal(true, @value.transaction_open?)
83
+ assert_equal(true, @value.transaction_open?(:first))
84
+ assert_equal(:first, @value.transaction_name)
85
+ assert_nothing_raised { @value.start_transaction } # 2
86
+ assert_not_equal(:first, @value.transaction_name)
87
+ assert_equal(nil, @value.transaction_name)
88
+ assert_raises(Transaction::TransactionError) { @value.abort_transaction(:second) }
89
+ assert_nothing_raised { @value.abort_transaction(:first) }
90
+ assert_equal(false, @value.transaction_open?)
91
+ assert_nothing_raised do
92
+ @value.start_transaction(:first)
93
+ @value.gsub!(/men/, 'women')
94
+ @value.start_transaction(:second)
95
+ @value.gsub!(/women/, 'people')
96
+ @value.start_transaction
97
+ @value.gsub!(/people/, 'sentients')
98
+ end
99
+ assert_nothing_raised { @value.abort_transaction(:second) }
100
+ assert_equal(true, @value.transaction_open?(:first))
101
+ assert_equal(VALUE.gsub(/men/, 'women'), @value)
102
+ assert_nothing_raised do
103
+ @value.start_transaction(:second)
104
+ @value.gsub!(/women/, 'people')
105
+ @value.start_transaction
106
+ @value.gsub!(/people/, 'sentients')
107
+ end
108
+ assert_raises(Transaction::TransactionError) { @value.rewind_transaction(:foo) }
109
+ assert_nothing_raised { @value.rewind_transaction(:second) }
110
+ assert_equal(VALUE.gsub(/men/, 'women'), @value)
111
+ assert_nothing_raised do
112
+ @value.gsub!(/women/, 'people')
113
+ @value.start_transaction
114
+ @value.gsub!(/people/, 'sentients')
115
+ end
116
+ assert_raises(Transaction::TransactionError) { @value.commit_transaction(:foo) }
117
+ assert_nothing_raised { @value.commit_transaction(:first) }
118
+ assert_equal(VALUE.gsub(/men/, 'sentients'), @value)
119
+ assert_equal(false, @value.transaction_open?)
120
+ end
121
+
122
+ def test_block
123
+ @value = VALUE.dup
124
+ Transaction::Simple.start(@value) do |tv|
125
+ assert_equal(true, tv.transaction_open?)
126
+ assert_nothing_raised { tv.gsub!(/men/, 'women') }
127
+ assert_equal(VALUE.gsub(/men/, 'women'), tv)
128
+ tv.abort_transaction
129
+ flunk("Failed to abort the transaction.")
130
+ end
131
+ assert_equal(false, @value.transaction_open?)
132
+ assert_equal(VALUE, @value)
133
+
134
+ @value = VALUE.dup
135
+ Transaction::Simple.start(@value) do |tv|
136
+ assert_equal(true, tv.transaction_open?)
137
+ assert_nothing_raised { tv.gsub!(/men/, 'women') }
138
+ assert_equal(VALUE.gsub(/men/, 'women'), tv)
139
+ tv.commit_transaction
140
+ flunk("Failed to commit the transaction.")
141
+ end
142
+ assert_equal(false, @value.transaction_open?)
143
+ assert_equal(VALUE.gsub(/men/, 'women'), @value)
144
+ end
145
+
146
+ def test_named_block
147
+ @value = VALUE.dup
148
+ Transaction::Simple.start_named(:first, @value) do |tv|
149
+ assert_equal(true, tv.transaction_open?)
150
+ assert_equal(true, tv.transaction_open?(:first))
151
+ assert_nothing_raised { tv.gsub!(/men/, 'women') }
152
+ assert_equal(VALUE.gsub(/men/, 'women'), tv)
153
+ tv.abort_transaction
154
+ flunk("Failed to abort the transaction.")
155
+ end
156
+ assert_equal(false, @value.transaction_open?)
157
+ assert_equal(false, @value.transaction_open?(:first))
158
+ assert_equal(VALUE, @value)
159
+
160
+ @value = VALUE.dup
161
+ Transaction::Simple.start_named(:first, @value) do |tv|
162
+ assert_equal(true, tv.transaction_open?)
163
+ assert_equal(true, tv.transaction_open?(:first))
164
+ assert_nothing_raised { tv.gsub!(/men/, 'women') }
165
+ assert_equal(VALUE.gsub(/men/, 'women'), tv)
166
+ tv.commit_transaction
167
+ flunk("Failed to commit the transaction.")
168
+ end
169
+ assert_equal(false, @value.transaction_open?)
170
+ assert_equal(false, @value.transaction_open?(:first))
171
+ assert_equal(VALUE.gsub(/men/, 'women'), @value)
172
+ end
173
+
174
+ def test_named_block_error
175
+ @value.start_transaction(:first)
176
+ Transaction::Simple.start_named(:second, @value) do |tv|
177
+ assert_equal(true, tv.transaction_open?)
178
+ assert_equal(true, tv.transaction_open?(:first))
179
+ assert_equal(true, tv.transaction_open?(:second))
180
+ assert_nothing_raised { tv.gsub!(/men/, 'women') }
181
+ assert_equal(VALUE.gsub(/men/, 'women'), tv)
182
+ assert_raises(Transaction::TransactionError) do
183
+ tv.abort_transaction(:first)
184
+ end
185
+ end
186
+ assert_equal(true, @value.transaction_open?)
187
+ assert_equal(true, @value.transaction_open?(:first))
188
+ assert_equal(false, @value.transaction_open?(:second))
189
+ assert_equal(VALUE.gsub(/men/, 'women'), @value)
190
+ assert_nothing_raised { @value.abort_transaction(:first) }
191
+ assert_equal(VALUE, @value)
192
+
193
+ @value.start_transaction(:first)
194
+ Transaction::Simple.start_named(:second, @value) do |tv|
195
+ assert_equal(true, tv.transaction_open?)
196
+ assert_equal(true, tv.transaction_open?(:first))
197
+ assert_equal(true, tv.transaction_open?(:second))
198
+ assert_nothing_raised { tv.gsub!(/men/, 'women') }
199
+ assert_equal(VALUE.gsub(/men/, 'women'), tv)
200
+ assert_raises(Transaction::TransactionError) do
201
+ tv.commit_transaction(:first)
202
+ end
203
+ end
204
+ assert_equal(true, @value.transaction_open?)
205
+ assert_equal(true, @value.transaction_open?(:first))
206
+ assert_equal(false, @value.transaction_open?(:second))
207
+ assert_equal(VALUE.gsub(/men/, 'women'), @value)
208
+ assert_nothing_raised { @value.abort_transaction(:first) }
209
+ assert_equal(VALUE, @value)
210
+ end
211
+
212
+ def test_multivar_block
213
+ a = VALUE.dup
214
+ b = a.dup
215
+
216
+ Transaction::Simple.start(a, b) do |ta, tb|
217
+ assert_equal(true, ta.transaction_open?)
218
+ assert_equal(true, tb.transaction_open?)
219
+ ta.abort_transaction
220
+ flunk("Failed to abort the transaction.")
221
+ end
222
+ assert_equal(false, a.transaction_open?)
223
+ assert_equal(false, b.transaction_open?)
224
+
225
+ Transaction::Simple.start(a, b) do |ta, tb|
226
+ assert_equal(true, ta.transaction_open?)
227
+ assert_equal(true, tb.transaction_open?)
228
+ ta.commit_transaction
229
+ flunk("Failed to commit the transaction.")
230
+ end
231
+ assert_equal(false, a.transaction_open?)
232
+ assert_equal(false, b.transaction_open?)
233
+ end
234
+
235
+ def test_multilevel_block
236
+ @value = VALUE.dup
237
+ Transaction::Simple.start_named(:outer, @value) do |tv0|
238
+ assert_equal(1, tv0.instance_variable_get(:@__transaction_level__))
239
+ assert_equal(true, tv0.transaction_open?(:outer))
240
+ Transaction::Simple.start_named(:inner, tv0) do |tv1|
241
+ assert_equal(2, tv0.instance_variable_get(:@__transaction_level__))
242
+ assert_equal(true, tv1.transaction_open?(:inner))
243
+ tv1.abort_transaction
244
+ flunk("Failed to abort the transaction.")
245
+ end
246
+ assert_equal(false, tv0.transaction_open?(:inner))
247
+ assert_equal(true, tv0.transaction_open?(:outer))
248
+
249
+ tv0.commit_transaction
250
+ flunk("Failed to commit the transaction.")
251
+ end
252
+ assert_equal(false, @value.transaction_open?(:inner))
253
+ assert_equal(false, @value.transaction_open?(:outer))
254
+ end
255
+
256
+ def test_array
257
+ assert_nothing_raised do
258
+ @orig = ["first", "second", "third"]
259
+ @value = ["first", "second", "third"]
260
+ @value.extend(Transaction::Simple)
261
+ end
262
+ assert_equal(@orig, @value)
263
+ assert_nothing_raised { @value.start_transaction }
264
+ assert_equal(true, @value.transaction_open?)
265
+ assert_nothing_raised { @value[1].gsub!(/second/, "fourth") }
266
+ assert_not_equal(@orig, @value)
267
+ assert_nothing_raised { @value.abort_transaction }
268
+ assert_equal(@orig, @value)
269
+ end
270
+ end
271
+
272
+ class Test__Transaction_Simple_ThreadSafe < Test::Unit::TestCase #:nodoc:
273
+ VALUE = "Now is the time for all good men to come to the aid of their country."
274
+
275
+ def setup
276
+ @value = VALUE.dup
277
+ @value.extend(Transaction::Simple::ThreadSafe)
278
+ end
279
+
280
+ def test_extended
281
+ assert_respond_to(@value, :start_transaction)
282
+ end
283
+
284
+ def test_started
285
+ assert_equal(false, @value.transaction_open?)
286
+ assert_nothing_raised { @value.start_transaction }
287
+ assert_equal(true, @value.transaction_open?)
288
+ end
289
+
290
+ def test_rewind
291
+ assert_equal(false, @value.transaction_open?)
292
+ assert_raises(Transaction::TransactionError) { @value.rewind_transaction }
293
+ assert_nothing_raised { @value.start_transaction }
294
+ assert_equal(true, @value.transaction_open?)
295
+ assert_nothing_raised { @value.gsub!(/men/, 'women') }
296
+ assert_not_equal(VALUE, @value)
297
+ assert_nothing_raised { @value.rewind_transaction }
298
+ assert_equal(true, @value.transaction_open?)
299
+ assert_equal(VALUE, @value)
300
+ end
301
+
302
+ def test_abort
303
+ assert_equal(false, @value.transaction_open?)
304
+ assert_raises(Transaction::TransactionError) { @value.abort_transaction }
305
+ assert_nothing_raised { @value.start_transaction }
306
+ assert_equal(true, @value.transaction_open?)
307
+ assert_nothing_raised { @value.gsub!(/men/, 'women') }
308
+ assert_not_equal(VALUE, @value)
309
+ assert_nothing_raised { @value.abort_transaction }
310
+ assert_equal(false, @value.transaction_open?)
311
+ assert_equal(VALUE, @value)
312
+ end
313
+
314
+ def test_commit
315
+ assert_equal(false, @value.transaction_open?)
316
+ assert_raises(Transaction::TransactionError) { @value.commit_transaction }
317
+ assert_nothing_raised { @value.start_transaction }
318
+ assert_equal(true, @value.transaction_open?)
319
+ assert_nothing_raised { @value.gsub!(/men/, 'women') }
320
+ assert_not_equal(VALUE, @value)
321
+ assert_equal(true, @value.transaction_open?)
322
+ assert_nothing_raised { @value.commit_transaction }
323
+ assert_equal(false, @value.transaction_open?)
324
+ assert_not_equal(VALUE, @value)
325
+ end
326
+
327
+ def test_multilevel
328
+ assert_equal(false, @value.transaction_open?)
329
+ assert_nothing_raised { @value.start_transaction }
330
+ assert_equal(true, @value.transaction_open?)
331
+ assert_nothing_raised { @value.gsub!(/men/, 'women') }
332
+ assert_equal(VALUE.gsub(/men/, 'women'), @value)
333
+ assert_equal(true, @value.transaction_open?)
334
+ assert_nothing_raised { @value.start_transaction }
335
+ assert_nothing_raised { @value.gsub!(/country/, 'nation-state') }
336
+ assert_nothing_raised { @value.commit_transaction }
337
+ assert_equal(VALUE.gsub(/men/, 'women').gsub(/country/, 'nation-state'), @value)
338
+ assert_equal(true, @value.transaction_open?)
339
+ assert_nothing_raised { @value.abort_transaction }
340
+ assert_equal(VALUE, @value)
341
+ end
342
+
343
+ def test_multilevel_named
344
+ assert_equal(false, @value.transaction_open?)
345
+ assert_raises(Transaction::TransactionError) { @value.transaction_name }
346
+ assert_nothing_raised { @value.start_transaction(:first) } # 1
347
+ assert_raises(Transaction::TransactionError) { @value.start_transaction(:first) }
348
+ assert_equal(true, @value.transaction_open?)
349
+ assert_equal(true, @value.transaction_open?(:first))
350
+ assert_equal(:first, @value.transaction_name)
351
+ assert_nothing_raised { @value.start_transaction } # 2
352
+ assert_not_equal(:first, @value.transaction_name)
353
+ assert_equal(nil, @value.transaction_name)
354
+ assert_raises(Transaction::TransactionError) { @value.abort_transaction(:second) }
355
+ assert_nothing_raised { @value.abort_transaction(:first) }
356
+ assert_equal(false, @value.transaction_open?)
357
+ assert_nothing_raised do
358
+ @value.start_transaction(:first)
359
+ @value.gsub!(/men/, 'women')
360
+ @value.start_transaction(:second)
361
+ @value.gsub!(/women/, 'people')
362
+ @value.start_transaction
363
+ @value.gsub!(/people/, 'sentients')
364
+ end
365
+ assert_nothing_raised { @value.abort_transaction(:second) }
366
+ assert_equal(true, @value.transaction_open?(:first))
367
+ assert_equal(VALUE.gsub(/men/, 'women'), @value)
368
+ assert_nothing_raised do
369
+ @value.start_transaction(:second)
370
+ @value.gsub!(/women/, 'people')
371
+ @value.start_transaction
372
+ @value.gsub!(/people/, 'sentients')
373
+ end
374
+ assert_raises(Transaction::TransactionError) { @value.rewind_transaction(:foo) }
375
+ assert_nothing_raised { @value.rewind_transaction(:second) }
376
+ assert_equal(VALUE.gsub(/men/, 'women'), @value)
377
+ assert_nothing_raised do
378
+ @value.gsub!(/women/, 'people')
379
+ @value.start_transaction
380
+ @value.gsub!(/people/, 'sentients')
381
+ end
382
+ assert_raises(Transaction::TransactionError) { @value.commit_transaction(:foo) }
383
+ assert_nothing_raised { @value.commit_transaction(:first) }
384
+ assert_equal(VALUE.gsub(/men/, 'sentients'), @value)
385
+ assert_equal(false, @value.transaction_open?)
386
+ end
387
+
388
+ def test_array
389
+ assert_nothing_raised do
390
+ @orig = ["first", "second", "third"]
391
+ @value = ["first", "second", "third"]
392
+ @value.extend(Transaction::Simple::ThreadSafe)
393
+ end
394
+ assert_equal(@orig, @value)
395
+ assert_nothing_raised { @value.start_transaction }
396
+ assert_equal(true, @value.transaction_open?)
397
+ assert_nothing_raised { @value[1].gsub!(/second/, "fourth") }
398
+ assert_not_equal(@orig, @value)
399
+ assert_nothing_raised { @value.abort_transaction }
400
+ assert_equal(@orig, @value)
401
+ end
402
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.1
3
+ specification_version: 1
4
+ name: transaction-simple
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.2.0
7
+ date: 2004-11-03
8
+ summary: Simple object transaction support for Ruby.
9
+ require_paths:
10
+ - lib
11
+ author: Austin Ziegler
12
+ email: transaction-simple@halostatue.ca
13
+ homepage: http://rubyforge.org/projects/trans-simple
14
+ rubyforge_project: trans-simple
15
+ description: ''
16
+ autorequire: transaction/simple
17
+ default_executable:
18
+ bindir: bin
19
+ has_rdoc: true
20
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
21
+ requirements:
22
+ -
23
+ - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 1.8.1
26
+ version:
27
+ platform: ruby
28
+ files:
29
+ - Changelog
30
+ - Install
31
+ - lib
32
+ - Rakefile
33
+ - Readme
34
+ - tests
35
+ - lib/transaction
36
+ - lib/transaction/simple.rb
37
+ - tests/tests.rb
38
+ - README
39
+ - ChangeLog
40
+ test_files:
41
+ - tests/tests.rb
42
+ rdoc_options:
43
+ - "--title"
44
+ - "Transaction::Simple -- Simple object transaction support"
45
+ - "--main"
46
+ - Transaction::Simple
47
+ - "--line-numbers"
48
+ extra_rdoc_files:
49
+ - README
50
+ - ChangeLog
51
+ - Install
52
+ executables: []
53
+ extensions: []
54
+ requirements: []
55
+ dependencies: []