Skip to content

Commit

Permalink
No longer creating transaction when not persisting
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Honer committed Aug 15, 2014
1 parent 3f4a6b1 commit 8725334
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/aasm/persistence/active_record_persistence.rb
Expand Up @@ -171,9 +171,7 @@ def aasm_ensure_initial_state
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)
Expand Down
17 changes: 17 additions & 0 deletions spec/unit/persistence/active_record_persistence_spec.rb
Expand Up @@ -447,6 +447,23 @@
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

Expand Down

0 comments on commit 8725334

Please sign in to comment.