Skip to content

Commit 3101b07

Browse files
authored
Merge pull request #508 from gocardless/vsavin/fix-reset-for-empty-cache
Handle the case where the cache is empty
2 parents da1996d + 4060a54 commit 3101b07

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## v10.2.1 3rd April 2023
2+
3+
### Changed
4+
- Fixed an edge case where `adapter.reset` were failing if the cache is empty
5+
16
## v10.2.0 3rd April 2023
27

38
### Changed

lib/statesman/adapters/active_record.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def create(from, to, metadata = {})
5252

5353
raise
5454
ensure
55-
remove_instance_variable(:@last_transition)
55+
reset
5656
end
5757

5858
def history(force_reload: false)
@@ -76,7 +76,8 @@ def last(force_reload: false)
7676
end
7777

7878
def reset
79-
remove_instance_variable(:@last_transition)
79+
remove_instance_variable(:@last_transition) \
80+
if instance_variable_defined?(:@last_transition)
8081
end
8182

8283
private

lib/statesman/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Statesman
4-
VERSION = "10.2.0"
4+
VERSION = "10.2.1"
55
end

spec/statesman/adapters/active_record_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,12 @@
388388
end
389389
end
390390

391+
describe "#reset" do
392+
it "works with empty cache" do
393+
expect { model.state_machine.reset }.to_not raise_error
394+
end
395+
end
396+
391397
it "resets last with #reload" do
392398
model.save!
393399
ActiveRecord::Base.transaction do

0 commit comments

Comments
 (0)