ibm_db 2.5.27-x86-mingw32 → 2.6.0-x86-mingw32
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.
- checksums.yaml +4 -4
- data/CHANGES +5 -0
- data/MANIFEST +14 -14
- data/README +225 -225
- data/ext/Makefile.nt32 +181 -181
- data/ext/Makefile.nt32.191 +212 -212
- data/ext/extconf.rb +264 -264
- data/ext/extconf_MacOS.rb +269 -0
- data/ext/ibm_db.c +1 -1
- data/ext/ruby_ibm_db.h +241 -241
- data/init.rb +41 -41
- data/lib/IBM_DB.rb +27 -3
- data/lib/active_record/connection_adapters/ibm_db_adapter.rb +3290 -3290
- data/lib/active_record/connection_adapters/ibmdb_adapter.rb +1 -1
- data/lib/active_record/vendor/db2-i5-zOS.yaml +328 -328
- data/lib/mswin32/ibm_db.rb +104 -20
- data/lib/mswin32/rb19x/ibm_db.so +0 -0
- data/lib/mswin32/rb21x/i386/ibm_db.so +0 -0
- data/lib/mswin32/rb22x/i386/ibm_db.so +0 -0
- data/lib/mswin32/rb2x/i386/ibm_db.so +0 -0
- data/test/cases/adapter_test.rb +207 -207
- data/test/cases/associations/belongs_to_associations_test.rb +711 -711
- data/test/cases/associations/cascaded_eager_loading_test.rb +181 -181
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +851 -851
- data/test/cases/associations/join_model_test.rb +743 -743
- data/test/cases/attribute_methods_test.rb +822 -822
- data/test/cases/base_test.rb +2133 -2133
- data/test/cases/calculations_test.rb +482 -482
- data/test/cases/migration_test.rb +2408 -2408
- data/test/cases/persistence_test.rb +642 -642
- data/test/cases/query_cache_test.rb +257 -257
- data/test/cases/relations_test.rb +1182 -1182
- data/test/cases/schema_dumper_test.rb +256 -256
- data/test/cases/transaction_callbacks_test.rb +300 -300
- data/test/cases/validations/uniqueness_validation_test.rb +299 -299
- data/test/cases/xml_serialization_test.rb +408 -408
- data/test/config.yml +154 -154
- data/test/connections/native_ibm_db/connection.rb +43 -43
- data/test/ibm_db_test.rb +24 -24
- data/test/models/warehouse_thing.rb +4 -4
- data/test/schema/schema.rb +751 -751
- metadata +31 -16
@@ -1,300 +1,300 @@
|
|
1
|
-
require "cases/helper"
|
2
|
-
require 'models/topic'
|
3
|
-
|
4
|
-
class TransactionCallbacksTest < ActiveRecord::TestCase
|
5
|
-
self.use_transactional_fixtures = false
|
6
|
-
fixtures :topics
|
7
|
-
|
8
|
-
class TopicWithCallbacks < ActiveRecord::Base
|
9
|
-
self.table_name = :topics
|
10
|
-
|
11
|
-
after_commit{|record| record.send(:do_after_commit, nil)}
|
12
|
-
after_commit(:on => :create){|record| record.send(:do_after_commit, :create)}
|
13
|
-
after_commit(:on => :update){|record| record.send(:do_after_commit, :update)}
|
14
|
-
after_commit(:on => :destroy){|record| record.send(:do_after_commit, :destroy)}
|
15
|
-
after_rollback{|record| record.send(:do_after_rollback, nil)}
|
16
|
-
after_rollback(:on => :create){|record| record.send(:do_after_rollback, :create)}
|
17
|
-
after_rollback(:on => :update){|record| record.send(:do_after_rollback, :update)}
|
18
|
-
after_rollback(:on => :destroy){|record| record.send(:do_after_rollback, :destroy)}
|
19
|
-
|
20
|
-
def history
|
21
|
-
@history ||= []
|
22
|
-
end
|
23
|
-
|
24
|
-
def after_commit_block(on = nil, &block)
|
25
|
-
@after_commit ||= {}
|
26
|
-
@after_commit[on] ||= []
|
27
|
-
@after_commit[on] << block
|
28
|
-
end
|
29
|
-
|
30
|
-
def after_rollback_block(on = nil, &block)
|
31
|
-
@after_rollback ||= {}
|
32
|
-
@after_rollback[on] ||= []
|
33
|
-
@after_rollback[on] << block
|
34
|
-
end
|
35
|
-
|
36
|
-
def do_after_commit(on)
|
37
|
-
blocks = @after_commit[on] if defined?(@after_commit)
|
38
|
-
blocks.each{|b| b.call(self)} if blocks
|
39
|
-
end
|
40
|
-
|
41
|
-
def do_after_rollback(on)
|
42
|
-
blocks = @after_rollback[on] if defined?(@after_rollback)
|
43
|
-
blocks.each{|b| b.call(self)} if blocks
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def setup
|
48
|
-
@first, @second = TopicWithCallbacks.find(1, 3).sort_by { |t| t.id }
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_call_after_commit_after_transaction_commits
|
52
|
-
@first.after_commit_block{|r| r.history << :after_commit}
|
53
|
-
@first.after_rollback_block{|r| r.history << :after_rollback}
|
54
|
-
|
55
|
-
@first.save!
|
56
|
-
assert_equal [:after_commit], @first.history
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_only_call_after_commit_on_update_after_transaction_commits_for_existing_record
|
60
|
-
@first.after_commit_block(:create){|r| r.history << :commit_on_create}
|
61
|
-
@first.after_commit_block(:update){|r| r.history << :commit_on_update}
|
62
|
-
@first.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
|
63
|
-
@first.after_rollback_block(:create){|r| r.history << :rollback_on_create}
|
64
|
-
@first.after_rollback_block(:update){|r| r.history << :rollback_on_update}
|
65
|
-
@first.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}
|
66
|
-
|
67
|
-
@first.save!
|
68
|
-
assert_equal [:commit_on_update], @first.history
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_only_call_after_commit_on_destroy_after_transaction_commits_for_destroyed_record
|
72
|
-
@first.after_commit_block(:create){|r| r.history << :commit_on_create}
|
73
|
-
@first.after_commit_block(:update){|r| r.history << :commit_on_update}
|
74
|
-
@first.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
|
75
|
-
@first.after_rollback_block(:create){|r| r.history << :rollback_on_create}
|
76
|
-
@first.after_rollback_block(:update){|r| r.history << :rollback_on_update}
|
77
|
-
@first.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}
|
78
|
-
|
79
|
-
@first.destroy
|
80
|
-
assert_equal [:commit_on_destroy], @first.history
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_only_call_after_commit_on_create_after_transaction_commits_for_new_record
|
84
|
-
unless current_adapter?(:IBM_DBAdapter)
|
85
|
-
@new_record = TopicWithCallbacks.new(:title => "New topic", :written_on => Date.today)
|
86
|
-
else
|
87
|
-
@new_record = TopicWithCallbacks.new(:title => "New topic", :written_on => Time.now)
|
88
|
-
end
|
89
|
-
@new_record.after_commit_block(:create){|r| r.history << :commit_on_create}
|
90
|
-
@new_record.after_commit_block(:update){|r| r.history << :commit_on_update}
|
91
|
-
@new_record.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
|
92
|
-
@new_record.after_rollback_block(:create){|r| r.history << :rollback_on_create}
|
93
|
-
@new_record.after_rollback_block(:update){|r| r.history << :rollback_on_update}
|
94
|
-
@new_record.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}
|
95
|
-
|
96
|
-
@new_record.save!
|
97
|
-
assert_equal [:commit_on_create], @new_record.history
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_call_after_rollback_after_transaction_rollsback
|
101
|
-
@first.after_commit_block{|r| r.history << :after_commit}
|
102
|
-
@first.after_rollback_block{|r| r.history << :after_rollback}
|
103
|
-
|
104
|
-
Topic.transaction do
|
105
|
-
@first.save!
|
106
|
-
raise ActiveRecord::Rollback
|
107
|
-
end
|
108
|
-
|
109
|
-
assert_equal [:after_rollback], @first.history
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_only_call_after_rollback_on_update_after_transaction_rollsback_for_existing_record
|
113
|
-
@first.after_commit_block(:create){|r| r.history << :commit_on_create}
|
114
|
-
@first.after_commit_block(:update){|r| r.history << :commit_on_update}
|
115
|
-
@first.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
|
116
|
-
@first.after_rollback_block(:create){|r| r.history << :rollback_on_create}
|
117
|
-
@first.after_rollback_block(:update){|r| r.history << :rollback_on_update}
|
118
|
-
@first.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}
|
119
|
-
|
120
|
-
Topic.transaction do
|
121
|
-
@first.save!
|
122
|
-
raise ActiveRecord::Rollback
|
123
|
-
end
|
124
|
-
|
125
|
-
assert_equal [:rollback_on_update], @first.history
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_only_call_after_rollback_on_destroy_after_transaction_rollsback_for_destroyed_record
|
129
|
-
@first.after_commit_block(:create){|r| r.history << :commit_on_create}
|
130
|
-
@first.after_commit_block(:update){|r| r.history << :commit_on_update}
|
131
|
-
@first.after_commit_block(:destroy){|r| r.history << :commit_on_update}
|
132
|
-
@first.after_rollback_block(:create){|r| r.history << :rollback_on_create}
|
133
|
-
@first.after_rollback_block(:update){|r| r.history << :rollback_on_update}
|
134
|
-
@first.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}
|
135
|
-
|
136
|
-
Topic.transaction do
|
137
|
-
@first.destroy
|
138
|
-
raise ActiveRecord::Rollback
|
139
|
-
end
|
140
|
-
|
141
|
-
assert_equal [:rollback_on_destroy], @first.history
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_only_call_after_rollback_on_create_after_transaction_rollsback_for_new_record
|
145
|
-
unless current_adapter?(:IBM_DBAdapter)
|
146
|
-
@new_record = TopicWithCallbacks.new(:title => "New topic", :written_on => Date.today)
|
147
|
-
else
|
148
|
-
@new_record = TopicWithCallbacks.new(:title => "New topic", :written_on => Time.now)
|
149
|
-
end
|
150
|
-
@new_record.after_commit_block(:create){|r| r.history << :commit_on_create}
|
151
|
-
@new_record.after_commit_block(:update){|r| r.history << :commit_on_update}
|
152
|
-
@new_record.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
|
153
|
-
@new_record.after_rollback_block(:create){|r| r.history << :rollback_on_create}
|
154
|
-
@new_record.after_rollback_block(:update){|r| r.history << :rollback_on_update}
|
155
|
-
@new_record.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}
|
156
|
-
|
157
|
-
Topic.transaction do
|
158
|
-
@new_record.save!
|
159
|
-
raise ActiveRecord::Rollback
|
160
|
-
end
|
161
|
-
|
162
|
-
assert_equal [:rollback_on_create], @new_record.history
|
163
|
-
end
|
164
|
-
|
165
|
-
def test_call_after_rollback_when_commit_fails
|
166
|
-
@first.connection.class.send(:alias_method, :real_method_commit_db_transaction, :commit_db_transaction)
|
167
|
-
begin
|
168
|
-
@first.connection.class.class_eval do
|
169
|
-
def commit_db_transaction; raise "boom!"; end
|
170
|
-
end
|
171
|
-
|
172
|
-
@first.after_commit_block{|r| r.history << :after_commit}
|
173
|
-
@first.after_rollback_block{|r| r.history << :after_rollback}
|
174
|
-
|
175
|
-
assert !@first.save rescue nil
|
176
|
-
assert_equal [:after_rollback], @first.history
|
177
|
-
ensure
|
178
|
-
@first.connection.class.send(:remove_method, :commit_db_transaction)
|
179
|
-
@first.connection.class.send(:alias_method, :commit_db_transaction, :real_method_commit_db_transaction)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
def test_only_call_after_rollback_on_records_rolled_back_to_a_savepoint
|
184
|
-
def @first.rollbacks(i=0); @rollbacks ||= 0; @rollbacks += i if i; end
|
185
|
-
def @first.commits(i=0); @commits ||= 0; @commits += i if i; end
|
186
|
-
@first.after_rollback_block{|r| r.rollbacks(1)}
|
187
|
-
@first.after_commit_block{|r| r.commits(1)}
|
188
|
-
|
189
|
-
def @second.rollbacks(i=0); @rollbacks ||= 0; @rollbacks += i if i; end
|
190
|
-
def @second.commits(i=0); @commits ||= 0; @commits += i if i; end
|
191
|
-
@second.after_rollback_block{|r| r.rollbacks(1)}
|
192
|
-
@second.after_commit_block{|r| r.commits(1)}
|
193
|
-
|
194
|
-
Topic.transaction do
|
195
|
-
@first.save!
|
196
|
-
Topic.transaction(:requires_new => true) do
|
197
|
-
@second.save!
|
198
|
-
raise ActiveRecord::Rollback
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
assert_equal 1, @first.commits
|
203
|
-
assert_equal 0, @first.rollbacks
|
204
|
-
assert_equal 0, @second.commits
|
205
|
-
assert_equal 1, @second.rollbacks
|
206
|
-
end
|
207
|
-
|
208
|
-
def test_only_call_after_rollback_on_records_rolled_back_to_a_savepoint_when_release_savepoint_fails
|
209
|
-
def @first.rollbacks(i=0); @rollbacks ||= 0; @rollbacks += i if i; end
|
210
|
-
def @first.commits(i=0); @commits ||= 0; @commits += i if i; end
|
211
|
-
|
212
|
-
@first.after_rollback_block{|r| r.rollbacks(1)}
|
213
|
-
@first.after_commit_block{|r| r.commits(1)}
|
214
|
-
|
215
|
-
Topic.transaction do
|
216
|
-
@first.save
|
217
|
-
Topic.transaction(:requires_new => true) do
|
218
|
-
@first.save!
|
219
|
-
raise ActiveRecord::Rollback
|
220
|
-
end
|
221
|
-
Topic.transaction(:requires_new => true) do
|
222
|
-
@first.save!
|
223
|
-
raise ActiveRecord::Rollback
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
assert_equal 1, @first.commits
|
228
|
-
assert_equal 2, @first.rollbacks
|
229
|
-
end
|
230
|
-
|
231
|
-
def test_after_transaction_callbacks_should_prevent_callbacks_from_being_called
|
232
|
-
def @first.last_after_transaction_error=(e); @last_transaction_error = e; end
|
233
|
-
def @first.last_after_transaction_error; @last_transaction_error; end
|
234
|
-
@first.after_commit_block{|r| r.last_after_transaction_error = :commit; raise "fail!";}
|
235
|
-
@first.after_rollback_block{|r| r.last_after_transaction_error = :rollback; raise "fail!";}
|
236
|
-
@second.after_commit_block{|r| r.history << :after_commit}
|
237
|
-
@second.after_rollback_block{|r| r.history << :after_rollback}
|
238
|
-
|
239
|
-
Topic.transaction do
|
240
|
-
@first.save!
|
241
|
-
@second.save!
|
242
|
-
end
|
243
|
-
assert_equal :commit, @first.last_after_transaction_error
|
244
|
-
assert_equal [:after_commit], @second.history
|
245
|
-
|
246
|
-
@second.history.clear
|
247
|
-
Topic.transaction do
|
248
|
-
@first.save!
|
249
|
-
@second.save!
|
250
|
-
raise ActiveRecord::Rollback
|
251
|
-
end
|
252
|
-
assert_equal :rollback, @first.last_after_transaction_error
|
253
|
-
assert_equal [:after_rollback], @second.history
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
|
258
|
-
class TransactionObserverCallbacksTest < ActiveRecord::TestCase
|
259
|
-
self.use_transactional_fixtures = false
|
260
|
-
fixtures :topics
|
261
|
-
|
262
|
-
class TopicWithObserverAttached < ActiveRecord::Base
|
263
|
-
self.table_name = :topics
|
264
|
-
def history
|
265
|
-
@history ||= []
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
class TopicWithObserverAttachedObserver < ActiveRecord::Observer
|
270
|
-
def after_commit(record)
|
271
|
-
record.history.push "after_commit"
|
272
|
-
end
|
273
|
-
|
274
|
-
def after_rollback(record)
|
275
|
-
record.history.push "after_rollback"
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
def test_after_commit_called
|
280
|
-
assert TopicWithObserverAttachedObserver.instance, 'should have observer'
|
281
|
-
|
282
|
-
topic = TopicWithObserverAttached.new
|
283
|
-
topic.save!
|
284
|
-
|
285
|
-
assert_equal %w{ after_commit }, topic.history
|
286
|
-
end
|
287
|
-
|
288
|
-
def test_after_rollback_called
|
289
|
-
assert TopicWithObserverAttachedObserver.instance, 'should have observer'
|
290
|
-
|
291
|
-
topic = TopicWithObserverAttached.new
|
292
|
-
|
293
|
-
Topic.transaction do
|
294
|
-
topic.save!
|
295
|
-
raise ActiveRecord::Rollback
|
296
|
-
end
|
297
|
-
|
298
|
-
assert_equal %w{ after_rollback }, topic.history
|
299
|
-
end
|
300
|
-
end
|
1
|
+
require "cases/helper"
|
2
|
+
require 'models/topic'
|
3
|
+
|
4
|
+
class TransactionCallbacksTest < ActiveRecord::TestCase
|
5
|
+
self.use_transactional_fixtures = false
|
6
|
+
fixtures :topics
|
7
|
+
|
8
|
+
class TopicWithCallbacks < ActiveRecord::Base
|
9
|
+
self.table_name = :topics
|
10
|
+
|
11
|
+
after_commit{|record| record.send(:do_after_commit, nil)}
|
12
|
+
after_commit(:on => :create){|record| record.send(:do_after_commit, :create)}
|
13
|
+
after_commit(:on => :update){|record| record.send(:do_after_commit, :update)}
|
14
|
+
after_commit(:on => :destroy){|record| record.send(:do_after_commit, :destroy)}
|
15
|
+
after_rollback{|record| record.send(:do_after_rollback, nil)}
|
16
|
+
after_rollback(:on => :create){|record| record.send(:do_after_rollback, :create)}
|
17
|
+
after_rollback(:on => :update){|record| record.send(:do_after_rollback, :update)}
|
18
|
+
after_rollback(:on => :destroy){|record| record.send(:do_after_rollback, :destroy)}
|
19
|
+
|
20
|
+
def history
|
21
|
+
@history ||= []
|
22
|
+
end
|
23
|
+
|
24
|
+
def after_commit_block(on = nil, &block)
|
25
|
+
@after_commit ||= {}
|
26
|
+
@after_commit[on] ||= []
|
27
|
+
@after_commit[on] << block
|
28
|
+
end
|
29
|
+
|
30
|
+
def after_rollback_block(on = nil, &block)
|
31
|
+
@after_rollback ||= {}
|
32
|
+
@after_rollback[on] ||= []
|
33
|
+
@after_rollback[on] << block
|
34
|
+
end
|
35
|
+
|
36
|
+
def do_after_commit(on)
|
37
|
+
blocks = @after_commit[on] if defined?(@after_commit)
|
38
|
+
blocks.each{|b| b.call(self)} if blocks
|
39
|
+
end
|
40
|
+
|
41
|
+
def do_after_rollback(on)
|
42
|
+
blocks = @after_rollback[on] if defined?(@after_rollback)
|
43
|
+
blocks.each{|b| b.call(self)} if blocks
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def setup
|
48
|
+
@first, @second = TopicWithCallbacks.find(1, 3).sort_by { |t| t.id }
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_call_after_commit_after_transaction_commits
|
52
|
+
@first.after_commit_block{|r| r.history << :after_commit}
|
53
|
+
@first.after_rollback_block{|r| r.history << :after_rollback}
|
54
|
+
|
55
|
+
@first.save!
|
56
|
+
assert_equal [:after_commit], @first.history
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_only_call_after_commit_on_update_after_transaction_commits_for_existing_record
|
60
|
+
@first.after_commit_block(:create){|r| r.history << :commit_on_create}
|
61
|
+
@first.after_commit_block(:update){|r| r.history << :commit_on_update}
|
62
|
+
@first.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
|
63
|
+
@first.after_rollback_block(:create){|r| r.history << :rollback_on_create}
|
64
|
+
@first.after_rollback_block(:update){|r| r.history << :rollback_on_update}
|
65
|
+
@first.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}
|
66
|
+
|
67
|
+
@first.save!
|
68
|
+
assert_equal [:commit_on_update], @first.history
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_only_call_after_commit_on_destroy_after_transaction_commits_for_destroyed_record
|
72
|
+
@first.after_commit_block(:create){|r| r.history << :commit_on_create}
|
73
|
+
@first.after_commit_block(:update){|r| r.history << :commit_on_update}
|
74
|
+
@first.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
|
75
|
+
@first.after_rollback_block(:create){|r| r.history << :rollback_on_create}
|
76
|
+
@first.after_rollback_block(:update){|r| r.history << :rollback_on_update}
|
77
|
+
@first.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}
|
78
|
+
|
79
|
+
@first.destroy
|
80
|
+
assert_equal [:commit_on_destroy], @first.history
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_only_call_after_commit_on_create_after_transaction_commits_for_new_record
|
84
|
+
unless current_adapter?(:IBM_DBAdapter)
|
85
|
+
@new_record = TopicWithCallbacks.new(:title => "New topic", :written_on => Date.today)
|
86
|
+
else
|
87
|
+
@new_record = TopicWithCallbacks.new(:title => "New topic", :written_on => Time.now)
|
88
|
+
end
|
89
|
+
@new_record.after_commit_block(:create){|r| r.history << :commit_on_create}
|
90
|
+
@new_record.after_commit_block(:update){|r| r.history << :commit_on_update}
|
91
|
+
@new_record.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
|
92
|
+
@new_record.after_rollback_block(:create){|r| r.history << :rollback_on_create}
|
93
|
+
@new_record.after_rollback_block(:update){|r| r.history << :rollback_on_update}
|
94
|
+
@new_record.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}
|
95
|
+
|
96
|
+
@new_record.save!
|
97
|
+
assert_equal [:commit_on_create], @new_record.history
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_call_after_rollback_after_transaction_rollsback
|
101
|
+
@first.after_commit_block{|r| r.history << :after_commit}
|
102
|
+
@first.after_rollback_block{|r| r.history << :after_rollback}
|
103
|
+
|
104
|
+
Topic.transaction do
|
105
|
+
@first.save!
|
106
|
+
raise ActiveRecord::Rollback
|
107
|
+
end
|
108
|
+
|
109
|
+
assert_equal [:after_rollback], @first.history
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_only_call_after_rollback_on_update_after_transaction_rollsback_for_existing_record
|
113
|
+
@first.after_commit_block(:create){|r| r.history << :commit_on_create}
|
114
|
+
@first.after_commit_block(:update){|r| r.history << :commit_on_update}
|
115
|
+
@first.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
|
116
|
+
@first.after_rollback_block(:create){|r| r.history << :rollback_on_create}
|
117
|
+
@first.after_rollback_block(:update){|r| r.history << :rollback_on_update}
|
118
|
+
@first.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}
|
119
|
+
|
120
|
+
Topic.transaction do
|
121
|
+
@first.save!
|
122
|
+
raise ActiveRecord::Rollback
|
123
|
+
end
|
124
|
+
|
125
|
+
assert_equal [:rollback_on_update], @first.history
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_only_call_after_rollback_on_destroy_after_transaction_rollsback_for_destroyed_record
|
129
|
+
@first.after_commit_block(:create){|r| r.history << :commit_on_create}
|
130
|
+
@first.after_commit_block(:update){|r| r.history << :commit_on_update}
|
131
|
+
@first.after_commit_block(:destroy){|r| r.history << :commit_on_update}
|
132
|
+
@first.after_rollback_block(:create){|r| r.history << :rollback_on_create}
|
133
|
+
@first.after_rollback_block(:update){|r| r.history << :rollback_on_update}
|
134
|
+
@first.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}
|
135
|
+
|
136
|
+
Topic.transaction do
|
137
|
+
@first.destroy
|
138
|
+
raise ActiveRecord::Rollback
|
139
|
+
end
|
140
|
+
|
141
|
+
assert_equal [:rollback_on_destroy], @first.history
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_only_call_after_rollback_on_create_after_transaction_rollsback_for_new_record
|
145
|
+
unless current_adapter?(:IBM_DBAdapter)
|
146
|
+
@new_record = TopicWithCallbacks.new(:title => "New topic", :written_on => Date.today)
|
147
|
+
else
|
148
|
+
@new_record = TopicWithCallbacks.new(:title => "New topic", :written_on => Time.now)
|
149
|
+
end
|
150
|
+
@new_record.after_commit_block(:create){|r| r.history << :commit_on_create}
|
151
|
+
@new_record.after_commit_block(:update){|r| r.history << :commit_on_update}
|
152
|
+
@new_record.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
|
153
|
+
@new_record.after_rollback_block(:create){|r| r.history << :rollback_on_create}
|
154
|
+
@new_record.after_rollback_block(:update){|r| r.history << :rollback_on_update}
|
155
|
+
@new_record.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}
|
156
|
+
|
157
|
+
Topic.transaction do
|
158
|
+
@new_record.save!
|
159
|
+
raise ActiveRecord::Rollback
|
160
|
+
end
|
161
|
+
|
162
|
+
assert_equal [:rollback_on_create], @new_record.history
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_call_after_rollback_when_commit_fails
|
166
|
+
@first.connection.class.send(:alias_method, :real_method_commit_db_transaction, :commit_db_transaction)
|
167
|
+
begin
|
168
|
+
@first.connection.class.class_eval do
|
169
|
+
def commit_db_transaction; raise "boom!"; end
|
170
|
+
end
|
171
|
+
|
172
|
+
@first.after_commit_block{|r| r.history << :after_commit}
|
173
|
+
@first.after_rollback_block{|r| r.history << :after_rollback}
|
174
|
+
|
175
|
+
assert !@first.save rescue nil
|
176
|
+
assert_equal [:after_rollback], @first.history
|
177
|
+
ensure
|
178
|
+
@first.connection.class.send(:remove_method, :commit_db_transaction)
|
179
|
+
@first.connection.class.send(:alias_method, :commit_db_transaction, :real_method_commit_db_transaction)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_only_call_after_rollback_on_records_rolled_back_to_a_savepoint
|
184
|
+
def @first.rollbacks(i=0); @rollbacks ||= 0; @rollbacks += i if i; end
|
185
|
+
def @first.commits(i=0); @commits ||= 0; @commits += i if i; end
|
186
|
+
@first.after_rollback_block{|r| r.rollbacks(1)}
|
187
|
+
@first.after_commit_block{|r| r.commits(1)}
|
188
|
+
|
189
|
+
def @second.rollbacks(i=0); @rollbacks ||= 0; @rollbacks += i if i; end
|
190
|
+
def @second.commits(i=0); @commits ||= 0; @commits += i if i; end
|
191
|
+
@second.after_rollback_block{|r| r.rollbacks(1)}
|
192
|
+
@second.after_commit_block{|r| r.commits(1)}
|
193
|
+
|
194
|
+
Topic.transaction do
|
195
|
+
@first.save!
|
196
|
+
Topic.transaction(:requires_new => true) do
|
197
|
+
@second.save!
|
198
|
+
raise ActiveRecord::Rollback
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
assert_equal 1, @first.commits
|
203
|
+
assert_equal 0, @first.rollbacks
|
204
|
+
assert_equal 0, @second.commits
|
205
|
+
assert_equal 1, @second.rollbacks
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_only_call_after_rollback_on_records_rolled_back_to_a_savepoint_when_release_savepoint_fails
|
209
|
+
def @first.rollbacks(i=0); @rollbacks ||= 0; @rollbacks += i if i; end
|
210
|
+
def @first.commits(i=0); @commits ||= 0; @commits += i if i; end
|
211
|
+
|
212
|
+
@first.after_rollback_block{|r| r.rollbacks(1)}
|
213
|
+
@first.after_commit_block{|r| r.commits(1)}
|
214
|
+
|
215
|
+
Topic.transaction do
|
216
|
+
@first.save
|
217
|
+
Topic.transaction(:requires_new => true) do
|
218
|
+
@first.save!
|
219
|
+
raise ActiveRecord::Rollback
|
220
|
+
end
|
221
|
+
Topic.transaction(:requires_new => true) do
|
222
|
+
@first.save!
|
223
|
+
raise ActiveRecord::Rollback
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
assert_equal 1, @first.commits
|
228
|
+
assert_equal 2, @first.rollbacks
|
229
|
+
end
|
230
|
+
|
231
|
+
def test_after_transaction_callbacks_should_prevent_callbacks_from_being_called
|
232
|
+
def @first.last_after_transaction_error=(e); @last_transaction_error = e; end
|
233
|
+
def @first.last_after_transaction_error; @last_transaction_error; end
|
234
|
+
@first.after_commit_block{|r| r.last_after_transaction_error = :commit; raise "fail!";}
|
235
|
+
@first.after_rollback_block{|r| r.last_after_transaction_error = :rollback; raise "fail!";}
|
236
|
+
@second.after_commit_block{|r| r.history << :after_commit}
|
237
|
+
@second.after_rollback_block{|r| r.history << :after_rollback}
|
238
|
+
|
239
|
+
Topic.transaction do
|
240
|
+
@first.save!
|
241
|
+
@second.save!
|
242
|
+
end
|
243
|
+
assert_equal :commit, @first.last_after_transaction_error
|
244
|
+
assert_equal [:after_commit], @second.history
|
245
|
+
|
246
|
+
@second.history.clear
|
247
|
+
Topic.transaction do
|
248
|
+
@first.save!
|
249
|
+
@second.save!
|
250
|
+
raise ActiveRecord::Rollback
|
251
|
+
end
|
252
|
+
assert_equal :rollback, @first.last_after_transaction_error
|
253
|
+
assert_equal [:after_rollback], @second.history
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
|
258
|
+
class TransactionObserverCallbacksTest < ActiveRecord::TestCase
|
259
|
+
self.use_transactional_fixtures = false
|
260
|
+
fixtures :topics
|
261
|
+
|
262
|
+
class TopicWithObserverAttached < ActiveRecord::Base
|
263
|
+
self.table_name = :topics
|
264
|
+
def history
|
265
|
+
@history ||= []
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
class TopicWithObserverAttachedObserver < ActiveRecord::Observer
|
270
|
+
def after_commit(record)
|
271
|
+
record.history.push "after_commit"
|
272
|
+
end
|
273
|
+
|
274
|
+
def after_rollback(record)
|
275
|
+
record.history.push "after_rollback"
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
def test_after_commit_called
|
280
|
+
assert TopicWithObserverAttachedObserver.instance, 'should have observer'
|
281
|
+
|
282
|
+
topic = TopicWithObserverAttached.new
|
283
|
+
topic.save!
|
284
|
+
|
285
|
+
assert_equal %w{ after_commit }, topic.history
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_after_rollback_called
|
289
|
+
assert TopicWithObserverAttachedObserver.instance, 'should have observer'
|
290
|
+
|
291
|
+
topic = TopicWithObserverAttached.new
|
292
|
+
|
293
|
+
Topic.transaction do
|
294
|
+
topic.save!
|
295
|
+
raise ActiveRecord::Rollback
|
296
|
+
end
|
297
|
+
|
298
|
+
assert_equal %w{ after_rollback }, topic.history
|
299
|
+
end
|
300
|
+
end
|