From b4d758eb20b2e6494848adc2605ba53cfffbeba8 Mon Sep 17 00:00:00 2001 From: Daniel Wakefield Date: Fri, 8 Feb 2019 18:04:07 +0000 Subject: [PATCH 1/2] Add test for after_commit's transactional integrity. --- .../adapters/active_record_queries_spec.rb | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/spec/statesman/adapters/active_record_queries_spec.rb b/spec/statesman/adapters/active_record_queries_spec.rb index 79b0abc0..9588269e 100644 --- a/spec/statesman/adapters/active_record_queries_spec.rb +++ b/spec/statesman/adapters/active_record_queries_spec.rb @@ -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 From a020d43810be335a36444dca2677cce545934279 Mon Sep 17 00:00:00 2001 From: Daniel Wakefield Date: Fri, 22 Feb 2019 12:04:49 +0000 Subject: [PATCH 2/2] Bump major version for releasing transaction based changes --- CHANGELOG.md | 6 ++++++ lib/statesman/version.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2731f83e..fbc16707 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/statesman/version.rb b/lib/statesman/version.rb index b2662919..52ec6b8a 100644 --- a/lib/statesman/version.rb +++ b/lib/statesman/version.rb @@ -1,3 +1,3 @@ module Statesman - VERSION = "3.5.0".freeze + VERSION = "4.0.0".freeze end