Skip to content

Commit

Permalink
Merge pull request #341 from gocardless/danw/i-dont-want-to-install-m…
Browse files Browse the repository at this point in the history
…ysql-so-run-my-tests-here

Test after_commit transactional integrity.
  • Loading branch information
danwakefield authored Feb 22, 2019
2 parents b71dd1a + a020d43 commit f79357b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
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

0 comments on commit f79357b

Please sign in to comment.