aasm 4.11.0 → 4.12.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 +4 -4
- data/.travis.yml +16 -17
- data/Appraisals +44 -0
- data/CHANGELOG.md +24 -1
- data/CONTRIBUTING.md +24 -0
- data/Gemfile +4 -21
- data/README.md +81 -34
- data/Rakefile +6 -1
- data/TESTING.md +25 -0
- data/aasm.gemspec +5 -2
- data/gemfiles/rails_3.2.gemfile +13 -0
- data/gemfiles/rails_4.0.gemfile +8 -9
- data/gemfiles/rails_4.2.gemfile +9 -9
- data/gemfiles/rails_4.2_mongoid_5.gemfile +5 -9
- data/gemfiles/rails_5.0.gemfile +7 -16
- data/lib/aasm/aasm.rb +9 -3
- data/lib/aasm/base.rb +3 -1
- data/lib/aasm/configuration.rb +4 -0
- data/lib/aasm/core/event.rb +19 -9
- data/lib/aasm/core/state.rb +7 -0
- data/lib/aasm/core/transition.rb +9 -0
- data/lib/aasm/instance_base.rb +8 -8
- data/lib/aasm/persistence/active_record_persistence.rb +1 -1
- data/lib/aasm/persistence/base.rb +3 -3
- data/lib/aasm/persistence/mongoid_persistence.rb +48 -9
- data/lib/aasm/persistence.rb +0 -3
- data/lib/aasm/state_machine.rb +4 -2
- data/lib/aasm/state_machine_store.rb +5 -2
- data/lib/aasm/version.rb +1 -1
- data/lib/generators/active_record/aasm_generator.rb +1 -1
- data/lib/motion-aasm.rb +0 -1
- data/spec/en.yml +3 -0
- data/spec/generators/active_record_generator_spec.rb +42 -34
- data/spec/generators/mongoid_generator_spec.rb +4 -6
- data/spec/models/{invalid_persistor.rb → active_record/invalid_persistor.rb} +0 -2
- data/spec/models/{silent_persistor.rb → active_record/silent_persistor.rb} +0 -2
- data/spec/models/active_record/simple_new_dsl.rb +2 -2
- data/spec/models/{transactor.rb → active_record/transactor.rb} +0 -2
- data/spec/models/{validator.rb → active_record/validator.rb} +6 -3
- data/spec/models/callbacks/basic.rb +5 -2
- data/spec/models/guard_with_params.rb +24 -0
- data/spec/models/guard_with_params_multiple.rb +18 -0
- data/spec/models/mongoid/invalid_persistor_mongoid.rb +39 -0
- data/spec/models/mongoid/silent_persistor_mongoid.rb +39 -0
- data/spec/models/mongoid/simple_mongoid.rb +2 -2
- data/spec/models/mongoid/validator_mongoid.rb +100 -0
- data/spec/models/multi_transitioner.rb +10 -0
- data/spec/models/multiple_transitions_that_differ_only_by_guard.rb +31 -0
- data/spec/models/parametrised_event.rb +7 -0
- data/spec/models/simple_multiple_example.rb +12 -0
- data/spec/models/sub_class.rb +34 -0
- data/spec/spec_helper.rb +0 -33
- data/spec/spec_helpers/active_record.rb +7 -0
- data/spec/spec_helpers/dynamoid.rb +33 -0
- data/spec/spec_helpers/mongoid.rb +7 -0
- data/spec/spec_helpers/redis.rb +7 -0
- data/spec/spec_helpers/remove_warnings.rb +1 -0
- data/spec/spec_helpers/sequel.rb +7 -0
- data/spec/unit/api_spec.rb +76 -73
- data/spec/unit/callbacks_spec.rb +5 -0
- data/spec/unit/event_spec.rb +12 -0
- data/spec/unit/guard_with_params_multiple_spec.rb +10 -0
- data/spec/unit/guard_with_params_spec.rb +14 -0
- data/spec/unit/inspection_spec.rb +5 -0
- data/spec/unit/localizer_spec.rb +55 -53
- data/spec/unit/multiple_transitions_that_differ_only_by_guard_spec.rb +14 -0
- data/spec/unit/override_warning_spec.rb +8 -0
- data/spec/unit/persistence/active_record_persistence_multiple_spec.rb +452 -445
- data/spec/unit/persistence/active_record_persistence_spec.rb +523 -490
- data/spec/unit/persistence/dynamoid_persistence_multiple_spec.rb +4 -9
- data/spec/unit/persistence/dynamoid_persistence_spec.rb +4 -9
- data/spec/unit/persistence/mongoid_persistence_multiple_spec.rb +87 -10
- data/spec/unit/persistence/mongoid_persistence_spec.rb +89 -10
- data/spec/unit/persistence/redis_persistence_spec.rb +3 -7
- data/spec/unit/persistence/sequel_persistence_multiple_spec.rb +4 -9
- data/spec/unit/persistence/sequel_persistence_spec.rb +4 -9
- data/spec/unit/simple_multiple_example_spec.rb +28 -0
- data/spec/unit/subclassing_multiple_spec.rb +37 -2
- data/spec/unit/subclassing_spec.rb +17 -2
- metadata +77 -32
- data/gemfiles/rails_3.2_stable.gemfile +0 -15
- data/gemfiles/rails_4.0_mongo_mapper.gemfile +0 -17
- data/gemfiles/rails_4.2_mongo_mapper.gemfile +0 -18
- data/lib/aasm/persistence/mongo_mapper_persistence.rb +0 -163
- 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/unit/persistence/mongo_mapper_persistence_multiple_spec.rb +0 -146
- data/spec/unit/persistence/mongo_mapper_persistence_spec.rb +0 -93
- /data/spec/models/{worker.rb → active_record/worker.rb} +0 -0
data/spec/unit/localizer_spec.rb
CHANGED
|
@@ -1,76 +1,78 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
-
require 'active_record'
|
|
3
|
-
require 'i18n'
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
if defined?(ActiceRecord)
|
|
4
|
+
require 'i18n'
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
I18n.load_path << 'spec/en.yml'
|
|
11
|
-
I18n.default_locale = :en
|
|
12
|
-
I18n.reload!
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
after(:all) do
|
|
16
|
-
I18n.load_path.clear
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
let (:foo_opened) { LocalizerTestModel.new }
|
|
20
|
-
let (:foo_closed) { LocalizerTestModel.new.tap { |x| x.aasm_state = :closed } }
|
|
6
|
+
I18n.enforce_available_locales = false
|
|
7
|
+
load_schema
|
|
21
8
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
describe AASM::Localizer, "new style" do
|
|
10
|
+
before(:all) do
|
|
11
|
+
I18n.load_path << 'spec/en.yml'
|
|
12
|
+
I18n.default_locale = :en
|
|
13
|
+
I18n.reload!
|
|
25
14
|
end
|
|
26
15
|
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
after(:all) do
|
|
17
|
+
I18n.load_path.clear
|
|
29
18
|
end
|
|
30
|
-
end
|
|
31
19
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
expect(LocalizerTestModel.aasm.human_event_name(:close)).to eq("Let's close it!")
|
|
35
|
-
end
|
|
20
|
+
let (:foo_opened) { LocalizerTestModel.new }
|
|
21
|
+
let (:foo_closed) { LocalizerTestModel.new.tap { |x| x.aasm_state = :closed } }
|
|
36
22
|
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
context 'aasm.human_state' do
|
|
24
|
+
it 'should return translated state value' do
|
|
25
|
+
expect(foo_opened.aasm.human_state).to eq("It's open now!")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'should return humanized value if not localized' do
|
|
29
|
+
expect(foo_closed.aasm.human_state).to eq("Closed")
|
|
30
|
+
end
|
|
39
31
|
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
32
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
I18n.reload!
|
|
48
|
-
end
|
|
33
|
+
context 'aasm.human_event_name' do
|
|
34
|
+
it 'should return translated event name' do
|
|
35
|
+
expect(LocalizerTestModel.aasm.human_event_name(:close)).to eq("Let's close it!")
|
|
36
|
+
end
|
|
49
37
|
|
|
50
|
-
|
|
51
|
-
|
|
38
|
+
it 'should return humanized event name' do
|
|
39
|
+
expect(LocalizerTestModel.aasm.human_event_name(:open)).to eq("Open")
|
|
40
|
+
end
|
|
41
|
+
end
|
|
52
42
|
end
|
|
53
43
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
expect(foo_opened.aasm.human_state).to eq("It's open now!")
|
|
44
|
+
describe AASM::Localizer, "deprecated style" do
|
|
45
|
+
before(:all) do
|
|
46
|
+
I18n.load_path << 'spec/en_deprecated_style.yml'
|
|
47
|
+
I18n.default_locale = :en
|
|
48
|
+
I18n.reload!
|
|
60
49
|
end
|
|
61
50
|
|
|
62
|
-
|
|
63
|
-
|
|
51
|
+
after(:all) do
|
|
52
|
+
I18n.load_path.clear
|
|
64
53
|
end
|
|
65
|
-
end
|
|
66
54
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
55
|
+
let (:foo_opened) { LocalizerTestModel.new }
|
|
56
|
+
let (:foo_closed) { LocalizerTestModel.new.tap { |x| x.aasm_state = :closed } }
|
|
57
|
+
|
|
58
|
+
context 'aasm.human_state' do
|
|
59
|
+
it 'should return translated state value' do
|
|
60
|
+
expect(foo_opened.aasm.human_state).to eq("It's open now!")
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'should return humanized value if not localized' do
|
|
64
|
+
expect(foo_closed.aasm.human_state).to eq("Closed")
|
|
65
|
+
end
|
|
70
66
|
end
|
|
71
67
|
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
context 'aasm.human_event_name' do
|
|
69
|
+
it 'should return translated event name' do
|
|
70
|
+
expect(LocalizerTestModel.aasm.human_event_name(:close)).to eq("Let's close it!")
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'should return humanized event name' do
|
|
74
|
+
expect(LocalizerTestModel.aasm.human_event_name(:open)).to eq("Open")
|
|
75
|
+
end
|
|
74
76
|
end
|
|
75
77
|
end
|
|
76
78
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "multiple transitions that differ only by guard" do
|
|
4
|
+
let(:job) { MultipleTransitionsThatDifferOnlyByGuard.new }
|
|
5
|
+
|
|
6
|
+
it 'does not follow the first transition if its guard fails' do
|
|
7
|
+
expect{job.go}.not_to raise_error
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'executes the second transition\'s callbacks' do
|
|
11
|
+
job.go
|
|
12
|
+
expect(job.executed_second).to be_truthy
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe 'warns when overrides a method' do
|
|
4
|
+
before do
|
|
5
|
+
AASM::Configuration.hide_warnings = false
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
after do
|
|
9
|
+
AASM::Configuration.hide_warnings = true
|
|
10
|
+
end
|
|
11
|
+
|
|
4
12
|
module Clumsy
|
|
5
13
|
def self.included base
|
|
6
14
|
base.send :include, AASM
|