aasm 4.1.0 → 4.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile +0 -1
- data/README.md +1 -1
- data/aasm.gemspec +0 -4
- data/gemfiles/rails_3.2.gemfile +0 -1
- data/gemfiles/rails_4.0.gemfile +0 -1
- data/gemfiles/rails_4.1.gemfile +0 -1
- data/gemfiles/rails_4.2.gemfile +0 -1
- data/lib/aasm/aasm.rb +13 -7
- data/lib/aasm/core/event.rb +1 -1
- data/lib/aasm/core/state.rb +8 -6
- data/lib/aasm/errors.rb +12 -1
- data/lib/aasm/persistence/active_record_persistence.rb +1 -1
- data/lib/aasm/persistence/sequel_persistence.rb +1 -0
- data/lib/aasm/version.rb +1 -1
- data/spec/models/callbacks/with_args.rb +9 -9
- data/spec/models/validator.rb +8 -0
- data/spec/spec_helper.rb +0 -3
- data/spec/unit/callbacks_spec.rb +1 -1
- data/spec/unit/persistence/active_record_persistence_spec.rb +6 -1
- data/spec/unit/persistence/sequel_persistence_spec.rb +13 -0
- data/spec/unit/transition_spec.rb +6 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e85a2c10a3cf49a548193c9634548eb38eb1578b
|
4
|
+
data.tar.gz: 9b87e33663caa939dbf4eeefad57ea6ebde01fac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e2b255e2cae2cfae4a13c14ef8bd89f20c132ae5acf8260e68319f40646008304f05870e5cfbb2e4402b7cedc588552b777407c613b30f7e8b1787b9eac8faf
|
7
|
+
data.tar.gz: 41843dcb1cfa5c1147abea4420951ae3217349abd7a7918a1ef0014671218a520957c61d2d7f70ae5634514df5722466e83deb64549b463a5d3d51a323049da3
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
## 4.2.0 (not yet released)
|
4
4
|
|
5
|
+
## 4.1.1
|
6
|
+
|
7
|
+
* support block notation for `:after_commit` event callbacks (see [issue #224](https://github.com/aasm/aasm/issues/224) for details)
|
8
|
+
* event arguments are now passed to state callbacks as well (not only to event callbacks) (see [issue #219](https://github.com/aasm/aasm/issues/219), thanks to [@tobithiel](https://github.com/tobithiel))
|
9
|
+
* `AASM::InvalidTransition` now references the current object (with the state machine) and the _AASM_ event name (see [issue #217](https://github.com/aasm/aasm/issues/217), thanks to [@awsmsrc](https://github.com/awsmsrc))
|
10
|
+
* bugfix: do not update unloaded state for [Sequel](http://sequel.jeremyevans.net/) (see [issue #218](https://github.com/aasm/aasm/issues/218), thanks to [@godfat](https://github.com/godfat))
|
11
|
+
|
5
12
|
## 4.1.0
|
6
13
|
|
7
14
|
* bugfix: initialize the aasm state column after initialization of the _Mongoid_ instance (see [issue #206](https://github.com/aasm/aasm/issues/206), thanks to [@Shwetakale ](https://github.com/Shwetakale ))
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/aasm.svg)](http://badge.fury.io/rb/aasm)
|
4
4
|
[![Build Status](https://travis-ci.org/aasm/aasm.svg?branch=master)](https://travis-ci.org/aasm/aasm)
|
5
|
+
[![Dependency Status](https://gemnasium.com/aasm/aasm.svg)](https://gemnasium.com/aasm/aasm)
|
5
6
|
[![Code Climate](https://codeclimate.com/github/aasm/aasm/badges/gpa.svg)](https://codeclimate.com/github/aasm/aasm)
|
6
|
-
[![Coverage Status](https://img.shields.io/coveralls/aasm/aasm.svg)](https://coveralls.io/r/aasm/aasm?branch=master)
|
7
7
|
|
8
8
|
This package contains AASM, a library for adding finite state machines to Ruby classes.
|
9
9
|
|
data/aasm.gemspec
CHANGED
@@ -24,10 +24,6 @@ Gem::Specification.new do |s|
|
|
24
24
|
# s.add_development_dependency 'debugger'
|
25
25
|
s.add_development_dependency 'pry'
|
26
26
|
|
27
|
-
# test coverage
|
28
|
-
# s.add_development_dependency 'mime-types', '~> 1.25' # needed by coveralls (>= 2.0 needs Ruby >=1.9.2)
|
29
|
-
# s.add_development_dependency 'coveralls'
|
30
|
-
|
31
27
|
s.files = `git ls-files`.split("\n")
|
32
28
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
33
29
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
data/gemfiles/rails_3.2.gemfile
CHANGED
data/gemfiles/rails_4.0.gemfile
CHANGED
data/gemfiles/rails_4.1.gemfile
CHANGED
data/gemfiles/rails_4.2.gemfile
CHANGED
data/lib/aasm/aasm.rb
CHANGED
@@ -69,8 +69,10 @@ private
|
|
69
69
|
)
|
70
70
|
|
71
71
|
if may_fire_to = event.may_fire?(self, *args)
|
72
|
-
old_state.fire_callbacks(:before_exit, self
|
73
|
-
|
72
|
+
old_state.fire_callbacks(:before_exit, self,
|
73
|
+
*process_args(event, aasm.current_state, *args))
|
74
|
+
old_state.fire_callbacks(:exit, self,
|
75
|
+
*process_args(event, aasm.current_state, *args)) # TODO: remove for AASM 4?
|
74
76
|
|
75
77
|
if new_state_name = event.fire(self, {:may_fire => may_fire_to}, *args)
|
76
78
|
aasm_fired(event, old_state, new_state_name, options, *args, &block)
|
@@ -90,9 +92,11 @@ private
|
|
90
92
|
|
91
93
|
new_state = aasm.state_object_for_name(new_state_name)
|
92
94
|
|
93
|
-
new_state.fire_callbacks(:before_enter, self
|
95
|
+
new_state.fire_callbacks(:before_enter, self,
|
96
|
+
*process_args(event, aasm.current_state, *args))
|
94
97
|
|
95
|
-
new_state.fire_callbacks(:enter, self
|
98
|
+
new_state.fire_callbacks(:enter, self,
|
99
|
+
*process_args(event, aasm.current_state, *args)) # TODO: remove for AASM 4?
|
96
100
|
|
97
101
|
persist_successful = true
|
98
102
|
if persist
|
@@ -107,8 +111,10 @@ private
|
|
107
111
|
end
|
108
112
|
|
109
113
|
if persist_successful
|
110
|
-
old_state.fire_callbacks(:after_exit, self
|
111
|
-
|
114
|
+
old_state.fire_callbacks(:after_exit, self,
|
115
|
+
*process_args(event, aasm.current_state, *args))
|
116
|
+
new_state.fire_callbacks(:after_enter, self,
|
117
|
+
*process_args(event, aasm.current_state, *args))
|
112
118
|
event.fire_callbacks(
|
113
119
|
:after,
|
114
120
|
self,
|
@@ -129,7 +135,7 @@ private
|
|
129
135
|
end
|
130
136
|
|
131
137
|
if AASM::StateMachine[self.class].config.whiny_transitions
|
132
|
-
raise AASM::InvalidTransition,
|
138
|
+
raise AASM::InvalidTransition.new(self, event_name)
|
133
139
|
else
|
134
140
|
false
|
135
141
|
end
|
data/lib/aasm/core/event.rb
CHANGED
@@ -12,7 +12,7 @@ module AASM::Core
|
|
12
12
|
|
13
13
|
# from aasm4
|
14
14
|
@options = options # QUESTION: .dup ?
|
15
|
-
add_options_from_dsl(@options, [:after, :before, :error, :success], &block) if block
|
15
|
+
add_options_from_dsl(@options, [:after, :before, :error, :success, :after_commit], &block) if block
|
16
16
|
end
|
17
17
|
|
18
18
|
# a neutered version of fire - it doesn't actually fire the event, it just
|
data/lib/aasm/core/state.rb
CHANGED
@@ -28,12 +28,12 @@ module AASM::Core
|
|
28
28
|
name.to_s
|
29
29
|
end
|
30
30
|
|
31
|
-
def fire_callbacks(action, record)
|
31
|
+
def fire_callbacks(action, record, *args)
|
32
32
|
action = @options[action]
|
33
33
|
catch :halt_aasm_chain do
|
34
34
|
action.is_a?(Array) ?
|
35
|
-
action.each {|a| _fire_callbacks(a, record)} :
|
36
|
-
_fire_callbacks(action, record)
|
35
|
+
action.each {|a| _fire_callbacks(a, record, args)} :
|
36
|
+
_fire_callbacks(action, record, args)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -66,12 +66,14 @@ module AASM::Core
|
|
66
66
|
self
|
67
67
|
end
|
68
68
|
|
69
|
-
def _fire_callbacks(action, record)
|
69
|
+
def _fire_callbacks(action, record, args)
|
70
70
|
case action
|
71
71
|
when Symbol, String
|
72
|
-
record.send(action)
|
72
|
+
arity = record.send(:method, action.to_sym).arity
|
73
|
+
record.send(action, *(arity < 0 ? args : args[0...arity]))
|
73
74
|
when Proc
|
74
|
-
action.
|
75
|
+
arity = action.arity
|
76
|
+
action.call(record, *(arity < 0 ? args : args[0...arity]))
|
75
77
|
end
|
76
78
|
end
|
77
79
|
|
data/lib/aasm/errors.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
module AASM
|
2
|
-
|
2
|
+
|
3
|
+
class InvalidTransition < RuntimeError
|
4
|
+
attr_reader :object, :event_name
|
5
|
+
def initialize(object, event_name)
|
6
|
+
@object, @event_name = object, event_name
|
7
|
+
end
|
8
|
+
|
9
|
+
def message
|
10
|
+
"Event '#{event_name}' cannot transition from '#{object.aasm.current_state}'"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
3
14
|
class UndefinedState < RuntimeError; end
|
4
15
|
class NoDirectAssignmentError < RuntimeError; end
|
5
16
|
end
|
@@ -187,7 +187,7 @@ module AASM
|
|
187
187
|
end
|
188
188
|
|
189
189
|
def aasm_validate_states
|
190
|
-
unless
|
190
|
+
unless aasm_skipping_validations
|
191
191
|
if aasm.current_state && !aasm.states.include?(aasm.current_state)
|
192
192
|
self.errors.add(AASM::StateMachine[self.class].config.column , "is invalid")
|
193
193
|
end
|
data/lib/aasm/version.rb
CHANGED
@@ -44,15 +44,15 @@ module Callbacks
|
|
44
44
|
|
45
45
|
def aasm_write_state(*args); log('aasm_write_state'); true; end
|
46
46
|
|
47
|
-
def before_enter_open; log(
|
48
|
-
def before_exit_open; log(
|
49
|
-
def after_enter_open; log(
|
50
|
-
def after_exit_open; log(
|
51
|
-
|
52
|
-
def before_enter_closed; log(
|
53
|
-
def before_exit_closed; log(
|
54
|
-
def after_enter_closed; log(
|
55
|
-
def after_exit_closed; log(
|
47
|
+
def before_enter_open(*args); log("before_enter_open(#{args.map(&:inspect).join(',')})"); end
|
48
|
+
def before_exit_open(*args); log("before_exit_open(#{args.map(&:inspect).join(',')})"); end
|
49
|
+
def after_enter_open(*args); log("after_enter_open(#{args.map(&:inspect).join(',')})"); end
|
50
|
+
def after_exit_open(*args); log("after_exit_open(#{args.map(&:inspect).join(',')})"); end
|
51
|
+
|
52
|
+
def before_enter_closed(*args); log("before_enter_closed(#{args.map(&:inspect).join(',')})"); end
|
53
|
+
def before_exit_closed(*args); log("before_enter_closed(#{args.map(&:inspect).join(',')})"); end
|
54
|
+
def after_enter_closed(*args); log("after_enter_closed(#{args.map(&:inspect).join(',')})"); end
|
55
|
+
def after_exit_closed(*args); log("after_exit_closed(#{args.map(&:inspect).join(',')})"); end
|
56
56
|
|
57
57
|
def before(arg1, *args); log("before(#{arg1.inspect},#{args.map(&:inspect).join(',')})"); end
|
58
58
|
def transition_proc(arg1, arg2); log("transition_proc(#{arg1.inspect},#{arg2.inspect})"); end
|
data/spec/models/validator.rb
CHANGED
@@ -12,6 +12,9 @@ class Validator < ActiveRecord::Base
|
|
12
12
|
transitions :to => :running, :from => :sleeping
|
13
13
|
end
|
14
14
|
event :sleep do
|
15
|
+
after_commit do
|
16
|
+
change_name_on_sleep
|
17
|
+
end
|
15
18
|
transitions :to => :sleeping, :from => :running
|
16
19
|
end
|
17
20
|
event :fail do
|
@@ -26,6 +29,11 @@ class Validator < ActiveRecord::Base
|
|
26
29
|
save!
|
27
30
|
end
|
28
31
|
|
32
|
+
def change_name_on_sleep
|
33
|
+
self.name = "sleeper"
|
34
|
+
save!
|
35
|
+
end
|
36
|
+
|
29
37
|
def fail
|
30
38
|
raise StandardError.new('failed on purpose')
|
31
39
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/unit/callbacks_spec.rb
CHANGED
@@ -145,7 +145,7 @@ describe 'callbacks for the new DSL' do
|
|
145
145
|
|
146
146
|
cb.reset_data
|
147
147
|
cb.close!(:arg1, :arg2)
|
148
|
-
expect(cb.data).to eql 'before(:arg1,:arg2) before_exit_open transition_proc(:arg1,:arg2) before_enter_closed aasm_write_state after_exit_open after_enter_closed after(:arg1,:arg2)'
|
148
|
+
expect(cb.data).to eql 'before(:arg1,:arg2) before_exit_open(:arg1,:arg2) transition_proc(:arg1,:arg2) before_enter_closed(:arg1,:arg2) aasm_write_state after_exit_open(:arg1,:arg2) after_enter_closed(:arg1,:arg2) after(:arg1,:arg2)'
|
149
149
|
end
|
150
150
|
|
151
151
|
it "should call the callbacks given the to-state as argument" do
|
@@ -431,9 +431,14 @@ describe 'transitions with persistence' do
|
|
431
431
|
it "should fire :after_commit if transaction was successful" do
|
432
432
|
validator = Validator.create(:name => 'name')
|
433
433
|
expect(validator).to be_sleeping
|
434
|
+
|
434
435
|
validator.run!
|
435
436
|
expect(validator).to be_running
|
436
|
-
expect(validator.name).
|
437
|
+
expect(validator.name).to eq("name changed")
|
438
|
+
|
439
|
+
validator.sleep!
|
440
|
+
expect(validator).to be_sleeping
|
441
|
+
expect(validator.name).to eq("sleeper")
|
437
442
|
end
|
438
443
|
|
439
444
|
it "should not fire :after_commit if transaction failed" do
|
@@ -44,6 +44,11 @@ describe 'sequel' do
|
|
44
44
|
expect(model.aasm.current_state).to eq(:alpha)
|
45
45
|
end
|
46
46
|
|
47
|
+
it "should save the initial state" do
|
48
|
+
model.save
|
49
|
+
expect(model.status).to eq("alpha")
|
50
|
+
end
|
51
|
+
|
47
52
|
it "should return the aasm column when new and the aasm field is not nil" do
|
48
53
|
model.status = "beta"
|
49
54
|
expect(model.aasm.current_state).to eq(:beta)
|
@@ -61,6 +66,14 @@ describe 'sequel' do
|
|
61
66
|
expect(model.aasm.current_state).to be_nil
|
62
67
|
end
|
63
68
|
|
69
|
+
it "should not change the state if state is not loaded" do
|
70
|
+
model.release
|
71
|
+
model.save
|
72
|
+
model.class.select(:id).first.save
|
73
|
+
model.reload
|
74
|
+
expect(model.aasm.current_state).to eq(:beta)
|
75
|
+
end
|
76
|
+
|
64
77
|
it "should call aasm_ensure_initial_state on validation before create" do
|
65
78
|
expect(model).to receive(:aasm_ensure_initial_state).and_return(true)
|
66
79
|
model.valid?
|
@@ -4,7 +4,12 @@ describe 'transitions' do
|
|
4
4
|
|
5
5
|
it 'should raise an exception when whiny' do
|
6
6
|
process = ProcessWithNewDsl.new
|
7
|
-
expect { process.stop! }.to raise_error
|
7
|
+
expect { process.stop! }.to raise_error do |err|
|
8
|
+
expect(err.class).to eql(AASM::InvalidTransition)
|
9
|
+
expect(err.message).to eql("Event 'stop' cannot transition from 'sleeping'")
|
10
|
+
expect(err.object).to eql(process)
|
11
|
+
expect(err.event_name).to eql(:stop)
|
12
|
+
end
|
8
13
|
expect(process).to be_sleeping
|
9
14
|
end
|
10
15
|
|
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: 4.1.
|
4
|
+
version: 4.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Barron
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-05-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|