diff --git a/CHANGELOG.md b/CHANGELOG.md index ecbb4eeb..408c0d0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v10.2.1 3rd April 2023 + +### Changed +- Fixed an edge case where `adapter.reset` were failing if the cache is empty + ## v10.2.0 3rd April 2023 ### Changed diff --git a/lib/statesman/adapters/active_record.rb b/lib/statesman/adapters/active_record.rb index 5847bd9a..72c9a8c6 100644 --- a/lib/statesman/adapters/active_record.rb +++ b/lib/statesman/adapters/active_record.rb @@ -52,7 +52,7 @@ def create(from, to, metadata = {}) raise ensure - remove_instance_variable(:@last_transition) + reset end def history(force_reload: false) @@ -76,7 +76,8 @@ def last(force_reload: false) end def reset - remove_instance_variable(:@last_transition) + remove_instance_variable(:@last_transition) \ + if instance_variable_defined?(:@last_transition) end private diff --git a/lib/statesman/version.rb b/lib/statesman/version.rb index 43678dd0..f7795584 100644 --- a/lib/statesman/version.rb +++ b/lib/statesman/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Statesman - VERSION = "10.2.0" + VERSION = "10.2.1" end diff --git a/spec/statesman/adapters/active_record_spec.rb b/spec/statesman/adapters/active_record_spec.rb index 0b155536..6300d376 100644 --- a/spec/statesman/adapters/active_record_spec.rb +++ b/spec/statesman/adapters/active_record_spec.rb @@ -388,6 +388,12 @@ end end + describe "#reset" do + it "works with empty cache" do + expect { model.state_machine.reset }.to_not raise_error + end + end + it "resets last with #reload" do model.save! ActiveRecord::Base.transaction do