state_machines 0.1.4 → 0.2.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/Changelog.md +2 -0
- data/lib/state_machines/integrations.rb +5 -19
- data/lib/state_machines/version.rb +1 -1
- data/test/unit/event/event_with_matching_disabled_transitions_test.rb +12 -12
- data/test/unit/event/event_with_matching_enabled_transitions_test.rb +12 -12
- data/test/unit/event_collection/event_collection_with_validations_test.rb +11 -12
- data/test/unit/integrations/integration_finder_test.rb +1 -1
- data/test/unit/invalid_transition/invalid_transition_with_integration_test.rb +8 -10
- data/test/unit/machine/machine_finder_with_existing_machine_on_superclass_test.rb +9 -10
- data/test/unit/machine/machine_with_conflicting_helpers_after_definition_test.rb +13 -12
- data/test/unit/machine/machine_with_conflicting_helpers_before_definition_test.rb +14 -14
- data/test/unit/machine/machine_with_custom_integration_test.rb +21 -18
- data/test/unit/machine/machine_with_custom_invalidation_test.rb +9 -10
- data/test/unit/machine/machine_with_custom_plural_test.rb +5 -6
- data/test/unit/machine/machine_with_integration_test.rb +24 -23
- data/test/unit/machine/machine_with_nil_action_test.rb +13 -10
- data/test/unit/machine_collection/machine_collection_fire_attributes_with_validations_test.rb +12 -12
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0c2ed05cead9f7eb53b9e80ac521171b50e8870
|
4
|
+
data.tar.gz: f0fbdb3f32090b62685cc82f3584dbda1c145032
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 489807212fea0ff23f9c65d735b8d8da649e4f671c0af22b6c5c23027d09be8db843f4c488497889756457b0d7b05427e5b8aa1e7dd7f7788fe6b66fda38bb9d
|
7
|
+
data.tar.gz: 2f0622c9e0f6dea50e7495fc036a911b233dd19630449c0f477cd01a03b54c67e5e2896c4c4459ce9732930925e6bb401bb14bb7599895624952d83088d00bdd
|
data/Changelog.md
CHANGED
@@ -20,7 +20,7 @@ module StateMachines
|
|
20
20
|
# built-in integrations for more information about how to define additional
|
21
21
|
# integrations.
|
22
22
|
module Integrations
|
23
|
-
@integrations =
|
23
|
+
@integrations = []
|
24
24
|
|
25
25
|
class << self
|
26
26
|
# Register integration
|
@@ -34,15 +34,8 @@ module StateMachines
|
|
34
34
|
true
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
|
-
def unregister(name) #:nodoc:#
|
39
|
-
@integrations.delete(name)
|
40
|
-
end
|
41
|
-
|
42
37
|
def reset #:nodoc:#
|
43
|
-
@integrations =
|
44
|
-
name_spaced_integrations
|
45
|
-
true
|
38
|
+
@integrations = []
|
46
39
|
end
|
47
40
|
|
48
41
|
# Gets a list of all of the available integrations for use.
|
@@ -56,7 +49,6 @@ module StateMachines
|
|
56
49
|
# # => [StateMachines::Integrations::ActiveModel]
|
57
50
|
def integrations
|
58
51
|
# Register all namespaced integrations
|
59
|
-
name_spaced_integrations
|
60
52
|
@integrations
|
61
53
|
end
|
62
54
|
|
@@ -114,16 +106,10 @@ module StateMachines
|
|
114
106
|
|
115
107
|
private
|
116
108
|
|
117
|
-
def name_spaced_integrations
|
118
|
-
# FIXME, Integrations should be add before their dependencies.
|
119
|
-
self.constants.reject{ |i| i==:Base }.each do |const|
|
120
|
-
integration = self.const_get(const)
|
121
|
-
add(integration)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
109
|
def add(integration)
|
126
|
-
|
110
|
+
if integration.respond_to?(:integration_name)
|
111
|
+
@integrations.insert(0, integration) unless @integrations.include?(integration)
|
112
|
+
end
|
127
113
|
end
|
128
114
|
end
|
129
115
|
end
|
@@ -1,19 +1,20 @@
|
|
1
1
|
require_relative '../../test_helper'
|
2
2
|
|
3
3
|
class EventWithMatchingDisabledTransitionsTest < StateMachinesTest
|
4
|
-
|
5
|
-
StateMachines::Integrations
|
6
|
-
|
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
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
def reset(object)
|
12
|
+
object.errors = []
|
13
|
+
end
|
14
|
+
end
|
11
15
|
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
end)
|
16
|
-
StateMachines::Integrations.register(StateMachines::Integrations::Custom)
|
16
|
+
def setup
|
17
|
+
StateMachines::Integrations.register(EventWithMatchingDisabledTransitionsTest::Custom)
|
17
18
|
|
18
19
|
@klass = Class.new do
|
19
20
|
attr_accessor :errors
|
@@ -109,7 +110,6 @@ class EventWithMatchingDisabledTransitionsTest < StateMachinesTest
|
|
109
110
|
|
110
111
|
def teardown
|
111
112
|
StateMachines::Integrations.reset
|
112
|
-
StateMachines::Integrations.send(:remove_const, 'Custom')
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
@@ -1,19 +1,20 @@
|
|
1
1
|
require_relative '../../test_helper'
|
2
2
|
|
3
3
|
class EventWithMatchingEnabledTransitionsTest < StateMachinesTest
|
4
|
-
|
5
|
-
StateMachines::Integrations
|
6
|
-
|
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
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
def reset(object)
|
12
|
+
object.errors = []
|
13
|
+
end
|
14
|
+
end
|
11
15
|
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
end)
|
16
|
-
StateMachines::Integrations.register(StateMachines::Integrations::Custom)
|
16
|
+
def setup
|
17
|
+
StateMachines::Integrations.register(EventWithMatchingEnabledTransitionsTest::Custom)
|
17
18
|
|
18
19
|
@klass = Class.new do
|
19
20
|
attr_accessor :errors
|
@@ -69,7 +70,6 @@ class EventWithMatchingEnabledTransitionsTest < StateMachinesTest
|
|
69
70
|
|
70
71
|
def teardown
|
71
72
|
StateMachines::Integrations.reset
|
72
|
-
StateMachines::Integrations.send(:remove_const, 'Custom')
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -1,20 +1,20 @@
|
|
1
1
|
require_relative '../../test_helper'
|
2
2
|
|
3
3
|
class EventCollectionWithValidationsTest < StateMachinesTest
|
4
|
-
|
5
|
-
StateMachines::Integrations
|
6
|
-
include StateMachines::Integrations::Base
|
4
|
+
module Custom
|
5
|
+
include StateMachines::Integrations::Base
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
def invalidate(object, _attribute, message, values = [])
|
8
|
+
(object.errors ||= []) << generate_message(message, values)
|
9
|
+
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
StateMachines::Integrations.register(StateMachines::Integrations::Custom)
|
11
|
+
def reset(object)
|
12
|
+
object.errors = []
|
13
|
+
end
|
14
|
+
end
|
17
15
|
|
16
|
+
def setup
|
17
|
+
StateMachines::Integrations.register(EventCollectionWithValidationsTest::Custom)
|
18
18
|
|
19
19
|
@klass = Class.new do
|
20
20
|
attr_accessor :errors
|
@@ -69,7 +69,6 @@ class EventCollectionWithValidationsTest < StateMachinesTest
|
|
69
69
|
|
70
70
|
def teardown
|
71
71
|
StateMachines::Integrations.reset
|
72
|
-
StateMachines::Integrations.send(:remove_const, 'Custom')
|
73
72
|
end
|
74
73
|
end
|
75
74
|
|
@@ -1,17 +1,16 @@
|
|
1
1
|
require_relative '../../test_helper'
|
2
2
|
|
3
3
|
class InvalidTransitionWithIntegrationTest < StateMachinesTest
|
4
|
-
|
5
|
-
StateMachines::Integrations
|
6
|
-
include StateMachines::Integrations::Base
|
7
|
-
|
8
|
-
def errors_for(object)
|
9
|
-
object.errors
|
10
|
-
end
|
11
|
-
end)
|
4
|
+
module Custom
|
5
|
+
include StateMachines::Integrations::Base
|
12
6
|
|
13
|
-
|
7
|
+
def errors_for(object)
|
8
|
+
object.errors
|
9
|
+
end
|
10
|
+
end
|
14
11
|
|
12
|
+
def setup
|
13
|
+
StateMachines::Integrations.register(InvalidTransitionWithIntegrationTest::Custom)
|
15
14
|
|
16
15
|
@klass = Class.new do
|
17
16
|
attr_accessor :errors
|
@@ -42,6 +41,5 @@ class InvalidTransitionWithIntegrationTest < StateMachinesTest
|
|
42
41
|
|
43
42
|
def teardown
|
44
43
|
StateMachines::Integrations.reset
|
45
|
-
StateMachines::Integrations.send(:remove_const, 'Custom')
|
46
44
|
end
|
47
45
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require_relative '../../test_helper'
|
2
2
|
|
3
3
|
class MachineFinderWithExistingMachineOnSuperclassTest < StateMachinesTest
|
4
|
-
|
5
|
-
|
6
|
-
include StateMachines::Integrations::Base
|
4
|
+
module Custom
|
5
|
+
include StateMachines::Integrations::Base
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
7
|
+
def self.matches?(_klass)
|
8
|
+
false
|
11
9
|
end
|
12
|
-
|
13
|
-
|
10
|
+
end
|
11
|
+
|
12
|
+
def setup
|
13
|
+
StateMachines::Integrations.register(MachineFinderWithExistingMachineOnSuperclassTest::Custom)
|
14
14
|
|
15
15
|
@base_class = Class.new
|
16
16
|
@base_machine = StateMachines::Machine.new(@base_class, :status, action: :save, integration: :custom)
|
@@ -76,11 +76,10 @@ class MachineFinderWithExistingMachineOnSuperclassTest < StateMachinesTest
|
|
76
76
|
ancestors
|
77
77
|
end
|
78
78
|
|
79
|
-
assert(class_ancestors.include?(
|
79
|
+
assert(class_ancestors.include?(MachineFinderWithExistingMachineOnSuperclassTest::Custom))
|
80
80
|
end
|
81
81
|
|
82
82
|
def teardown
|
83
83
|
StateMachines::Integrations.reset
|
84
|
-
StateMachines::Integrations.send(:remove_const, 'Custom')
|
85
84
|
end
|
86
85
|
end
|
@@ -1,9 +1,20 @@
|
|
1
1
|
require_relative '../../test_helper'
|
2
2
|
|
3
3
|
class MachineWithConflictingHelpersAfterDefinitionTest < StateMachinesTest
|
4
|
+
module Custom
|
5
|
+
include StateMachines::Integrations::Base
|
6
|
+
|
7
|
+
def create_with_scope(_name)
|
8
|
+
->(_klass, _values) { [] }
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_without_scope(_name)
|
12
|
+
->(_klass, _values) { [] }
|
13
|
+
end
|
14
|
+
end
|
4
15
|
def setup
|
5
16
|
@original_stderr, $stderr = $stderr, StringIO.new
|
6
|
-
|
17
|
+
StateMachines::Integrations.register(MachineWithConflictingHelpersAfterDefinitionTest::Custom)
|
7
18
|
@klass = Class.new do
|
8
19
|
def self.with_state
|
9
20
|
:with_state
|
@@ -68,17 +79,7 @@ class MachineWithConflictingHelpersAfterDefinitionTest < StateMachinesTest
|
|
68
79
|
end
|
69
80
|
end
|
70
81
|
|
71
|
-
StateMachines::Integrations.const_set('Custom', Module.new do
|
72
|
-
include StateMachines::Integrations::Base
|
73
|
-
|
74
|
-
def create_with_scope(_name)
|
75
|
-
lambda { |_klass, _values| [] }
|
76
|
-
end
|
77
82
|
|
78
|
-
def create_without_scope(_name)
|
79
|
-
lambda { |_klass, _values| [] }
|
80
|
-
end
|
81
|
-
end)
|
82
83
|
|
83
84
|
@machine = StateMachines::Machine.new(@klass, integration: :custom)
|
84
85
|
@machine.state :parked, :idling
|
@@ -238,6 +239,6 @@ class MachineWithConflictingHelpersAfterDefinitionTest < StateMachinesTest
|
|
238
239
|
|
239
240
|
def teardown
|
240
241
|
$stderr = @original_stderr
|
241
|
-
StateMachines::Integrations.
|
242
|
+
StateMachines::Integrations.reset
|
242
243
|
end
|
243
244
|
end
|
@@ -1,9 +1,23 @@
|
|
1
1
|
require_relative '../../test_helper'
|
2
2
|
|
3
3
|
class MachineWithConflictingHelpersBeforeDefinitionTest < StateMachinesTest
|
4
|
+
module Custom
|
5
|
+
include StateMachines::Integrations::Base
|
6
|
+
|
7
|
+
def create_with_scope(_name)
|
8
|
+
lambda { |_klass, _values| [] }
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_without_scope(_name)
|
12
|
+
lambda { |_klass, _values| [] }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
4
16
|
def setup
|
5
17
|
@original_stderr, $stderr = $stderr, StringIO.new
|
6
18
|
|
19
|
+
StateMachines::Integrations.register(MachineWithConflictingHelpersBeforeDefinitionTest::Custom)
|
20
|
+
|
7
21
|
@superclass = Class.new do
|
8
22
|
def self.with_state
|
9
23
|
:with_state
|
@@ -68,19 +82,6 @@ class MachineWithConflictingHelpersBeforeDefinitionTest < StateMachinesTest
|
|
68
82
|
end
|
69
83
|
end
|
70
84
|
@klass = Class.new(@superclass)
|
71
|
-
|
72
|
-
StateMachines::Integrations.const_set('Custom', Module.new do
|
73
|
-
include StateMachines::Integrations::Base
|
74
|
-
|
75
|
-
def create_with_scope(_name)
|
76
|
-
lambda { |_klass, _values| [] }
|
77
|
-
end
|
78
|
-
|
79
|
-
def create_without_scope(_name)
|
80
|
-
lambda { |_klass, _values| [] }
|
81
|
-
end
|
82
|
-
end)
|
83
|
-
|
84
85
|
@machine = StateMachines::Machine.new(@klass, integration: :custom)
|
85
86
|
@machine.state :parked, :idling
|
86
87
|
@machine.event :ignite
|
@@ -169,7 +170,6 @@ class MachineWithConflictingHelpersBeforeDefinitionTest < StateMachinesTest
|
|
169
170
|
|
170
171
|
def teardown
|
171
172
|
$stderr = @original_stderr
|
172
|
-
StateMachines::Integrations.send(:remove_const, 'Custom')
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|
@@ -2,29 +2,27 @@ require_relative '../../test_helper'
|
|
2
2
|
require_relative '../../../test/files/models/vehicle'
|
3
3
|
|
4
4
|
class MachineWithCustomIntegrationTest < StateMachinesTest
|
5
|
-
|
6
|
-
StateMachines::Integrations
|
7
|
-
integration = Module.new do
|
8
|
-
include StateMachines::Integrations::Base
|
5
|
+
module Custom
|
6
|
+
include StateMachines::Integrations::Base
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
end
|
8
|
+
def self.matching_ancestors
|
9
|
+
['Vehicle']
|
13
10
|
end
|
11
|
+
end
|
14
12
|
|
15
|
-
|
16
|
-
StateMachines::Integrations.register(
|
13
|
+
def setup
|
14
|
+
StateMachines::Integrations.register(MachineWithCustomIntegrationTest::Custom)
|
17
15
|
|
18
16
|
@klass = Vehicle
|
19
17
|
end
|
20
18
|
|
21
19
|
def test_should_be_extended_by_the_integration_if_explicit
|
22
20
|
machine = StateMachines::Machine.new(@klass, integration: :custom)
|
23
|
-
assert((class << machine; ancestors; end).include?(
|
21
|
+
assert((class << machine; ancestors; end).include?(MachineWithCustomIntegrationTest::Custom))
|
24
22
|
end
|
25
23
|
|
26
24
|
def test_should_not_be_extended_by_the_integration_if_implicit_but_not_available
|
27
|
-
|
25
|
+
MachineWithCustomIntegrationTest::Custom.class_eval do
|
28
26
|
class << self; remove_method :matching_ancestors; end
|
29
27
|
def self.matching_ancestors
|
30
28
|
[]
|
@@ -32,11 +30,11 @@ class MachineWithCustomIntegrationTest < StateMachinesTest
|
|
32
30
|
end
|
33
31
|
|
34
32
|
machine = StateMachines::Machine.new(@klass)
|
35
|
-
assert(!(class << machine; ancestors; end).include?(
|
33
|
+
assert(!(class << machine; ancestors; end).include?(MachineWithCustomIntegrationTest::Custom))
|
36
34
|
end
|
37
35
|
|
38
36
|
def test_should_not_be_extended_by_the_integration_if_implicit_but_not_matched
|
39
|
-
|
37
|
+
MachineWithCustomIntegrationTest::Custom.class_eval do
|
40
38
|
class << self; remove_method :matching_ancestors; end
|
41
39
|
def self.matching_ancestors
|
42
40
|
[]
|
@@ -44,26 +42,31 @@ class MachineWithCustomIntegrationTest < StateMachinesTest
|
|
44
42
|
end
|
45
43
|
|
46
44
|
machine = StateMachines::Machine.new(@klass)
|
47
|
-
assert(!(class << machine; ancestors; end).include?(
|
45
|
+
assert(!(class << machine; ancestors; end).include?(MachineWithCustomIntegrationTest::Custom))
|
48
46
|
end
|
49
47
|
|
50
48
|
def test_should_be_extended_by_the_integration_if_implicit_and_available_and_matches
|
51
49
|
machine = StateMachines::Machine.new(@klass)
|
52
|
-
assert((class << machine; ancestors; end).include?(
|
50
|
+
assert((class << machine; ancestors; end).include?(MachineWithCustomIntegrationTest::Custom))
|
53
51
|
end
|
54
52
|
|
55
53
|
def test_should_not_be_extended_by_the_integration_if_nil
|
56
54
|
machine = StateMachines::Machine.new(@klass, integration: nil)
|
57
|
-
assert(!(class << machine; ancestors; end).include?(
|
55
|
+
assert(!(class << machine; ancestors; end).include?(MachineWithCustomIntegrationTest::Custom))
|
58
56
|
end
|
59
57
|
|
60
58
|
def test_should_not_be_extended_by_the_integration_if_false
|
61
59
|
machine = StateMachines::Machine.new(@klass, integration: false)
|
62
|
-
assert(!(class << machine; ancestors; end).include?(
|
60
|
+
assert(!(class << machine; ancestors; end).include?(MachineWithCustomIntegrationTest::Custom))
|
63
61
|
end
|
64
62
|
|
65
63
|
def teardown
|
66
64
|
StateMachines::Integrations.reset
|
67
|
-
|
65
|
+
MachineWithCustomIntegrationTest::Custom.class_eval do
|
66
|
+
class << self; remove_method :matching_ancestors; end
|
67
|
+
def self.matching_ancestors
|
68
|
+
['Vehicle']
|
69
|
+
end
|
70
|
+
end
|
68
71
|
end
|
69
72
|
end
|
@@ -1,22 +1,22 @@
|
|
1
1
|
require_relative '../../test_helper'
|
2
2
|
|
3
3
|
class MachineWithCustomInvalidationTest < StateMachinesTest
|
4
|
-
|
5
|
-
|
6
|
-
include StateMachines::Integrations::Base
|
4
|
+
module Custom
|
5
|
+
include StateMachines::Integrations::Base
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
7
|
+
def invalidate(object, _attribute, message, values = [])
|
8
|
+
object.error = generate_message(message, values)
|
11
9
|
end
|
12
|
-
|
13
|
-
|
10
|
+
end
|
11
|
+
|
12
|
+
def setup
|
13
|
+
StateMachines::Integrations.register(MachineWithCustomInvalidationTest::Custom)
|
14
14
|
|
15
15
|
@klass = Class.new do
|
16
16
|
attr_accessor :error
|
17
17
|
end
|
18
18
|
|
19
|
-
@machine = StateMachines::Machine.new(@klass, integration: :custom, messages: {
|
19
|
+
@machine = StateMachines::Machine.new(@klass, integration: :custom, messages: {invalid_transition: 'cannot %s'})
|
20
20
|
@machine.state :parked
|
21
21
|
|
22
22
|
@object = @klass.new
|
@@ -34,7 +34,6 @@ class MachineWithCustomInvalidationTest < StateMachinesTest
|
|
34
34
|
|
35
35
|
def teardown
|
36
36
|
StateMachines::Integrations.reset
|
37
|
-
StateMachines::Integrations.send(:remove_const, 'Custom')
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
@@ -2,7 +2,6 @@ require_relative '../../test_helper'
|
|
2
2
|
|
3
3
|
class MachineWithCustomPluralTest < StateMachinesTest
|
4
4
|
def setup
|
5
|
-
StateMachines::Integrations.reset
|
6
5
|
@integration = Module.new do
|
7
6
|
include StateMachines::Integrations::Base
|
8
7
|
|
@@ -11,18 +10,18 @@ class MachineWithCustomPluralTest < StateMachinesTest
|
|
11
10
|
@without_scopes = []
|
12
11
|
|
13
12
|
def create_with_scope(name)
|
14
|
-
|
13
|
+
MachineWithCustomPluralTest::Custom.with_scopes << name
|
15
14
|
lambda {}
|
16
15
|
end
|
17
16
|
|
18
17
|
def create_without_scope(name)
|
19
|
-
|
18
|
+
MachineWithCustomPluralTest::Custom.without_scopes << name
|
20
19
|
lambda {}
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
|
-
|
25
|
-
StateMachines::Integrations.register(
|
23
|
+
MachineWithCustomPluralTest.const_set('Custom', @integration)
|
24
|
+
StateMachines::Integrations.register(MachineWithCustomPluralTest::Custom)
|
26
25
|
end
|
27
26
|
|
28
27
|
def test_should_define_a_singular_and_plural_with_scope
|
@@ -47,7 +46,7 @@ class MachineWithCustomPluralTest < StateMachinesTest
|
|
47
46
|
|
48
47
|
def teardown
|
49
48
|
StateMachines::Integrations.reset
|
50
|
-
|
49
|
+
MachineWithCustomPluralTest.send(:remove_const, 'Custom')
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
@@ -1,34 +1,36 @@
|
|
1
1
|
require_relative '../../test_helper'
|
2
2
|
|
3
3
|
class MachineWithIntegrationTest < StateMachinesTest
|
4
|
-
def setup
|
5
|
-
StateMachines::Integrations.const_set('Custom', Module.new do
|
6
|
-
include StateMachines::Integrations::Base
|
7
4
|
|
8
|
-
|
5
|
+
module Custom
|
6
|
+
include StateMachines::Integrations::Base
|
7
|
+
|
8
|
+
@defaults = {action: :save, use_transactions: false}
|
9
9
|
|
10
|
-
|
10
|
+
attr_reader :initialized, :with_scopes, :without_scopes, :ran_transaction
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def after_initialize
|
13
|
+
@initialized = true
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def create_with_scope(name)
|
17
|
+
(@with_scopes ||= []) << name
|
18
|
+
lambda {}
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
def create_without_scope(name)
|
22
|
+
(@without_scopes ||= []) << name
|
23
|
+
lambda {}
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
def transaction(_)
|
27
|
+
@ran_transaction = true
|
28
|
+
yield
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def setup
|
33
|
+
StateMachines::Integrations.register(MachineWithIntegrationTest::Custom)
|
32
34
|
|
33
35
|
|
34
36
|
@machine = StateMachines::Machine.new(Class.new, integration: :custom)
|
@@ -66,6 +68,5 @@ class MachineWithIntegrationTest < StateMachinesTest
|
|
66
68
|
|
67
69
|
def teardown
|
68
70
|
StateMachines::Integrations.reset
|
69
|
-
StateMachines::Integrations.send(:remove_const, 'Custom')
|
70
71
|
end
|
71
72
|
end
|
@@ -1,24 +1,27 @@
|
|
1
1
|
require_relative '../../test_helper'
|
2
2
|
|
3
3
|
class MachineWithNilActionTest < StateMachinesTest
|
4
|
-
|
5
|
-
|
6
|
-
include StateMachines::Integrations::Base
|
4
|
+
module Custom
|
5
|
+
include StateMachines::Integrations::Base
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
StateMachines::Integrations.const_set('Custom', integration)
|
11
|
-
StateMachines::Integrations.register(StateMachines::Integrations::Custom)
|
7
|
+
@defaults = {action: :save}
|
8
|
+
end
|
12
9
|
|
13
|
-
|
10
|
+
def setup
|
11
|
+
StateMachines::Integrations.register(MachineWithNilActionTest::Custom)
|
14
12
|
end
|
15
13
|
|
16
14
|
def test_should_have_a_nil_action
|
17
|
-
|
15
|
+
machine = StateMachines::Machine.new(Class.new, action: nil, integration: :custom)
|
16
|
+
assert_nil machine.action
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_should_have_default_action
|
20
|
+
machine = StateMachines::Machine.new(Class.new, integration: :custom)
|
21
|
+
assert_equal :save, machine.action
|
18
22
|
end
|
19
23
|
|
20
24
|
def teardown
|
21
25
|
StateMachines::Integrations.reset
|
22
|
-
StateMachines::Integrations.send(:remove_const, 'Custom')
|
23
26
|
end
|
24
27
|
end
|
data/test/unit/machine_collection/machine_collection_fire_attributes_with_validations_test.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
require_relative '../../test_helper'
|
2
2
|
|
3
3
|
class MachineCollectionFireWithValidationsTest < StateMachinesTest
|
4
|
-
|
5
|
-
StateMachines::Integrations
|
6
|
-
|
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
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
def reset(object)
|
12
|
+
object.errors = []
|
13
|
+
end
|
14
|
+
end
|
11
15
|
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
end)
|
16
|
-
StateMachines::Integrations.register(StateMachines::Integrations::Custom)
|
16
|
+
def setup
|
17
|
+
StateMachines::Integrations.register(MachineCollectionFireWithValidationsTest::Custom)
|
17
18
|
|
18
19
|
@klass = Class.new do
|
19
20
|
attr_accessor :errors
|
@@ -66,7 +67,6 @@ class MachineCollectionFireWithValidationsTest < StateMachinesTest
|
|
66
67
|
|
67
68
|
def teardown
|
68
69
|
StateMachines::Integrations.reset
|
69
|
-
StateMachines::Integrations.send(:remove_const, 'Custom')
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: state_machines
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abdelkader Boudih
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-01-
|
12
|
+
date: 2015-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -559,7 +559,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
559
559
|
version: '0'
|
560
560
|
requirements: []
|
561
561
|
rubyforge_project:
|
562
|
-
rubygems_version: 2.
|
562
|
+
rubygems_version: 2.4.5
|
563
563
|
signing_key:
|
564
564
|
specification_version: 4
|
565
565
|
summary: State machines for attributes
|