Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer creating transaction when not persisting #164

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/aasm/persistence/active_record_persistence.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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