spec/routine_spec.rb in lev-6.0.0 vs spec/routine_spec.rb in lev-7.0.0
- old
+ new
@@ -114,6 +114,43 @@
expect(e.message).to eq('code broken - such disaster - kind lev')
end
end
end
+ it 'does not mess up results on a transaction retry' do
+ # To get the transaction to retry, we need to raise an exception the first time
+ # through execution, after an output has been set in a nested routine and
+ # translated to the parent routine
+
+ stub_const 'NestedRoutine', Class.new
+ NestedRoutine.class_eval {
+ lev_routine
+ def exec
+ outputs[:test] = 1
+ end
+ }
+
+ stub_const 'MainRoutine', Class.new
+ MainRoutine.class_eval {
+ lev_routine
+ uses_routine NestedRoutine,
+ translations: {outputs: {type: :verbatim}}
+
+ def exec
+ run(NestedRoutine)
+
+ @times_called ||= 0
+ @times_called += 1
+ raise(::ActiveRecord::TransactionIsolationConflict, 'hi') if @times_called == 1
+ end
+ }
+
+ # In reality, the Lev routine is the top-level transaction, but rspec has its own
+ # transactions at the top, so we have to fake that the Lev routine transaction
+ # is at the top.
+ allow(ActiveRecord::Base).to receive(:tr_in_nested_transaction?) { false }
+
+ results = MainRoutine.call
+ expect(results.outputs.test).to eq 1
+ end
+
end