Skip to content

Handle the case where the cache is empty #508

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

Merged
merged 2 commits into from
Apr 3, 2023
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
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