aasm 5.3.0 → 5.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 442f7c145e97a545e9dd1cd5ecab268177b93deb0b258ab381107f1207fe9654
4
- data.tar.gz: 1d32640b0bfab501acc40b10f7d21be342944ed133086d44ccb924f03485f3b8
3
+ metadata.gz: 7ec8cfc1d821c4acb9bd0ce3f3af83174f28314f4f9c91f511d2a77555faf731
4
+ data.tar.gz: 8ed85be2d9cee794e3738349ba567667946b5df80ded58a5bd009d864b99fc02
5
5
  SHA512:
6
- metadata.gz: be33b17c558b289c012f25ccbed984cd3b2859e14a5120bf240020eb2d83c2645834784e5bc50dac0e5a3f161f13f3d85c2a29dcefcce694be395b604676ef32
7
- data.tar.gz: 87668c8a48a9cf0335a4359970e868758a25398e2af8fb025ab9dd39db2a89147f0fad25fee9c11e1da9522fbeca6595f5363318b8baf2b7625ee1b88f3d8b80
6
+ metadata.gz: 19ecf2a0254280ecbcacee23b7f671d4a5fefc5cc0bf4eabffd5fc98e1bff648b35048a201d4f60e22b6ca989ca03dd958f8ff558ee8c62c2662b83d994b9692
7
+ data.tar.gz: afe81dea0198b16bfbac59293625b1ab7aa94a62f1250511a7e03957d71724f52b1a01e5c01d48d3bf04c53013578a5ffae8859b9134212137b1aadd4285b894
@@ -56,6 +56,8 @@ jobs:
56
56
  gemfile: rails_4.2_mongoid_5
57
57
  - ruby: truffleruby
58
58
  gemfile: rails_5.2
59
+ - ruby: truffleruby
60
+ gemfile: rails_6.1
59
61
  allow_failures:
60
62
  - false
61
63
  env:
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
3
  ## unreleased
4
+ ## 5.3.1
5
+ * Fix fire! with string argument [#787](https://github.com/aasm/aasm/issues/787), in PR[#788](https://github.com/aasm/aasm/pull/788) thanks to [norman](https://github.com/norman)
6
+
7
+ * Allow `fire` and `fire!` to accept a String or Symbol for the event name, and raise AASM::UndefinedEvent rather than AASM::UndefinedState
8
+ when an event can not be found, thanks to [norman](https://github.com/norman).
4
9
 
5
10
  ## 5.3.0
6
11
 
data/lib/aasm/errors.rb CHANGED
@@ -17,5 +17,6 @@ module AASM
17
17
  end
18
18
 
19
19
  class UndefinedState < RuntimeError; end
20
+ class UndefinedEvent < UndefinedState; end
20
21
  class NoDirectAssignmentError < RuntimeError; end
21
22
  end
@@ -134,10 +134,11 @@ module AASM
134
134
  private
135
135
 
136
136
  def event_exists?(event_name, bang = false)
137
- event = @instance.class.aasm(@name).state_machine.events[event_name]
138
- event_error = bang ? "#{event_name}!" : event_name
137
+ event = @instance.class.aasm(@name).state_machine.events[event_name.to_sym]
138
+ return true if event
139
139
 
140
- raise AASM::UndefinedState, "State :#{event_error} doesn't exist" if event.nil?
140
+ event_error = bang ? "#{event_name}!" : event_name
141
+ raise AASM::UndefinedEvent, "Event :#{event_error} doesn't exist" if event.nil?
141
142
  end
142
143
  end
143
144
  end
data/lib/aasm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module AASM
2
- VERSION = "5.3.0"
2
+ VERSION = "5.3.1"
3
3
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  begin
4
4
  require 'mongoid'
5
+ require 'rails'
5
6
  puts "mongoid #{Mongoid::VERSION} gem found, running mongoid specs \e[32m#{'✔'}\e[0m"
6
7
 
7
8
  if Mongoid::VERSION.to_f <= 5
@@ -153,11 +153,11 @@ describe 'callbacks for the new DSL' do
153
153
 
154
154
  expect {
155
155
  callback.aasm.fire(:unknown)
156
- }.to raise_error(AASM::UndefinedState, "State :unknown doesn't exist")
156
+ }.to raise_error(AASM::UndefinedEvent, "Event :unknown doesn't exist")
157
157
 
158
158
  expect {
159
159
  callback.aasm.fire!(:unknown)
160
- }.to raise_error(AASM::UndefinedState, "State :unknown! doesn't exist")
160
+ }.to raise_error(AASM::UndefinedEvent, "Event :unknown! doesn't exist")
161
161
  end
162
162
 
163
163
  it "does not run any state callback if the event guard fails" do
@@ -92,10 +92,10 @@ describe 'when being unsuspended' do
92
92
  end
93
93
 
94
94
  it "should raise AASM::UndefinedState when firing unknown events" do
95
- expect { auth.aasm.fire(:unknown) }.to raise_error(AASM::UndefinedState, "State :unknown doesn't exist")
95
+ expect { auth.aasm.fire(:unknown) }.to raise_error(AASM::UndefinedEvent, "Event :unknown doesn't exist")
96
96
  end
97
97
 
98
98
  it "should raise AASM::UndefinedState when firing unknown bang events" do
99
- expect { auth.aasm.fire!(:unknown) }.to raise_error(AASM::UndefinedState, "State :unknown! doesn't exist")
99
+ expect { auth.aasm.fire!(:unknown) }.to raise_error(AASM::UndefinedEvent, "Event :unknown! doesn't exist")
100
100
  end
101
101
  end
@@ -296,15 +296,32 @@ describe 'current event' do
296
296
  end
297
297
 
298
298
  describe "when calling events with fire/fire!" do
299
- it "fire should populate aasm.current_event and transition (sleeping to showering)" do
300
- pe.aasm.fire(:wakeup)
301
- expect(pe.aasm.current_event).to eq :wakeup
302
- expect(pe.aasm.current_state).to eq :showering
299
+ context "fire" do
300
+ it "should populate aasm.current_event and transition (sleeping to showering)" do
301
+ pe.aasm.fire(:wakeup)
302
+ expect(pe.aasm.current_event).to eq :wakeup
303
+ expect(pe.aasm.current_state).to eq :showering
304
+ end
305
+
306
+ it "should allow event names as strings" do
307
+ pe.aasm.fire("wakeup")
308
+ expect(pe.aasm.current_event).to eq :wakeup
309
+ expect(pe.aasm.current_state).to eq :showering
310
+ end
303
311
  end
304
- it "fire! should populate aasm.current_event and transition (sleeping to showering)" do
305
- pe.aasm.fire!(:wakeup)
306
- expect(pe.aasm.current_event).to eq :wakeup!
307
- expect(pe.aasm.current_state).to eq :showering
312
+
313
+ context "fire!" do
314
+ it "should populate aasm.current_event and transition (sleeping to showering)" do
315
+ pe.aasm.fire!(:wakeup)
316
+ expect(pe.aasm.current_event).to eq :wakeup!
317
+ expect(pe.aasm.current_state).to eq :showering
318
+ end
319
+
320
+ it "should allow event names as strings" do
321
+ pe.aasm.fire!("wakeup")
322
+ expect(pe.aasm.current_event).to eq :wakeup!
323
+ expect(pe.aasm.current_state).to eq :showering
324
+ end
308
325
  end
309
326
  end
310
327
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.0
4
+ version: 5.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thorsten Boettger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-07-22 00:00:00.000000000 Z
12
+ date: 2022-09-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby