aasm 4.12.3 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/ISSUE_TEMPLATE/bug_report.md +27 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.travis.yml +48 -18
- data/Appraisals +50 -26
- data/CHANGELOG.md +75 -3
- data/Dockerfile +44 -0
- data/Gemfile +2 -3
- data/README.md +216 -110
- data/aasm.gemspec +2 -0
- data/docker-compose.yml +40 -0
- data/gemfiles/norails.gemfile +10 -0
- data/gemfiles/rails_4.2.gemfile +9 -8
- data/gemfiles/rails_4.2_mongoid_5.gemfile +6 -5
- data/gemfiles/rails_4.2_nobrainer.gemfile +9 -0
- data/gemfiles/rails_5.0.gemfile +6 -6
- data/gemfiles/rails_5.0_nobrainer.gemfile +9 -0
- data/gemfiles/rails_5.1.gemfile +14 -0
- data/gemfiles/rails_5.2.gemfile +14 -0
- data/lib/aasm.rb +5 -2
- data/lib/aasm/aasm.rb +30 -27
- data/lib/aasm/base.rb +25 -7
- data/lib/aasm/core/event.rb +14 -24
- data/lib/aasm/core/invoker.rb +129 -0
- data/lib/aasm/core/invokers/base_invoker.rb +75 -0
- data/lib/aasm/core/invokers/class_invoker.rb +52 -0
- data/lib/aasm/core/invokers/literal_invoker.rb +47 -0
- data/lib/aasm/core/invokers/proc_invoker.rb +59 -0
- data/lib/aasm/core/state.rb +10 -9
- data/lib/aasm/core/transition.rb +7 -68
- data/lib/aasm/errors.rb +4 -3
- data/lib/aasm/instance_base.rb +16 -4
- data/lib/aasm/persistence.rb +3 -0
- data/lib/aasm/persistence/active_record_persistence.rb +25 -5
- data/lib/aasm/persistence/base.rb +1 -1
- data/lib/aasm/persistence/core_data_query_persistence.rb +2 -1
- data/lib/aasm/persistence/dynamoid_persistence.rb +1 -1
- data/lib/aasm/persistence/mongoid_persistence.rb +1 -1
- data/lib/aasm/persistence/no_brainer_persistence.rb +105 -0
- data/lib/aasm/persistence/orm.rb +23 -19
- data/lib/aasm/persistence/plain_persistence.rb +2 -1
- data/lib/aasm/persistence/redis_persistence.rb +1 -1
- data/lib/aasm/persistence/sequel_persistence.rb +0 -1
- data/lib/aasm/rspec/allow_event.rb +5 -1
- data/lib/aasm/rspec/allow_transition_to.rb +5 -1
- data/lib/aasm/rspec/transition_from.rb +5 -1
- data/lib/aasm/version.rb +1 -1
- data/lib/generators/aasm/orm_helpers.rb +6 -0
- data/lib/generators/active_record/aasm_generator.rb +3 -1
- data/lib/generators/nobrainer/aasm_generator.rb +28 -0
- data/lib/motion-aasm.rb +1 -0
- data/spec/database.rb +16 -1
- data/spec/en.yml +0 -3
- data/spec/generators/active_record_generator_spec.rb +6 -0
- data/spec/generators/no_brainer_generator_spec.rb +29 -0
- data/spec/{en_deprecated_style.yml → localizer_test_model_deprecated_style.yml} +0 -4
- data/spec/localizer_test_model_new_style.yml +5 -0
- data/spec/models/active_record/active_record_callback.rb +93 -0
- data/spec/models/active_record/instance_level_skip_validation_example.rb +19 -0
- data/spec/models/active_record/localizer_test_model.rb +3 -3
- data/spec/models/active_record/person.rb +23 -0
- data/spec/models/active_record/simple_new_dsl.rb +15 -0
- data/spec/models/active_record/work.rb +3 -0
- data/spec/models/callbacks/with_state_arg.rb +5 -1
- data/spec/models/callbacks/with_state_arg_multiple.rb +4 -1
- data/spec/models/default_state.rb +1 -1
- data/spec/models/nobrainer/complex_no_brainer_example.rb +36 -0
- data/spec/models/nobrainer/invalid_persistor_no_brainer.rb +39 -0
- data/spec/models/nobrainer/no_scope_no_brainer.rb +21 -0
- data/spec/models/nobrainer/nobrainer_relationships.rb +25 -0
- data/spec/models/nobrainer/silent_persistor_no_brainer.rb +39 -0
- data/spec/models/nobrainer/simple_new_dsl_nobrainer.rb +25 -0
- data/spec/models/nobrainer/simple_no_brainer.rb +23 -0
- data/spec/models/nobrainer/validator_no_brainer.rb +98 -0
- data/spec/models/simple_example.rb +8 -0
- data/spec/models/simple_example_with_guard_args.rb +17 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/spec_helpers/active_record.rb +2 -1
- data/spec/spec_helpers/dynamoid.rb +7 -5
- data/spec/spec_helpers/mongoid.rb +20 -1
- data/spec/spec_helpers/nobrainer.rb +15 -0
- data/spec/spec_helpers/redis.rb +5 -2
- data/spec/spec_helpers/sequel.rb +1 -1
- data/spec/unit/abstract_class_spec.rb +27 -0
- data/spec/unit/api_spec.rb +4 -0
- data/spec/unit/callback_multiple_spec.rb +7 -3
- data/spec/unit/callbacks_spec.rb +32 -2
- data/spec/unit/complex_example_spec.rb +0 -1
- data/spec/unit/event_spec.rb +13 -0
- data/spec/unit/exception_spec.rb +1 -1
- data/spec/unit/inspection_multiple_spec.rb +9 -5
- data/spec/unit/inspection_spec.rb +7 -3
- data/spec/unit/invoker_spec.rb +189 -0
- data/spec/unit/invokers/base_invoker_spec.rb +72 -0
- data/spec/unit/invokers/class_invoker_spec.rb +95 -0
- data/spec/unit/invokers/literal_invoker_spec.rb +86 -0
- data/spec/unit/invokers/proc_invoker_spec.rb +86 -0
- data/spec/unit/localizer_spec.rb +9 -10
- data/spec/unit/persistence/active_record_persistence_multiple_spec.rb +4 -4
- data/spec/unit/persistence/active_record_persistence_spec.rb +109 -4
- data/spec/unit/persistence/mongoid_persistence_multiple_spec.rb +0 -4
- data/spec/unit/persistence/mongoid_persistence_spec.rb +0 -4
- data/spec/unit/persistence/no_brainer_persistence_multiple_spec.rb +198 -0
- data/spec/unit/persistence/no_brainer_persistence_spec.rb +158 -0
- data/spec/unit/rspec_matcher_spec.rb +9 -0
- data/spec/unit/simple_example_spec.rb +15 -0
- data/spec/unit/state_spec.rb +23 -7
- data/spec/unit/transition_spec.rb +1 -1
- data/test/minitest_helper.rb +2 -2
- data/test/unit/minitest_matcher_test.rb +1 -1
- metadata +106 -12
- data/callbacks.txt +0 -51
- data/gemfiles/rails_3.2.gemfile +0 -13
- data/gemfiles/rails_4.0.gemfile +0 -15
@@ -0,0 +1,23 @@
|
|
1
|
+
class SimpleNoBrainer
|
2
|
+
include NoBrainer::Document
|
3
|
+
include AASM
|
4
|
+
|
5
|
+
field :status, type: String
|
6
|
+
|
7
|
+
aasm column: :status do
|
8
|
+
state :unknown_scope, :another_unknown_scope
|
9
|
+
state :new
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class SimpleNoBrainerMultiple
|
14
|
+
include NoBrainer::Document
|
15
|
+
include AASM
|
16
|
+
|
17
|
+
field :status, type: String
|
18
|
+
|
19
|
+
aasm :left, column: :status do
|
20
|
+
state :unknown_scope, :another_unknown_scope
|
21
|
+
state :new
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
class ValidatorNoBrainer
|
2
|
+
include NoBrainer::Document
|
3
|
+
include AASM
|
4
|
+
|
5
|
+
field :name
|
6
|
+
field :status
|
7
|
+
|
8
|
+
attr_accessor :invalid
|
9
|
+
|
10
|
+
validate do |_|
|
11
|
+
errors.add(:validator, 'invalid') if invalid
|
12
|
+
end
|
13
|
+
|
14
|
+
aasm column: :status, whiny_persistence: true do
|
15
|
+
before_all_transactions :before_all_transactions
|
16
|
+
after_all_transactions :after_all_transactions
|
17
|
+
|
18
|
+
state :sleeping, initial: true
|
19
|
+
state :running
|
20
|
+
state :failed, after_enter: :fail
|
21
|
+
|
22
|
+
event :run, after_commit: :change_name! do
|
23
|
+
transitions to: :running, from: :sleeping
|
24
|
+
end
|
25
|
+
|
26
|
+
event :sleep do
|
27
|
+
after_commit do |name|
|
28
|
+
change_name_on_sleep name
|
29
|
+
end
|
30
|
+
transitions to: :sleeping, from: :running
|
31
|
+
end
|
32
|
+
|
33
|
+
event :fail do
|
34
|
+
transitions to: :failed, from: %i[sleeping running]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
validates_presence_of :name
|
39
|
+
|
40
|
+
def change_name!
|
41
|
+
self.name = 'name changed'
|
42
|
+
save!
|
43
|
+
end
|
44
|
+
|
45
|
+
def change_name_on_sleep(name)
|
46
|
+
self.name = name
|
47
|
+
save!
|
48
|
+
end
|
49
|
+
|
50
|
+
def fail
|
51
|
+
raise StandardError, 'failed on purpose'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class MultipleValidatorNoBrainer
|
56
|
+
include NoBrainer::Document
|
57
|
+
include AASM
|
58
|
+
|
59
|
+
field :name
|
60
|
+
field :status
|
61
|
+
|
62
|
+
attr_accessor :invalid
|
63
|
+
|
64
|
+
aasm :left, column: :status, whiny_persistence: true do
|
65
|
+
state :sleeping, initial: true
|
66
|
+
state :running
|
67
|
+
state :failed, after_enter: :fail
|
68
|
+
|
69
|
+
event :run, after_commit: :change_name! do
|
70
|
+
transitions to: :running, from: :sleeping
|
71
|
+
end
|
72
|
+
event :sleep do
|
73
|
+
after_commit do |name|
|
74
|
+
change_name_on_sleep name
|
75
|
+
end
|
76
|
+
transitions to: :sleeping, from: :running
|
77
|
+
end
|
78
|
+
event :fail do
|
79
|
+
transitions to: :failed, from: %i[sleeping running]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
validates_presence_of :name
|
84
|
+
|
85
|
+
def change_name!
|
86
|
+
self.name = 'name changed'
|
87
|
+
save!
|
88
|
+
end
|
89
|
+
|
90
|
+
def change_name_on_sleep(name)
|
91
|
+
self.name = name
|
92
|
+
save!
|
93
|
+
end
|
94
|
+
|
95
|
+
def fail
|
96
|
+
raise StandardError, 'failed on purpose'
|
97
|
+
end
|
98
|
+
end
|
@@ -3,13 +3,21 @@ class SimpleExample
|
|
3
3
|
aasm do
|
4
4
|
state :initialised, :initial => true
|
5
5
|
state :filled_out
|
6
|
+
state :denied
|
6
7
|
state :authorised
|
7
8
|
|
8
9
|
event :fill_out do
|
9
10
|
transitions :from => :initialised, :to => :filled_out
|
10
11
|
end
|
12
|
+
|
13
|
+
event :deny do
|
14
|
+
transitions from: :initialised, to: :denied
|
15
|
+
end
|
16
|
+
|
11
17
|
event :authorise do
|
12
18
|
transitions :from => :filled_out, :to => :authorised
|
13
19
|
end
|
20
|
+
|
14
21
|
end
|
22
|
+
|
15
23
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class SimpleExampleWithGuardArgs
|
2
|
+
include AASM
|
3
|
+
aasm do
|
4
|
+
state :initialised, :initial => true
|
5
|
+
state :filled_out_with_args
|
6
|
+
|
7
|
+
event :fill_out_with_args do
|
8
|
+
transitions :guard => [:arg_is_valid?],
|
9
|
+
:from => :initialised,
|
10
|
+
:to => :filled_out_with_args
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def arg_is_valid?(arg)
|
15
|
+
return arg
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,19 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start do
|
3
|
+
add_filter '/spec/'
|
4
|
+
end
|
5
|
+
|
6
|
+
if ENV['CI'] == 'true'
|
7
|
+
require 'codecov'
|
8
|
+
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
9
|
+
end
|
10
|
+
|
1
11
|
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
|
2
12
|
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
|
3
13
|
require 'aasm'
|
4
14
|
require 'rspec'
|
5
15
|
require 'aasm/rspec'
|
16
|
+
require 'i18n'
|
6
17
|
require 'pry'
|
7
18
|
|
8
19
|
# require 'ruby-debug'; Debugger.settings[:autoeval] = true; debugger; rubys_debugger = 'annoying'
|
@@ -24,3 +35,7 @@ Dir[File.dirname(__FILE__) + "/spec_helpers/**/*.rb"].sort.each { |f| require Fi
|
|
24
35
|
|
25
36
|
# example model classes
|
26
37
|
Dir[File.dirname(__FILE__) + "/models/*.rb"].sort.each { |f| require File.expand_path(f) }
|
38
|
+
|
39
|
+
I18n.load_path << 'spec/en.yml'
|
40
|
+
I18n.enforce_available_locales = false
|
41
|
+
I18n.default_locale = :en
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
begin
|
3
3
|
require 'active_record'
|
4
|
-
|
4
|
+
|
5
|
+
puts "active_record #{ActiveRecord::VERSION::STRING} gem found, running ActiveRecord specs \e[32m#{'✔'}\e[0m"
|
5
6
|
rescue LoadError
|
6
7
|
puts "active_record gem not found, not running ActiveRecord specs \e[31m#{'✖'}\e[0m"
|
7
8
|
end
|
@@ -1,20 +1,22 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
|
2
3
|
begin
|
3
4
|
require 'dynamoid'
|
4
5
|
require 'aws-sdk-resources'
|
5
|
-
puts "dynamoid gem found, running Dynamoid specs \e[32m#{'✔'}\e[0m"
|
6
|
+
puts "dynamoid #{Dynamoid::VERSION} gem found, running Dynamoid specs \e[32m#{'✔'}\e[0m"
|
6
7
|
|
7
8
|
ENV['ACCESS_KEY'] ||= 'abcd'
|
8
9
|
ENV['SECRET_KEY'] ||= '1234'
|
9
10
|
|
10
|
-
Aws.config.update(
|
11
|
+
Aws.config.update(
|
11
12
|
region: 'us-west-2',
|
12
13
|
credentials: Aws::Credentials.new(ENV['ACCESS_KEY'], ENV['SECRET_KEY'])
|
13
|
-
|
14
|
+
)
|
14
15
|
|
15
16
|
Dynamoid.configure do |config|
|
16
|
-
config.namespace =
|
17
|
-
config.endpoint = '
|
17
|
+
config.namespace = 'dynamoid_tests'
|
18
|
+
config.endpoint = "http://#{ENV['DYNAMODB_HOST'] || '127.0.0.1'}:" \
|
19
|
+
"#{ENV['DYNAMODB_PORT'] || 30180}"
|
18
20
|
config.warn_on_scan = false
|
19
21
|
end
|
20
22
|
|
@@ -1,7 +1,26 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
|
2
3
|
begin
|
3
4
|
require 'mongoid'
|
4
|
-
puts "mongoid gem found, running mongoid specs \e[32m#{'✔'}\e[0m"
|
5
|
+
puts "mongoid #{Mongoid::VERSION} gem found, running mongoid specs \e[32m#{'✔'}\e[0m"
|
6
|
+
|
7
|
+
if Mongoid::VERSION.to_f <= 5
|
8
|
+
Mongoid::Config.sessions = {
|
9
|
+
default: {
|
10
|
+
database: "mongoid_#{Process.pid}",
|
11
|
+
hosts: ["#{ENV['MONGODB_HOST'] || 'localhost'}:" \
|
12
|
+
"#{ENV['MONGODB_PORT'] || 27017}"]
|
13
|
+
}
|
14
|
+
}
|
15
|
+
else
|
16
|
+
Mongoid::Config.send(:clients=, {
|
17
|
+
default: {
|
18
|
+
database: "mongoid_#{Process.pid}",
|
19
|
+
hosts: ["#{ENV['MONGODB_HOST'] || 'localhost'}:" \
|
20
|
+
"#{ENV['MONGODB_PORT'] || 27017}"]
|
21
|
+
}
|
22
|
+
})
|
23
|
+
end
|
5
24
|
rescue LoadError
|
6
25
|
puts "mongoid gem not found, not running mongoid specs \e[31m#{'✖'}\e[0m"
|
7
26
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'nobrainer'
|
5
|
+
|
6
|
+
NoBrainer.configure do |config|
|
7
|
+
config.app_name = :aasm
|
8
|
+
config.environment = :test
|
9
|
+
config.warn_on_active_record = false
|
10
|
+
end
|
11
|
+
|
12
|
+
puts "nobrainer #{Gem.loaded_specs['nobrainer'].version} gem found, running nobrainer specs \e[32m#{'✔'}\e[0m"
|
13
|
+
rescue LoadError
|
14
|
+
puts "nobrainer gem not found, not running nobrainer specs \e[31m#{'✖'}\e[0m"
|
15
|
+
end
|
data/spec/spec_helpers/redis.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
|
2
3
|
begin
|
3
4
|
require 'redis-objects'
|
4
|
-
|
5
|
+
require 'redis/objects/version'
|
6
|
+
puts "redis-objects #{Redis::Objects::VERSION} gem found, running Redis specs \e[32m#{'✔'}\e[0m"
|
5
7
|
|
6
|
-
Redis.current = Redis.new(host: '127.0.0.1',
|
8
|
+
Redis.current = Redis.new(host: (ENV['REDIS_HOST'] || '127.0.0.1'),
|
9
|
+
port: (ENV['REDIS_PORT'] || 6379))
|
7
10
|
|
8
11
|
RSpec.configure do |c|
|
9
12
|
c.before(:each) do
|
data/spec/spec_helpers/sequel.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
begin
|
3
3
|
require 'sequel'
|
4
|
-
puts "sequel gem found, running Sequel specs \e[32m#{'✔'}\e[0m"
|
4
|
+
puts "sequel #{Sequel::VERSION} gem found, running Sequel specs \e[32m#{'✔'}\e[0m"
|
5
5
|
rescue LoadError
|
6
6
|
puts "sequel gem not found, not running Sequel specs \e[31m#{'✖'}\e[0m"
|
7
7
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
if defined?(ActiveRecord)
|
3
|
+
require 'models/active_record/person'
|
4
|
+
|
5
|
+
load_schema
|
6
|
+
describe 'Abstract subclassing' do
|
7
|
+
|
8
|
+
it 'should have the parent states' do
|
9
|
+
Person.aasm.states.each do |state|
|
10
|
+
expect(Base.aasm.states).to include(state)
|
11
|
+
end
|
12
|
+
expect(Person.aasm.states).to eq(Base.aasm.states)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should have the same events as its parent' do
|
16
|
+
expect(Base.aasm.events).to eq(Person.aasm.events)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should not break aasm methods when super class is abstract_class' do
|
20
|
+
person = Person.new
|
21
|
+
person.status = 'active'
|
22
|
+
person.deactivate!
|
23
|
+
expect(person.aasm.current_state).to eq(:inactive)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/spec/unit/api_spec.rb
CHANGED
@@ -13,6 +13,10 @@ if defined?(ActiveRecord)
|
|
13
13
|
expect(DefaultState.new.aasm.current_state).to eql :alpha
|
14
14
|
end
|
15
15
|
|
16
|
+
it "uses display option" do
|
17
|
+
expect(DefaultState.new.aasm.human_state).to eql "ALPHA"
|
18
|
+
end
|
19
|
+
|
16
20
|
it "uses the provided method" do
|
17
21
|
expect(ProvidedState.new.aasm.current_state).to eql :beta
|
18
22
|
end
|
@@ -49,7 +49,7 @@ describe 'callbacks for the new DSL' do
|
|
49
49
|
|
50
50
|
expect {
|
51
51
|
callback.left_close!
|
52
|
-
}.to raise_error(AASM::InvalidTransition, "Event 'left_close' cannot transition from 'open'. Failed callback(s): [:
|
52
|
+
}.to raise_error(AASM::InvalidTransition, "Event 'left_close' cannot transition from 'open'. Failed callback(s): [:event_guard].")
|
53
53
|
|
54
54
|
end
|
55
55
|
|
@@ -88,7 +88,7 @@ describe 'callbacks for the new DSL' do
|
|
88
88
|
|
89
89
|
expect {
|
90
90
|
callback.left_close!
|
91
|
-
}.to raise_error(AASM::InvalidTransition, "Event 'left_close' cannot transition from 'open'. Failed callback(s): [:
|
91
|
+
}.to raise_error(AASM::InvalidTransition, "Event 'left_close' cannot transition from 'open'. Failed callback(s): [:transition_guard].")
|
92
92
|
end
|
93
93
|
|
94
94
|
it "does not run transition_guard twice for multiple permitted transitions" do
|
@@ -154,6 +154,8 @@ describe 'callbacks for the new DSL' do
|
|
154
154
|
expect(cb).to receive(:before_method).with(:arg1).once.ordered
|
155
155
|
expect(cb).to receive(:transition_method).never
|
156
156
|
expect(cb).to receive(:transition_method2).with(:arg1).once.ordered
|
157
|
+
expect(cb).to receive(:before_success_method).with(:arg1).once.ordered
|
158
|
+
expect(cb).to receive(:success_method).with(:arg1).once.ordered
|
157
159
|
expect(cb).to receive(:after_method).with(:arg1).once.ordered
|
158
160
|
cb.close!(:out_to_lunch, :arg1)
|
159
161
|
|
@@ -161,6 +163,8 @@ describe 'callbacks for the new DSL' do
|
|
161
163
|
some_object = double('some object')
|
162
164
|
expect(cb).to receive(:before_method).with(some_object).once.ordered
|
163
165
|
expect(cb).to receive(:transition_method2).with(some_object).once.ordered
|
166
|
+
expect(cb).to receive(:before_success_method).with(some_object).once.ordered
|
167
|
+
expect(cb).to receive(:success_method).with(some_object).once.ordered
|
164
168
|
expect(cb).to receive(:after_method).with(some_object).once.ordered
|
165
169
|
cb.close!(:out_to_lunch, some_object)
|
166
170
|
end
|
@@ -287,7 +291,7 @@ describe 'event callbacks' do
|
|
287
291
|
expect(@foo).to receive(:aasm_event_failed).with(:null, :open)
|
288
292
|
expect{
|
289
293
|
@foo.null
|
290
|
-
}.to raise_error(AASM::InvalidTransition, "Event 'null' cannot transition from 'open'. Failed callback(s): [:always_false
|
294
|
+
}.to raise_error(AASM::InvalidTransition, "Event 'null' cannot transition from 'open'. Failed callback(s): [:always_false].")
|
291
295
|
end
|
292
296
|
|
293
297
|
it 'should not call it if persist fails for bang fire' do
|
data/spec/unit/callbacks_spec.rb
CHANGED
@@ -3,14 +3,14 @@ Dir[File.dirname(__FILE__) + "/../models/callbacks/*.rb"].sort.each { |f| requir
|
|
3
3
|
|
4
4
|
shared_examples 'an implemented callback that accepts error' do
|
5
5
|
context 'with callback defined' do
|
6
|
-
it "should run error_callback if an exception is raised" do
|
6
|
+
it "should run error_callback if an exception is raised and always return false" do
|
7
7
|
aasm_model.class.send(:define_method, callback_name) do |e|
|
8
8
|
@data = [e]
|
9
9
|
end
|
10
10
|
|
11
11
|
allow(aasm_model).to receive(:before_enter).and_raise(e = StandardError.new)
|
12
12
|
|
13
|
-
aasm_model.safe_close!
|
13
|
+
expect(aasm_model.safe_close!).to be false
|
14
14
|
expect(aasm_model.data).to eql [e]
|
15
15
|
end
|
16
16
|
|
@@ -203,6 +203,32 @@ describe 'callbacks for the new DSL' do
|
|
203
203
|
}.to raise_error(AASM::InvalidTransition)
|
204
204
|
end
|
205
205
|
|
206
|
+
it "does not propagate failures to next attempt of same transition" do
|
207
|
+
callback = Callbacks::Basic.new(:log => false, :fail_transition_guard => true)
|
208
|
+
|
209
|
+
expect {
|
210
|
+
callback.close!
|
211
|
+
}.to raise_error(AASM::InvalidTransition, "Event 'close' cannot transition from 'open'. Failed callback(s): [:transition_guard].")
|
212
|
+
|
213
|
+
expect {
|
214
|
+
callback.close!
|
215
|
+
}.to raise_error(AASM::InvalidTransition, "Event 'close' cannot transition from 'open'. Failed callback(s): [:transition_guard].")
|
216
|
+
end
|
217
|
+
|
218
|
+
it "does not propagate failures to next attempt of same event when no transition is applicable" do
|
219
|
+
callback = Callbacks::Basic.new(:log => false, :fail_transition_guard => true)
|
220
|
+
|
221
|
+
expect {
|
222
|
+
callback.close!
|
223
|
+
}.to raise_error(AASM::InvalidTransition, "Event 'close' cannot transition from 'open'. Failed callback(s): [:transition_guard].")
|
224
|
+
|
225
|
+
callback.aasm.current_state = :closed
|
226
|
+
|
227
|
+
expect {
|
228
|
+
callback.close!
|
229
|
+
}.to raise_error(AASM::InvalidTransition, "Event 'close' cannot transition from 'closed'.")
|
230
|
+
end
|
231
|
+
|
206
232
|
it "does not run transition_guard twice for multiple permitted transitions" do
|
207
233
|
show_debug_log = false
|
208
234
|
callback = Callbacks::MultipleTransitionsTransitionGuard.new(:log => show_debug_log, :fail_transition_guard => true)
|
@@ -289,7 +315,9 @@ describe 'callbacks for the new DSL' do
|
|
289
315
|
expect(cb).to receive(:before_method).with(:arg1).once.ordered
|
290
316
|
expect(cb).to receive(:transition_method).with(:arg1).once.ordered
|
291
317
|
expect(cb).to receive(:transition_method).never
|
318
|
+
expect(cb).to receive(:before_success_method).with(:arg1).once.ordered
|
292
319
|
expect(cb).to receive(:success_method).with(:arg1).once.ordered
|
320
|
+
expect(cb).to receive(:success_method3).with(:arg1).once.ordered
|
293
321
|
expect(cb).to receive(:success_method).never
|
294
322
|
expect(cb).to receive(:after_method).with(:arg1).once.ordered
|
295
323
|
cb.close!(:arg1)
|
@@ -299,7 +327,9 @@ describe 'callbacks for the new DSL' do
|
|
299
327
|
expect(cb).to receive(:before_method).with(some_object).once.ordered
|
300
328
|
expect(cb).to receive(:transition_method).with(some_object).once.ordered
|
301
329
|
expect(cb).to receive(:transition_method).never
|
330
|
+
expect(cb).to receive(:before_success_method).with(some_object).once.ordered
|
302
331
|
expect(cb).to receive(:success_method).with(some_object).once.ordered
|
332
|
+
expect(cb).to receive(:success_method3).with(some_object).once.ordered
|
303
333
|
expect(cb).to receive(:success_method).never
|
304
334
|
expect(cb).to receive(:after_method).with(some_object).once.ordered
|
305
335
|
cb.close!(some_object)
|