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

Test after_commit transactional integrity. #341

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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v4.0.0, 22 February 2019

- Forces Statesman to use a new transactions with `requires_new: true` (https://github.com/gocardless/statesman/pull/249)
- Fixes an issue with `after_commit` transition blocks that where being
executed even if the transaction rolled back. ([patch](https://github.com/gocardless/statesman/pull/338) by [@matid](https://github.com/matid))

## v3.5.0, 2 November 2018

- Expose `most_recent_transition_join` - ActiveRecords `or` requires that both
Expand Down
2 changes: 1 addition & 1 deletion lib/statesman/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Statesman
VERSION = "3.5.0".freeze
VERSION = "4.0.0".freeze
end
34 changes: 34 additions & 0 deletions spec/statesman/adapters/active_record_queries_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,38 @@ def self.transition_class
end
end
end

context "after_commit transactional integrity" do
before do
MyStateMachine.class_eval do
cattr_accessor(:after_commit_callback_executed) { false }

after_transition(from: :initial, to: :succeeded, after_commit: true) do
# This leaks state in a testable way if transactional integrity is broken.
MyStateMachine.after_commit_callback_executed = true
end
end
end

after do
MyStateMachine.class_eval do
callbacks[:after_commit] = []
end
end

let!(:model) do
MyActiveRecordModel.create
end

# rubocop:disable RSpec/ExampleLength
it do
expect do
ActiveRecord::Base.transaction do
model.state_machine.transition_to!(:succeeded)
raise ActiveRecord::Rollback
end
end.to_not change(MyStateMachine, :after_commit_callback_executed)
end
# rubocop:enable RSpec/ExampleLength
end
end