mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
No longer creating transaction when not persisting
This commit is contained in:
parent
3f4a6b1a0b
commit
8725334370
2 changed files with 18 additions and 3 deletions
|
@ -171,9 +171,7 @@ module AASM
|
|||
end
|
||||
|
||||
def aasm_fire_event(name, options, *args, &block)
|
||||
success = self.class.transaction(:requires_new => requires_new?) do
|
||||
super
|
||||
end
|
||||
success = options[:persist] ? self.class.transaction(:requires_new => requires_new?) { super } : super
|
||||
|
||||
if success && options[:persist]
|
||||
new_state = aasm.state_object_for_name(aasm.current_state)
|
||||
|
|
|
@ -447,6 +447,23 @@ describe 'transitions with persistence' do
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
context "when not persisting" do
|
||||
it 'should not rollback all changes' do
|
||||
expect(transactor).to be_sleeping
|
||||
expect(worker.status).to eq('sleeping')
|
||||
|
||||
# Notice here we're calling "run" and not "run!" with a bang.
|
||||
expect {transactor.run}.to raise_error(StandardError, 'failed on purpose')
|
||||
expect(transactor).to be_running
|
||||
expect(worker.reload.status).to eq('running')
|
||||
end
|
||||
|
||||
it 'should not create a database transaction' do
|
||||
expect(transactor.class).not_to receive(:transaction)
|
||||
expect {transactor.run}.to raise_error(StandardError, 'failed on purpose')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue