File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -194,7 +194,7 @@ def each_tuple(&block) #:nodoc:
194
194
rescue Exception => e
195
195
raise e
196
196
ensure
197
- close if @block
197
+ close if @block && connection . active?
198
198
end
199
199
end
200
200
@count
@@ -216,7 +216,7 @@ def each_batch(&block) #:nodoc:
216
216
break if has_do_while && rc != @options [ :while ]
217
217
end
218
218
ensure
219
- close if @block
219
+ close if @block && connection . active?
220
220
end
221
221
end
222
222
@count
Original file line number Diff line number Diff line change @@ -130,6 +130,26 @@ def test_batch_exception
130
130
assert_equal e . message , 'Oops'
131
131
end
132
132
133
+ def test_exception_in_failed_transaction
134
+ begin
135
+ Product . each_row_by_sql ( "select * from products" ) do |r |
136
+ Product . connection . execute ( 'select kaboom' )
137
+ end
138
+ rescue Exception => e
139
+ assert_match ( /kaboom/ , e . message )
140
+ end
141
+ end
142
+
143
+ def test_batch_exception_in_failed_transaction
144
+ begin
145
+ Product . each_row_batch_by_sql ( "select * from products" ) do |r |
146
+ Product . connection . execute ( 'select kaboom' )
147
+ end
148
+ rescue Exception => e
149
+ assert_match ( /kaboom/ , e . message )
150
+ end
151
+ end
152
+
133
153
def test_cursor
134
154
cursor = Product . all . each_row
135
155
assert cursor . respond_to? ( :each )
You can’t perform that action at this time.
0 commit comments