|
28 | 28 | end |
29 | 29 |
|
30 | 30 | context "within transaction" do |
31 | | - context 'when prepend is true' do |
32 | | - let(:handler_1) { spy("handler_1") } |
33 | | - let(:handler_2) { spy("handler_2") } |
| 31 | + let(:handler_1) { spy("handler_1") } |
| 32 | + let(:handler_2) { spy("handler_2") } |
34 | 33 |
|
| 34 | + context 'when prepend is true' do |
35 | 35 | it 'executes prepended callback first' do |
36 | 36 | ActiveRecord::Base.transaction do |
37 | 37 | example_class.new.after_commit { handler_1.call } |
|
54 | 54 | end |
55 | 55 |
|
56 | 56 | context 'when prepend is not specified' do |
57 | | - let(:handler_1) { spy("handler_1") } |
58 | | - let(:handler_2) { spy("handler_2") } |
59 | | - |
60 | 57 | it 'executes callbacks in the order they were defined' do |
61 | 58 | ActiveRecord::Base.transaction do |
62 | 59 | example_class.new.after_commit { handler_1.call } |
|
99 | 96 | expect(handler).to have_received(:call) |
100 | 97 | end |
101 | 98 | end |
| 99 | + |
| 100 | + it 'propagates an error raised in one of multiple callbacks' do |
| 101 | + expect do |
| 102 | + ActiveRecord::Base.transaction do |
| 103 | + example_class.new.after_commit { raise 'this should prevent other callbacks being executed' } |
| 104 | + example_class.new.after_commit { handler_1.call } |
| 105 | + example_class.new.after_commit { handler_2.call } |
| 106 | + end |
| 107 | + end.to raise_error('this should prevent other callbacks being executed') |
| 108 | + expect(handler_1).not_to have_received(:call) |
| 109 | + expect(handler_2).not_to have_received(:call) |
| 110 | + end |
102 | 111 | end |
103 | 112 |
|
104 | 113 | context "without transaction" do |
|
0 commit comments