state_machines 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +2 -0
- data/Changelog.md +7 -1
- data/README.md +11 -9
- data/lib/state_machines/extensions.rb +1 -1
- data/lib/state_machines/integrations.rb +1 -5
- data/lib/state_machines/integrations/base.rb +2 -5
- data/lib/state_machines/machine.rb +14 -10
- data/lib/state_machines/path_collection.rb +3 -3
- data/lib/state_machines/state.rb +21 -16
- data/lib/state_machines/state_collection.rb +1 -1
- data/lib/state_machines/transition.rb +1 -1
- data/lib/state_machines/transition_collection.rb +2 -2
- data/lib/state_machines/version.rb +1 -1
- data/state_machines.gemspec +1 -2
- data/test/files/integrations/vehicle.rb +1 -1
- data/test/files/models/driver.rb +13 -0
- data/test/files/models/motorcycle.rb +5 -0
- data/test/functional/driver_default_nonstandard_test.rb +13 -0
- data/test/functional/motorcycle_test.rb +6 -0
- data/test/unit/event/event_with_matching_disabled_transitions_test.rb +1 -1
- data/test/unit/event/event_with_transition_with_nil_to_state_test.rb +2 -2
- data/test/unit/integrations/integration_matcher_test.rb +4 -2
- data/test/unit/machine/machine_with_custom_integration_test.rb +2 -2
- data/test/unit/transition_collection/transition_collection_empty_with_block_test.rb +1 -1
- data/test/unit/transition_collection/transition_collection_with_after_callback_halt_test.rb +10 -14
- data/test/unit/transition_collection/transition_collection_with_before_callback_halt_test.rb +14 -10
- metadata +9 -426
- data/test/unit/branch/branch_with_multiple_on_requirements_test.rb +0 -20
- data/test/unit/machine_collection/machine_collection_fire_attributes_with_validations_test.rb +0 -72
@@ -1,20 +0,0 @@
|
|
1
|
-
require_relative '../../test_helper'
|
2
|
-
|
3
|
-
class BranchWithMultipleExceptToRequirementsTest < StateMachinesTest
|
4
|
-
def setup
|
5
|
-
@object = Object.new
|
6
|
-
@branch = StateMachines::Branch.new(except_to: [:idling, :parked])
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_should_match_if_not_included
|
10
|
-
assert @branch.matches?(@object, to: :first_gear)
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_should_not_match_if_included
|
14
|
-
refute @branch.matches?(@object, to: :idling)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_should_be_included_in_known_states
|
18
|
-
assert_equal [:idling, :parked], @branch.known_states
|
19
|
-
end
|
20
|
-
end
|
data/test/unit/machine_collection/machine_collection_fire_attributes_with_validations_test.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require_relative '../../test_helper'
|
2
|
-
|
3
|
-
class MachineCollectionFireWithValidationsTest < StateMachinesTest
|
4
|
-
module Custom
|
5
|
-
include StateMachines::Integrations::Base
|
6
|
-
|
7
|
-
def invalidate(object, _attribute, message, values = [])
|
8
|
-
(object.errors ||= []) << generate_message(message, values)
|
9
|
-
end
|
10
|
-
|
11
|
-
def reset(object)
|
12
|
-
object.errors = []
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def setup
|
17
|
-
StateMachines::Integrations.register(MachineCollectionFireWithValidationsTest::Custom)
|
18
|
-
|
19
|
-
@klass = Class.new do
|
20
|
-
attr_accessor :errors
|
21
|
-
|
22
|
-
def initialize
|
23
|
-
@errors = []
|
24
|
-
super
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
@machines = StateMachines::MachineCollection.new
|
29
|
-
@machines[:state] = @state = StateMachines::Machine.new(@klass, :state, initial: :parked, integration: :custom)
|
30
|
-
@state.event :ignite do
|
31
|
-
transition parked: :idling
|
32
|
-
end
|
33
|
-
|
34
|
-
@machines[:alarm_state] = @alarm_state = StateMachines::Machine.new(@klass, :alarm_state, initial: :active, namespace: 'alarm', integration: :custom)
|
35
|
-
@alarm_state.event :disable do
|
36
|
-
transition active: :off
|
37
|
-
end
|
38
|
-
|
39
|
-
@object = @klass.new
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_should_not_invalidate_if_transitions_exist
|
43
|
-
assert @machines.fire_events(@object, :ignite, :disable_alarm)
|
44
|
-
assert_equal [], @object.errors
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_should_invalidate_if_no_transitions_exist
|
48
|
-
@object.state = 'idling'
|
49
|
-
@object.alarm_state = 'off'
|
50
|
-
|
51
|
-
refute @machines.fire_events(@object, :ignite, :disable_alarm)
|
52
|
-
assert_equal ['cannot transition via "ignite"', 'cannot transition via "disable"'], @object.errors
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_should_run_failure_callbacks_if_no_transitions_exist
|
56
|
-
@object.state = 'idling'
|
57
|
-
@object.alarm_state = 'off'
|
58
|
-
@state_failure_run = @alarm_state_failure_run = false
|
59
|
-
|
60
|
-
@machines[:state].after_failure { @state_failure_run = true }
|
61
|
-
@machines[:alarm_state].after_failure { @alarm_state_failure_run = true }
|
62
|
-
|
63
|
-
refute @machines.fire_events(@object, :ignite, :disable_alarm)
|
64
|
-
assert @state_failure_run
|
65
|
-
assert @alarm_state_failure_run
|
66
|
-
end
|
67
|
-
|
68
|
-
def teardown
|
69
|
-
StateMachines::Integrations.reset
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|