Skip to content

Commit

Permalink
Merge pull request #508 from gocardless/vsavin/fix-reset-for-empty-cache
Browse files Browse the repository at this point in the history
Handle the case where the cache is empty
  • Loading branch information
zerc committed Apr 3, 2023
2 parents da1996d + 4060a54 commit 3101b07
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/statesman/adapters/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def create(from, to, metadata = {})

raise
ensure
remove_instance_variable(:@last_transition)
reset
end

def history(force_reload: false)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/statesman/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Statesman
VERSION = "10.2.0"
VERSION = "10.2.1"
end
6 changes: 6 additions & 0 deletions spec/statesman/adapters/active_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3101b07

Please sign in to comment.