aasm 4.5.1 → 5.5.0
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/LICENSE +1 -1
- data/README.md +809 -129
- data/lib/aasm/aasm.rb +74 -37
- data/lib/aasm/base.rb +188 -41
- data/lib/aasm/configuration.rb +27 -2
- data/lib/aasm/core/event.rb +75 -47
- 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 +49 -0
- data/lib/aasm/core/invokers/proc_invoker.rb +59 -0
- data/lib/aasm/core/state.rb +22 -13
- data/lib/aasm/core/transition.rb +30 -23
- data/lib/aasm/dsl_helper.rb +24 -22
- data/lib/aasm/errors.rb +8 -5
- data/lib/aasm/instance_base.rb +63 -15
- data/lib/aasm/localizer.rb +13 -3
- data/lib/aasm/minitest/allow_event.rb +13 -0
- data/lib/aasm/minitest/allow_transition_to.rb +13 -0
- data/lib/aasm/minitest/have_state.rb +13 -0
- data/lib/aasm/minitest/transition_from.rb +21 -0
- data/lib/aasm/minitest.rb +5 -0
- data/lib/aasm/minitest_spec.rb +15 -0
- data/lib/aasm/persistence/active_record_persistence.rb +87 -79
- data/lib/aasm/persistence/base.rb +30 -30
- data/lib/aasm/persistence/core_data_query_persistence.rb +94 -0
- data/lib/aasm/persistence/dynamoid_persistence.rb +92 -0
- data/lib/aasm/persistence/mongoid_persistence.rb +49 -35
- data/lib/aasm/persistence/no_brainer_persistence.rb +105 -0
- data/lib/aasm/persistence/orm.rb +154 -0
- data/lib/aasm/persistence/plain_persistence.rb +2 -1
- data/lib/aasm/persistence/redis_persistence.rb +112 -0
- data/lib/aasm/persistence/sequel_persistence.rb +37 -67
- data/lib/aasm/persistence.rb +20 -5
- 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 +8 -4
- data/lib/aasm/state_machine.rb +6 -12
- data/lib/aasm/state_machine_store.rb +76 -0
- data/lib/aasm/version.rb +1 -1
- data/lib/aasm.rb +8 -2
- data/lib/generators/aasm/aasm_generator.rb +16 -0
- data/lib/generators/aasm/orm_helpers.rb +41 -0
- data/lib/generators/active_record/aasm_generator.rb +40 -0
- data/lib/generators/active_record/templates/migration.rb +8 -0
- data/lib/generators/active_record/templates/migration_existing.rb +5 -0
- data/lib/generators/mongoid/aasm_generator.rb +28 -0
- data/lib/generators/nobrainer/aasm_generator.rb +28 -0
- data/lib/motion-aasm.rb +37 -0
- metadata +104 -259
- data/.document +0 -6
- data/.gitignore +0 -19
- data/.travis.yml +0 -37
- data/API +0 -34
- data/CHANGELOG.md +0 -272
- data/CODE_OF_CONDUCT.md +0 -13
- data/Gemfile +0 -15
- data/HOWTO +0 -12
- data/PLANNED_CHANGES.md +0 -11
- data/README_FROM_VERSION_3_TO_4.md +0 -240
- data/Rakefile +0 -26
- data/aasm.gemspec +0 -31
- data/callbacks.txt +0 -51
- data/gemfiles/rails_3.2.gemfile +0 -14
- data/gemfiles/rails_4.0.gemfile +0 -12
- data/gemfiles/rails_4.0_mongo_mapper.gemfile +0 -14
- data/gemfiles/rails_4.1.gemfile +0 -12
- data/gemfiles/rails_4.1_mongo_mapper.gemfile +0 -14
- data/gemfiles/rails_4.2.gemfile +0 -12
- data/gemfiles/rails_4.2_mongo_mapper.gemfile +0 -14
- data/gemfiles/rails_4.2_mongoid_5.gemfile +0 -12
- data/lib/aasm/persistence/mongo_mapper_persistence.rb +0 -157
- data/spec/database.rb +0 -63
- data/spec/database.yml +0 -3
- data/spec/en.yml +0 -9
- data/spec/en_deprecated_style.yml +0 -10
- data/spec/models/active_record/basic_active_record_two_state_machines_example.rb +0 -25
- data/spec/models/active_record/complex_active_record_example.rb +0 -33
- data/spec/models/active_record/derivate_new_dsl.rb +0 -7
- data/spec/models/active_record/false_state.rb +0 -35
- data/spec/models/active_record/gate.rb +0 -39
- data/spec/models/active_record/localizer_test_model.rb +0 -34
- data/spec/models/active_record/no_direct_assignment.rb +0 -21
- data/spec/models/active_record/no_scope.rb +0 -21
- data/spec/models/active_record/persisted_state.rb +0 -12
- data/spec/models/active_record/provided_and_persisted_state.rb +0 -24
- data/spec/models/active_record/reader.rb +0 -7
- data/spec/models/active_record/readme_job.rb +0 -21
- data/spec/models/active_record/simple_new_dsl.rb +0 -17
- data/spec/models/active_record/thief.rb +0 -29
- data/spec/models/active_record/transient.rb +0 -6
- data/spec/models/active_record/with_enum.rb +0 -39
- data/spec/models/active_record/with_false_enum.rb +0 -31
- data/spec/models/active_record/with_true_enum.rb +0 -39
- data/spec/models/active_record/writer.rb +0 -6
- data/spec/models/basic_two_state_machines_example.rb +0 -25
- data/spec/models/callbacks/basic.rb +0 -78
- data/spec/models/callbacks/basic_multiple.rb +0 -75
- data/spec/models/callbacks/guard_within_block.rb +0 -66
- data/spec/models/callbacks/guard_within_block_multiple.rb +0 -66
- data/spec/models/callbacks/multiple_transitions_transition_guard.rb +0 -65
- data/spec/models/callbacks/multiple_transitions_transition_guard_multiple.rb +0 -65
- data/spec/models/callbacks/private_method.rb +0 -44
- data/spec/models/callbacks/private_method_multiple.rb +0 -44
- data/spec/models/callbacks/with_args.rb +0 -61
- data/spec/models/callbacks/with_args_multiple.rb +0 -61
- data/spec/models/callbacks/with_state_arg.rb +0 -26
- data/spec/models/callbacks/with_state_arg_multiple.rb +0 -26
- data/spec/models/complex_example.rb +0 -222
- data/spec/models/conversation.rb +0 -93
- data/spec/models/default_state.rb +0 -12
- data/spec/models/double_definer.rb +0 -21
- data/spec/models/foo.rb +0 -92
- data/spec/models/foo_callback_multiple.rb +0 -45
- data/spec/models/guardian.rb +0 -48
- data/spec/models/guardian_multiple.rb +0 -48
- data/spec/models/initial_state_proc.rb +0 -31
- data/spec/models/invalid_persistor.rb +0 -31
- data/spec/models/mongo_mapper/complex_mongo_mapper_example.rb +0 -37
- data/spec/models/mongo_mapper/no_scope_mongo_mapper.rb +0 -21
- data/spec/models/mongo_mapper/simple_mongo_mapper.rb +0 -23
- data/spec/models/mongo_mapper/simple_new_dsl_mongo_mapper.rb +0 -25
- data/spec/models/mongoid/complex_mongoid_example.rb +0 -37
- data/spec/models/mongoid/no_scope_mongoid.rb +0 -21
- data/spec/models/mongoid/simple_mongoid.rb +0 -23
- data/spec/models/mongoid/simple_new_dsl_mongoid.rb +0 -25
- data/spec/models/no_initial_state.rb +0 -25
- data/spec/models/not_auto_loaded/process.rb +0 -21
- data/spec/models/parametrised_event.rb +0 -29
- data/spec/models/parametrised_event_multiple.rb +0 -29
- data/spec/models/process_with_new_dsl.rb +0 -31
- data/spec/models/provided_state.rb +0 -24
- data/spec/models/sequel/complex_sequel_example.rb +0 -45
- data/spec/models/sequel/sequel_multiple.rb +0 -25
- data/spec/models/sequel/sequel_simple.rb +0 -25
- data/spec/models/silencer.rb +0 -27
- data/spec/models/simple_example.rb +0 -15
- data/spec/models/simple_multiple_example.rb +0 -30
- data/spec/models/state_machine_with_failed_event.rb +0 -12
- data/spec/models/sub_class.rb +0 -7
- data/spec/models/sub_class_with_more_states.rb +0 -18
- data/spec/models/sub_classing.rb +0 -3
- data/spec/models/super_class.rb +0 -46
- data/spec/models/this_name_better_not_be_in_use.rb +0 -11
- data/spec/models/transactor.rb +0 -53
- data/spec/models/valid_state_name.rb +0 -23
- data/spec/models/validator.rb +0 -79
- data/spec/models/worker.rb +0 -2
- data/spec/spec_helper.rb +0 -25
- data/spec/unit/api_spec.rb +0 -77
- data/spec/unit/basic_two_state_machines_example_spec.rb +0 -10
- data/spec/unit/callback_multiple_spec.rb +0 -295
- data/spec/unit/callbacks_spec.rb +0 -296
- data/spec/unit/complex_example_spec.rb +0 -84
- data/spec/unit/complex_multiple_example_spec.rb +0 -99
- data/spec/unit/edge_cases_spec.rb +0 -16
- data/spec/unit/event_multiple_spec.rb +0 -73
- data/spec/unit/event_naming_spec.rb +0 -11
- data/spec/unit/event_spec.rb +0 -322
- data/spec/unit/guard_multiple_spec.rb +0 -60
- data/spec/unit/guard_spec.rb +0 -60
- data/spec/unit/initial_state_multiple_spec.rb +0 -15
- data/spec/unit/initial_state_spec.rb +0 -12
- data/spec/unit/inspection_multiple_spec.rb +0 -201
- data/spec/unit/inspection_spec.rb +0 -111
- data/spec/unit/localizer_spec.rb +0 -76
- data/spec/unit/memory_leak_spec.rb +0 -38
- data/spec/unit/new_dsl_spec.rb +0 -12
- data/spec/unit/persistence/active_record_persistence_multiple_spec.rb +0 -573
- data/spec/unit/persistence/active_record_persistence_spec.rb +0 -552
- data/spec/unit/persistence/mongo_mapper_persistence_multiple_spec.rb +0 -146
- data/spec/unit/persistence/mongo_mapper_persistence_spec.rb +0 -93
- data/spec/unit/persistence/mongoid_persistence_multiple_spec.rb +0 -127
- data/spec/unit/persistence/mongoid_persistence_spec.rb +0 -79
- data/spec/unit/persistence/sequel_persistence_multiple_spec.rb +0 -153
- data/spec/unit/persistence/sequel_persistence_spec.rb +0 -100
- data/spec/unit/readme_spec.rb +0 -42
- data/spec/unit/reloading_spec.rb +0 -15
- data/spec/unit/rspec_matcher_spec.rb +0 -79
- data/spec/unit/simple_example_spec.rb +0 -42
- data/spec/unit/simple_multiple_example_spec.rb +0 -63
- data/spec/unit/state_spec.rb +0 -89
- data/spec/unit/subclassing_multiple_spec.rb +0 -39
- data/spec/unit/subclassing_spec.rb +0 -31
- data/spec/unit/transition_spec.rb +0 -291
@@ -1,93 +0,0 @@
|
|
1
|
-
describe 'mongo_mapper' do
|
2
|
-
begin
|
3
|
-
require 'mongo_mapper'
|
4
|
-
require 'logger'
|
5
|
-
require 'spec_helper'
|
6
|
-
|
7
|
-
Dir[File.dirname(__FILE__) + "/../../models/mongo_mapper/*.rb"].sort.each do |f|
|
8
|
-
require File.expand_path(f)
|
9
|
-
end
|
10
|
-
|
11
|
-
before(:all) do
|
12
|
-
config = {
|
13
|
-
'test' => {
|
14
|
-
'database' => "mongo_mapper_#{Process.pid}"
|
15
|
-
}
|
16
|
-
}
|
17
|
-
|
18
|
-
MongoMapper.setup(config, 'test') #, :logger => Logger.new(STDERR))
|
19
|
-
end
|
20
|
-
|
21
|
-
after do
|
22
|
-
# Clear Out all non-system Mongo collections between tests
|
23
|
-
MongoMapper.database.collections.each do |collection|
|
24
|
-
collection.drop unless collection.capped? || (collection.name =~ /\Asystem/)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "named scopes with the old DSL" do
|
29
|
-
|
30
|
-
context "Does not already respond_to? the scope name" do
|
31
|
-
it "should add a scope" do
|
32
|
-
expect(SimpleMongoMapper).to respond_to(:unknown_scope)
|
33
|
-
expect(SimpleMongoMapper.unknown_scope.class).to eq(MongoMapper::Plugins::Querying::DecoratedPluckyQuery)
|
34
|
-
#expect(SimpleMongoMapper.unknown_scope.is_a?(ActiveRecord::Relation)).to be_truthy
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context "Already respond_to? the scope name" do
|
39
|
-
it "should not add a scope" do
|
40
|
-
expect(SimpleMongoMapper).to respond_to(:next)
|
41
|
-
expect(SimpleMongoMapper.new.class).to eq(SimpleMongoMapper)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "named scopes with the new DSL" do
|
48
|
-
|
49
|
-
context "Does not already respond_to? the scope name" do
|
50
|
-
it "should add a scope" do
|
51
|
-
expect(SimpleNewDslMongoMapper).to respond_to(:unknown_scope)
|
52
|
-
expect(SimpleNewDslMongoMapper.unknown_scope.class).to eq(MongoMapper::Plugins::Querying::DecoratedPluckyQuery)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "Already respond_to? the scope name" do
|
57
|
-
it "should not add a scope" do
|
58
|
-
expect(SimpleNewDslMongoMapper).to respond_to(:next)
|
59
|
-
expect(SimpleNewDslMongoMapper.new.class).to eq(SimpleNewDslMongoMapper)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
it "does not create scopes if requested" do
|
64
|
-
expect(NoScopeMongoMapper).not_to respond_to(:ignored_scope)
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "instance methods" do
|
70
|
-
|
71
|
-
let(:simple) {SimpleNewDslMongoMapper.new}
|
72
|
-
|
73
|
-
it "should call aasm_ensure_initial_state on validation before create" do
|
74
|
-
expect(SimpleNewDslMongoMapper.aasm.initial_state).to eq(:unknown_scope)
|
75
|
-
expect(SimpleNewDslMongoMapper.aasm.attribute_name).to eq(:status)
|
76
|
-
expect(simple.status).to eq(nil)
|
77
|
-
simple.valid?
|
78
|
-
expect(simple.status).to eq('unknown_scope')
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should call aasm_ensure_initial_state before create, even if skipping validations" do
|
82
|
-
expect(simple.status).to eq(nil)
|
83
|
-
simple.save(:validate => false)
|
84
|
-
expect(simple.status).to eq('unknown_scope')
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
rescue LoadError
|
89
|
-
puts "--------------------------------------------------------------------------"
|
90
|
-
puts "Not running MongoMapper multiple-specs because mongo_mapper gem is not installed!!!"
|
91
|
-
puts "--------------------------------------------------------------------------"
|
92
|
-
end
|
93
|
-
end
|
@@ -1,127 +0,0 @@
|
|
1
|
-
describe 'mongoid' do
|
2
|
-
begin
|
3
|
-
require 'mongoid'
|
4
|
-
require 'logger'
|
5
|
-
require 'spec_helper'
|
6
|
-
|
7
|
-
Dir[File.dirname(__FILE__) + "/../../models/mongoid/*.rb"].sort.each do |f|
|
8
|
-
require File.expand_path(f)
|
9
|
-
end
|
10
|
-
|
11
|
-
before(:all) do
|
12
|
-
# if you want to see the statements while running the spec enable the following line
|
13
|
-
# Mongoid.logger = Logger.new(STDERR)
|
14
|
-
|
15
|
-
Mongoid.configure do |config|
|
16
|
-
config.connect_to "mongoid_#{Process.pid}"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
after do
|
21
|
-
Mongoid.purge!
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "named scopes with the old DSL" do
|
25
|
-
|
26
|
-
context "Does not already respond_to? the scope name" do
|
27
|
-
it "should add a scope" do
|
28
|
-
expect(SimpleMongoidMultiple).to respond_to(:unknown_scope)
|
29
|
-
expect(SimpleMongoidMultiple.unknown_scope.class).to eq(Mongoid::Criteria)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "Already respond_to? the scope name" do
|
34
|
-
it "should not add a scope" do
|
35
|
-
expect(SimpleMongoidMultiple).to respond_to(:new)
|
36
|
-
expect(SimpleMongoidMultiple.new.class).to eq(SimpleMongoidMultiple)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "named scopes with the new DSL" do
|
43
|
-
context "Does not already respond_to? the scope name" do
|
44
|
-
it "should add a scope" do
|
45
|
-
expect(SimpleNewDslMongoidMultiple).to respond_to(:unknown_scope)
|
46
|
-
expect(SimpleNewDslMongoidMultiple.unknown_scope.class).to eq(Mongoid::Criteria)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "Already respond_to? the scope name" do
|
51
|
-
it "should not add a scope" do
|
52
|
-
expect(SimpleNewDslMongoidMultiple).to respond_to(:new)
|
53
|
-
expect(SimpleNewDslMongoidMultiple.new.class).to eq(SimpleNewDslMongoidMultiple)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
it "does not create scopes if requested" do
|
58
|
-
expect(NoScopeMongoidMultiple).not_to respond_to(:ignored_scope)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "instance methods" do
|
63
|
-
let(:simple) {SimpleNewDslMongoidMultiple.new}
|
64
|
-
|
65
|
-
it "should initialize the aasm state on instantiation" do
|
66
|
-
expect(SimpleNewDslMongoidMultiple.new.status).to eql 'unknown_scope'
|
67
|
-
expect(SimpleNewDslMongoidMultiple.new.aasm(:left).current_state).to eql :unknown_scope
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "complex example" do
|
73
|
-
it "works" do
|
74
|
-
record = ComplexMongoidExample.new
|
75
|
-
expect_aasm_states record, :one, :alpha
|
76
|
-
|
77
|
-
record.save!
|
78
|
-
expect_aasm_states record, :one, :alpha
|
79
|
-
record.reload
|
80
|
-
expect_aasm_states record, :one, :alpha
|
81
|
-
|
82
|
-
record.increment!
|
83
|
-
expect_aasm_states record, :two, :alpha
|
84
|
-
record.reload
|
85
|
-
expect_aasm_states record, :two, :alpha
|
86
|
-
|
87
|
-
record.level_up!
|
88
|
-
expect_aasm_states record, :two, :beta
|
89
|
-
record.reload
|
90
|
-
expect_aasm_states record, :two, :beta
|
91
|
-
|
92
|
-
record.increment!
|
93
|
-
expect { record.increment! }.to raise_error(AASM::InvalidTransition)
|
94
|
-
expect_aasm_states record, :three, :beta
|
95
|
-
record.reload
|
96
|
-
expect_aasm_states record, :three, :beta
|
97
|
-
|
98
|
-
record.level_up!
|
99
|
-
expect_aasm_states record, :three, :gamma
|
100
|
-
record.reload
|
101
|
-
expect_aasm_states record, :three, :gamma
|
102
|
-
|
103
|
-
record.level_down # without saving
|
104
|
-
expect_aasm_states record, :three, :beta
|
105
|
-
record.reload
|
106
|
-
expect_aasm_states record, :three, :gamma
|
107
|
-
|
108
|
-
record.level_down # without saving
|
109
|
-
expect_aasm_states record, :three, :beta
|
110
|
-
record.reset!
|
111
|
-
expect_aasm_states record, :one, :beta
|
112
|
-
end
|
113
|
-
|
114
|
-
def expect_aasm_states(record, left_state, right_state)
|
115
|
-
expect(record.aasm(:left).current_state).to eql left_state.to_sym
|
116
|
-
expect(record.left).to eql left_state.to_s
|
117
|
-
expect(record.aasm(:right).current_state).to eql right_state.to_sym
|
118
|
-
expect(record.right).to eql right_state.to_s
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
rescue LoadError
|
123
|
-
puts "--------------------------------------------------------------------------"
|
124
|
-
puts "Not running Mongoid multiple-specs because mongoid gem is not installed!!!"
|
125
|
-
puts "--------------------------------------------------------------------------"
|
126
|
-
end
|
127
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
describe 'mongoid' do
|
2
|
-
begin
|
3
|
-
require 'mongoid'
|
4
|
-
require 'logger'
|
5
|
-
require 'spec_helper'
|
6
|
-
|
7
|
-
Dir[File.dirname(__FILE__) + "/../../models/mongoid/*.rb"].sort.each do |f|
|
8
|
-
require File.expand_path(f)
|
9
|
-
end
|
10
|
-
|
11
|
-
before(:all) do
|
12
|
-
# if you want to see the statements while running the spec enable the following line
|
13
|
-
# Mongoid.logger = Logger.new(STDERR)
|
14
|
-
|
15
|
-
Mongoid.configure do |config|
|
16
|
-
config.connect_to "mongoid_#{Process.pid}"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
after do
|
21
|
-
Mongoid.purge!
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "named scopes with the old DSL" do
|
25
|
-
|
26
|
-
context "Does not already respond_to? the scope name" do
|
27
|
-
it "should add a scope" do
|
28
|
-
expect(SimpleMongoid).to respond_to(:unknown_scope)
|
29
|
-
expect(SimpleMongoid.unknown_scope.class).to eq(Mongoid::Criteria)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "Already respond_to? the scope name" do
|
34
|
-
it "should not add a scope" do
|
35
|
-
expect(SimpleMongoid).to respond_to(:new)
|
36
|
-
expect(SimpleMongoid.new.class).to eq(SimpleMongoid)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "named scopes with the new DSL" do
|
43
|
-
|
44
|
-
context "Does not already respond_to? the scope name" do
|
45
|
-
it "should add a scope" do
|
46
|
-
expect(SimpleNewDslMongoid).to respond_to(:unknown_scope)
|
47
|
-
expect(SimpleNewDslMongoid.unknown_scope.class).to eq(Mongoid::Criteria)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context "Already respond_to? the scope name" do
|
52
|
-
it "should not add a scope" do
|
53
|
-
expect(SimpleNewDslMongoid).to respond_to(:new)
|
54
|
-
expect(SimpleNewDslMongoid.new.class).to eq(SimpleNewDslMongoid)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
it "does not create scopes if requested" do
|
59
|
-
expect(NoScopeMongoid).not_to respond_to(:ignored_scope)
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "instance methods" do
|
65
|
-
let(:simple) {SimpleNewDslMongoid.new}
|
66
|
-
|
67
|
-
it "should initialize the aasm state on instantiation" do
|
68
|
-
expect(SimpleNewDslMongoid.new.status).to eql 'unknown_scope'
|
69
|
-
expect(SimpleNewDslMongoid.new.aasm.current_state).to eql :unknown_scope
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
rescue LoadError
|
75
|
-
puts "--------------------------------------------------------------------------"
|
76
|
-
puts "Not running Mongoid specs because mongoid gem is not installed!!!"
|
77
|
-
puts "--------------------------------------------------------------------------"
|
78
|
-
end
|
79
|
-
end
|
@@ -1,153 +0,0 @@
|
|
1
|
-
describe 'sequel' do
|
2
|
-
begin
|
3
|
-
require 'sequel'
|
4
|
-
require 'logger'
|
5
|
-
require 'spec_helper'
|
6
|
-
|
7
|
-
Dir[File.dirname(__FILE__) + "/../../models/sequel/*.rb"].sort.each do |f|
|
8
|
-
require File.expand_path(f)
|
9
|
-
end
|
10
|
-
|
11
|
-
before(:all) do
|
12
|
-
@model = SequelMultiple
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "instance methods" do
|
16
|
-
let(:model) {@model.new}
|
17
|
-
|
18
|
-
it "should respond to aasm persistence methods" do
|
19
|
-
expect(model).to respond_to(:aasm_read_state)
|
20
|
-
expect(model).to respond_to(:aasm_write_state)
|
21
|
-
expect(model).to respond_to(:aasm_write_state_without_persistence)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should return the initial state when new and the aasm field is nil" do
|
25
|
-
expect(model.aasm(:left).current_state).to eq(:alpha)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should save the initial state" do
|
29
|
-
model.save
|
30
|
-
expect(model.status).to eq("alpha")
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should return the aasm column when new and the aasm field is not nil" do
|
34
|
-
model.status = "beta"
|
35
|
-
expect(model.aasm(:left).current_state).to eq(:beta)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should return the aasm column when not new and the aasm_column is not nil" do
|
39
|
-
allow(model).to receive(:new?).and_return(false)
|
40
|
-
model.status = "gamma"
|
41
|
-
expect(model.aasm(:left).current_state).to eq(:gamma)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should allow a nil state" do
|
45
|
-
allow(model).to receive(:new?).and_return(false)
|
46
|
-
model.status = nil
|
47
|
-
expect(model.aasm(:left).current_state).to be_nil
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should not change the state if state is not loaded" do
|
51
|
-
model.release
|
52
|
-
model.save
|
53
|
-
model.class.select(:id).first.save
|
54
|
-
model.reload
|
55
|
-
expect(model.aasm(:left).current_state).to eq(:beta)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should call aasm_ensure_initial_state on validation before create" do
|
59
|
-
expect(model).to receive(:aasm_ensure_initial_state).and_return(true)
|
60
|
-
model.valid?
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should call aasm_ensure_initial_state before create, even if skipping validations" do
|
64
|
-
expect(model).to receive(:aasm_ensure_initial_state).and_return(true)
|
65
|
-
model.save(:validate => false)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe 'subclasses' do
|
70
|
-
it "should have the same states as its parent class" do
|
71
|
-
expect(Class.new(@model).aasm(:left).states).to eq(@model.aasm(:left).states)
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should have the same events as its parent class" do
|
75
|
-
expect(Class.new(@model).aasm(:left).events).to eq(@model.aasm(:left).events)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should have the same column as its parent even for the new dsl" do
|
79
|
-
expect(@model.aasm(:left).attribute_name).to eq(:status)
|
80
|
-
expect(Class.new(@model).aasm(:left).attribute_name).to eq(:status)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe 'initial states' do
|
85
|
-
it 'should support conditions' do
|
86
|
-
@model.aasm(:left) do
|
87
|
-
initial_state lambda{ |m| m.default }
|
88
|
-
end
|
89
|
-
|
90
|
-
expect(@model.new(:default => :beta).aasm(:left).current_state).to eq(:beta)
|
91
|
-
expect(@model.new(:default => :gamma).aasm(:left).current_state).to eq(:gamma)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe "complex example" do
|
96
|
-
it "works" do
|
97
|
-
record = ComplexSequelExample.new
|
98
|
-
expect(record.aasm(:left).current_state).to eql :one
|
99
|
-
expect(record.left).to be_nil
|
100
|
-
expect(record.aasm(:right).current_state).to eql :alpha
|
101
|
-
expect(record.right).to be_nil
|
102
|
-
|
103
|
-
record.save
|
104
|
-
expect_aasm_states record, :one, :alpha
|
105
|
-
record.reload
|
106
|
-
expect_aasm_states record, :one, :alpha
|
107
|
-
|
108
|
-
record.increment!
|
109
|
-
expect_aasm_states record, :two, :alpha
|
110
|
-
record.reload
|
111
|
-
expect_aasm_states record, :two, :alpha
|
112
|
-
|
113
|
-
record.level_up!
|
114
|
-
expect_aasm_states record, :two, :beta
|
115
|
-
record.reload
|
116
|
-
expect_aasm_states record, :two, :beta
|
117
|
-
|
118
|
-
record.increment!
|
119
|
-
expect { record.increment! }.to raise_error(AASM::InvalidTransition)
|
120
|
-
expect_aasm_states record, :three, :beta
|
121
|
-
record.reload
|
122
|
-
expect_aasm_states record, :three, :beta
|
123
|
-
|
124
|
-
record.level_up!
|
125
|
-
expect_aasm_states record, :three, :gamma
|
126
|
-
record.reload
|
127
|
-
expect_aasm_states record, :three, :gamma
|
128
|
-
|
129
|
-
record.level_down # without saving
|
130
|
-
expect_aasm_states record, :three, :beta
|
131
|
-
record.reload
|
132
|
-
expect_aasm_states record, :three, :gamma
|
133
|
-
|
134
|
-
record.level_down # without saving
|
135
|
-
expect_aasm_states record, :three, :beta
|
136
|
-
record.reset!
|
137
|
-
expect_aasm_states record, :one, :beta
|
138
|
-
end
|
139
|
-
|
140
|
-
def expect_aasm_states(record, left_state, right_state)
|
141
|
-
expect(record.aasm(:left).current_state).to eql left_state.to_sym
|
142
|
-
expect(record.left).to eql left_state.to_s
|
143
|
-
expect(record.aasm(:right).current_state).to eql right_state.to_sym
|
144
|
-
expect(record.right).to eql right_state.to_s
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
rescue LoadError
|
149
|
-
puts "------------------------------------------------------------------------"
|
150
|
-
puts "Not running Sequel multiple-specs because sequel gem is not installed!!!"
|
151
|
-
puts "------------------------------------------------------------------------"
|
152
|
-
end
|
153
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
describe 'sequel' do
|
2
|
-
begin
|
3
|
-
require 'sequel'
|
4
|
-
require 'logger'
|
5
|
-
require 'spec_helper'
|
6
|
-
|
7
|
-
Dir[File.dirname(__FILE__) + "/../../models/sequel/*.rb"].sort.each do |f|
|
8
|
-
require File.expand_path(f)
|
9
|
-
end
|
10
|
-
|
11
|
-
before(:all) do
|
12
|
-
@model = SequelSimple
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "instance methods" do
|
16
|
-
let(:model) {@model.new}
|
17
|
-
|
18
|
-
it "should respond to aasm persistence methods" do
|
19
|
-
expect(model).to respond_to(:aasm_read_state)
|
20
|
-
expect(model).to respond_to(:aasm_write_state)
|
21
|
-
expect(model).to respond_to(:aasm_write_state_without_persistence)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should return the initial state when new and the aasm field is nil" do
|
25
|
-
expect(model.aasm.current_state).to eq(:alpha)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should save the initial state" do
|
29
|
-
model.save
|
30
|
-
expect(model.status).to eq("alpha")
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should return the aasm column when new and the aasm field is not nil" do
|
34
|
-
model.status = "beta"
|
35
|
-
expect(model.aasm.current_state).to eq(:beta)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should return the aasm column when not new and the aasm_column is not nil" do
|
39
|
-
allow(model).to receive(:new?).and_return(false)
|
40
|
-
model.status = "gamma"
|
41
|
-
expect(model.aasm.current_state).to eq(:gamma)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should allow a nil state" do
|
45
|
-
allow(model).to receive(:new?).and_return(false)
|
46
|
-
model.status = nil
|
47
|
-
expect(model.aasm.current_state).to be_nil
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should not change the state if state is not loaded" do
|
51
|
-
model.release
|
52
|
-
model.save
|
53
|
-
model.class.select(:id).first.save
|
54
|
-
model.reload
|
55
|
-
expect(model.aasm.current_state).to eq(:beta)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should call aasm_ensure_initial_state on validation before create" do
|
59
|
-
expect(model).to receive(:aasm_ensure_initial_state).and_return(true)
|
60
|
-
model.valid?
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should call aasm_ensure_initial_state before create, even if skipping validations" do
|
64
|
-
expect(model).to receive(:aasm_ensure_initial_state).and_return(true)
|
65
|
-
model.save(:validate => false)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe 'subclasses' do
|
70
|
-
it "should have the same states as its parent class" do
|
71
|
-
expect(Class.new(@model).aasm.states).to eq(@model.aasm.states)
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should have the same events as its parent class" do
|
75
|
-
expect(Class.new(@model).aasm.events).to eq(@model.aasm.events)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should have the same column as its parent even for the new dsl" do
|
79
|
-
expect(@model.aasm.attribute_name).to eq(:status)
|
80
|
-
expect(Class.new(@model).aasm.attribute_name).to eq(:status)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe 'initial states' do
|
85
|
-
it 'should support conditions' do
|
86
|
-
@model.aasm do
|
87
|
-
initial_state lambda{ |m| m.default }
|
88
|
-
end
|
89
|
-
|
90
|
-
expect(@model.new(:default => :beta).aasm.current_state).to eq(:beta)
|
91
|
-
expect(@model.new(:default => :gamma).aasm.current_state).to eq(:gamma)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
rescue LoadError
|
96
|
-
puts "------------------------------------------------------------------------"
|
97
|
-
puts "Not running Sequel specs because sequel gem is not installed!!!"
|
98
|
-
puts "------------------------------------------------------------------------"
|
99
|
-
end
|
100
|
-
end
|
data/spec/unit/readme_spec.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'testing the README examples' do
|
4
|
-
|
5
|
-
it 'Usage' do
|
6
|
-
class Job
|
7
|
-
include AASM
|
8
|
-
|
9
|
-
aasm do
|
10
|
-
state :sleeping, :initial => true
|
11
|
-
state :running
|
12
|
-
state :cleaning
|
13
|
-
|
14
|
-
event :run do
|
15
|
-
transitions :from => :sleeping, :to => :running
|
16
|
-
end
|
17
|
-
|
18
|
-
event :clean do
|
19
|
-
transitions :from => :running, :to => :cleaning
|
20
|
-
end
|
21
|
-
|
22
|
-
event :sleep do
|
23
|
-
transitions :from => [:running, :cleaning], :to => :sleeping
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
job = Job.new
|
29
|
-
|
30
|
-
expect(job.sleeping?).to eql true
|
31
|
-
expect(job.may_run?).to eql true
|
32
|
-
|
33
|
-
job.run
|
34
|
-
|
35
|
-
expect(job.running?).to eql true
|
36
|
-
expect(job.sleeping?).to eql false
|
37
|
-
expect(job.may_run?).to eql false
|
38
|
-
|
39
|
-
expect { job.run }.to raise_error(AASM::InvalidTransition)
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
data/spec/unit/reloading_spec.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'when redefining states' do
|
4
|
-
let(:definer) { DoubleDefiner.new }
|
5
|
-
|
6
|
-
it "allows extending states" do
|
7
|
-
expect(definer).to receive(:do_enter)
|
8
|
-
definer.finish
|
9
|
-
end
|
10
|
-
|
11
|
-
it "allows extending events" do
|
12
|
-
expect(definer).to receive(:do_on_transition)
|
13
|
-
definer.finish
|
14
|
-
end
|
15
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'state machine' do
|
4
|
-
let(:simple) { SimpleExample.new }
|
5
|
-
let(:multiple) { SimpleMultipleExample.new }
|
6
|
-
|
7
|
-
describe 'transition_from' do
|
8
|
-
it "works for simple state machines" do
|
9
|
-
expect(simple).to transition_from(:initialised).to(:filled_out).on_event(:fill_out)
|
10
|
-
expect(simple).to_not transition_from(:initialised).to(:authorised).on_event(:fill_out)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "works for multiple state machines" do
|
14
|
-
expect(multiple).to transition_from(:standing).to(:walking).on_event(:walk).on(:move)
|
15
|
-
expect(multiple).to_not transition_from(:standing).to(:running).on_event(:walk).on(:move)
|
16
|
-
|
17
|
-
expect(multiple).to transition_from(:sleeping).to(:processing).on_event(:start).on(:work)
|
18
|
-
expect(multiple).to_not transition_from(:sleeping).to(:sleeping).on_event(:start).on(:work)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe 'allow_transition_to' do
|
23
|
-
it "works for simple state machines" do
|
24
|
-
expect(simple).to allow_transition_to(:filled_out)
|
25
|
-
expect(simple).to_not allow_transition_to(:authorised)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "works for multiple state machines" do
|
29
|
-
expect(multiple).to allow_transition_to(:walking).on(:move)
|
30
|
-
expect(multiple).to_not allow_transition_to(:standing).on(:move)
|
31
|
-
|
32
|
-
expect(multiple).to allow_transition_to(:processing).on(:work)
|
33
|
-
expect(multiple).to_not allow_transition_to(:sleeping).on(:work)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "have_state" do
|
38
|
-
it "works for simple state machines" do
|
39
|
-
expect(simple).to have_state :initialised
|
40
|
-
expect(simple).to_not have_state :filled_out
|
41
|
-
simple.fill_out
|
42
|
-
expect(simple).to have_state :filled_out
|
43
|
-
end
|
44
|
-
|
45
|
-
it "works for multiple state machines" do
|
46
|
-
expect(multiple).to have_state(:standing).on(:move)
|
47
|
-
expect(multiple).to_not have_state(:walking).on(:move)
|
48
|
-
multiple.walk
|
49
|
-
expect(multiple).to have_state(:walking).on(:move)
|
50
|
-
|
51
|
-
expect(multiple).to have_state(:sleeping).on(:work)
|
52
|
-
expect(multiple).to_not have_state(:processing).on(:work)
|
53
|
-
multiple.start
|
54
|
-
expect(multiple).to have_state(:processing).on(:work)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "allow_event" do
|
59
|
-
it "works for simple state machines" do
|
60
|
-
expect(simple).to allow_event :fill_out
|
61
|
-
expect(simple).to_not allow_event :authorise
|
62
|
-
simple.fill_out
|
63
|
-
expect(simple).to allow_event :authorise
|
64
|
-
end
|
65
|
-
|
66
|
-
it "works for multiple state machines" do
|
67
|
-
expect(multiple).to allow_event(:walk).on(:move)
|
68
|
-
expect(multiple).to_not allow_event(:hold).on(:move)
|
69
|
-
multiple.walk
|
70
|
-
expect(multiple).to allow_event(:hold).on(:move)
|
71
|
-
|
72
|
-
expect(multiple).to allow_event(:start).on(:work)
|
73
|
-
expect(multiple).to_not allow_event(:stop).on(:work)
|
74
|
-
multiple.start
|
75
|
-
expect(multiple).to allow_event(:stop).on(:work)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|