mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
supporting nested AR transactions
This commit is contained in:
parent
db1460c495
commit
91a90c9233
2 changed files with 16 additions and 4 deletions
|
@ -132,7 +132,7 @@ module AASM
|
|||
end
|
||||
|
||||
def aasm_fire_event(name, options, *args)
|
||||
transaction do
|
||||
transaction(requires_new: true) do
|
||||
super
|
||||
end
|
||||
end
|
||||
|
|
|
@ -179,9 +179,10 @@ describe 'transitions with persistence' do
|
|||
end
|
||||
|
||||
describe 'transactions' do
|
||||
let(:worker) { Worker.create!(:name => 'worker', :status => 'sleeping') }
|
||||
let(:transactor) { Transactor.create!(:name => 'transactor', :worker => worker) }
|
||||
|
||||
it 'should rollback all changes' do
|
||||
worker = Worker.create!(:name => 'worker', :status => 'sleeping')
|
||||
transactor = Transactor.create!(:name => 'transactor', :worker => worker)
|
||||
transactor.should be_sleeping
|
||||
worker.status.should == 'sleeping'
|
||||
|
||||
|
@ -189,6 +190,17 @@ describe 'transitions with persistence' do
|
|||
transactor.should be_running
|
||||
worker.reload.status.should == 'sleeping'
|
||||
end
|
||||
end
|
||||
|
||||
it "should rollback all changes in nested transaction" do
|
||||
transactor.should be_sleeping
|
||||
worker.status.should == 'sleeping'
|
||||
|
||||
Worker.transaction do
|
||||
lambda { transactor.run! }.should raise_error(StandardError, 'failed on purpose')
|
||||
end
|
||||
|
||||
transactor.should be_running
|
||||
worker.reload.status.should == 'sleeping'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue