Skip to content

Commit

Permalink
Merge pull request #86 from ozeias/master
Browse files Browse the repository at this point in the history
Supporting nested AR transactions
  • Loading branch information
alto committed Aug 27, 2013
2 parents db1460c + 7c57783 commit 44513ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/aasm/persistence/active_record_persistence.rb
Expand Up @@ -132,7 +132,7 @@ def aasm_ensure_initial_state
end

def aasm_fire_event(name, options, *args)
transaction do
transaction(:requires_new => true) do
super
end
end
Expand Down
18 changes: 15 additions & 3 deletions spec/unit/persistence/active_record_persistence_spec.rb
Expand Up @@ -179,16 +179,28 @@
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'

lambda {transactor.run!}.should raise_error(StandardError, 'failed on purpose')
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

0 comments on commit 44513ee

Please sign in to comment.