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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3935f97b4e0314e076a6a35afc73f4f187058293
4
- data.tar.gz: f2e5c9374a4f1b05729035f14f4909dc7f218518
3
+ metadata.gz: e0c2ed05cead9f7eb53b9e80ac521171b50e8870
4
+ data.tar.gz: f0fbdb3f32090b62685cc82f3584dbda1c145032
5
5
  SHA512:
6
- metadata.gz: 48312c212788cc3b03356ea37dbfa1cd5b73ea881b2f61f6367d3d8ad3eece0c145b79bc47b7c895b222651f887af31ca3695028c2c8f87d43f4e7a166944d42
7
- data.tar.gz: 4e05b6813f79d0374d9f21be4f91567fa09ed5c18fb9dd99ae108be5e1d813f149fbd757b3ee11ff1f9988d0819a3fa81907967cbcdbb0858d8a12c3de27514a
6
+ metadata.gz: 489807212fea0ff23f9c65d735b8d8da649e4f671c0af22b6c5c23027d09be8db843f4c488497889756457b0d7b05427e5b8aa1e7dd7f7788fe6b66fda38bb9d
7
+ data.tar.gz: 2f0622c9e0f6dea50e7495fc036a911b233dd19630449c0f477cd01a03b54c67e5e2896c4c4459ce9732930925e6bb401bb14bb7599895624952d83088d00bdd
@@ -1,3 +1,5 @@
1
+ * Namespaced integrations are not registered by default anymore
2
+
1
3
  * Pass `static: false` in case you don't want initial states to be forced. e.g.
2
4
 
3
5
  ```ruby
@@ -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 = Set.new
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 = Set.new
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
- @integrations << integration if integration.respond_to?(:integration_name)
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,3 +1,3 @@
1
1
  module StateMachines
2
- VERSION = '0.1.4'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -1,19 +1,20 @@
1
1
  require_relative '../../test_helper'
2
2
 
3
3
  class EventWithMatchingDisabledTransitionsTest < StateMachinesTest
4
- def setup
5
- StateMachines::Integrations.const_set('Custom', Module.new do
6
- include StateMachines::Integrations::Base
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
- def invalidate(object, _attribute, message, values = [])
9
- (object.errors ||= []) << generate_message(message, values)
10
- end
11
+ def reset(object)
12
+ object.errors = []
13
+ end
14
+ end
11
15
 
12
- def reset(object)
13
- object.errors = []
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
- def setup
5
- StateMachines::Integrations.const_set('Custom', Module.new do
6
- include StateMachines::Integrations::Base
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
- def invalidate(object, _attribute, message, values = [])
9
- (object.errors ||= []) << generate_message(message, values)
10
- end
11
+ def reset(object)
12
+ object.errors = []
13
+ end
14
+ end
11
15
 
12
- def reset(object)
13
- object.errors = []
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
- def setup
5
- StateMachines::Integrations.const_set('Custom', Module.new do
6
- include StateMachines::Integrations::Base
4
+ module Custom
5
+ include StateMachines::Integrations::Base
7
6
 
8
- def invalidate(object, _attribute, message, values = [])
9
- (object.errors ||= []) << generate_message(message, values)
10
- end
7
+ def invalidate(object, _attribute, message, values = [])
8
+ (object.errors ||= []) << generate_message(message, values)
9
+ end
11
10
 
12
- def reset(object)
13
- object.errors = []
14
- end
15
- end)
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
 
@@ -11,6 +11,6 @@ class IntegrationFinderTest < StateMachinesTest
11
11
  end
12
12
 
13
13
  def test_should_have_no_integrations
14
- assert_equal(Set.new, StateMachines::Integrations.list)
14
+ assert_equal([], StateMachines::Integrations.list)
15
15
  end
16
16
  end
@@ -1,17 +1,16 @@
1
1
  require_relative '../../test_helper'
2
2
 
3
3
  class InvalidTransitionWithIntegrationTest < StateMachinesTest
4
- def setup
5
- StateMachines::Integrations.const_set('Custom', Module.new do
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
- StateMachines::Integrations.register(StateMachines::Integrations::Custom)
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
- def setup
5
- integration = Module.new do
6
- include StateMachines::Integrations::Base
4
+ module Custom
5
+ include StateMachines::Integrations::Base
7
6
 
8
- def self.matches?(_klass)
9
- false
10
- end
7
+ def self.matches?(_klass)
8
+ false
11
9
  end
12
- StateMachines::Integrations.const_set('Custom', integration)
13
- StateMachines::Integrations.register(StateMachines::Integrations::Custom)
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?(StateMachines::Integrations::Custom))
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.send(:remove_const, 'Custom')
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
- def setup
6
- StateMachines::Integrations.reset
7
- integration = Module.new do
8
- include StateMachines::Integrations::Base
5
+ module Custom
6
+ include StateMachines::Integrations::Base
9
7
 
10
- def self.matching_ancestors
11
- ['Vehicle']
12
- end
8
+ def self.matching_ancestors
9
+ ['Vehicle']
13
10
  end
11
+ end
14
12
 
15
- StateMachines::Integrations.const_set('Custom', integration)
16
- StateMachines::Integrations.register(StateMachines::Integrations::Custom)
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?(StateMachines::Integrations::Custom))
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
- StateMachines::Integrations::Custom.class_eval do
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?(StateMachines::Integrations::Custom))
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
- StateMachines::Integrations::Custom.class_eval do
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?(StateMachines::Integrations::Custom))
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?(StateMachines::Integrations::Custom))
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?(StateMachines::Integrations::Custom))
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?(StateMachines::Integrations::Custom))
60
+ assert(!(class << machine; ancestors; end).include?(MachineWithCustomIntegrationTest::Custom))
63
61
  end
64
62
 
65
63
  def teardown
66
64
  StateMachines::Integrations.reset
67
- StateMachines::Integrations.send(:remove_const, 'Custom')
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
- def setup
5
- @integration = Module.new do
6
- include StateMachines::Integrations::Base
4
+ module Custom
5
+ include StateMachines::Integrations::Base
7
6
 
8
- def invalidate(object, _attribute, message, values = [])
9
- object.error = generate_message(message, values)
10
- end
7
+ def invalidate(object, _attribute, message, values = [])
8
+ object.error = generate_message(message, values)
11
9
  end
12
- StateMachines::Integrations.const_set('Custom', @integration)
13
- StateMachines::Integrations.register(StateMachines::Integrations::Custom)
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: { invalid_transition: 'cannot %s' })
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
- StateMachines::Integrations::Custom.with_scopes << name
13
+ MachineWithCustomPluralTest::Custom.with_scopes << name
15
14
  lambda {}
16
15
  end
17
16
 
18
17
  def create_without_scope(name)
19
- StateMachines::Integrations::Custom.without_scopes << name
18
+ MachineWithCustomPluralTest::Custom.without_scopes << name
20
19
  lambda {}
21
20
  end
22
21
  end
23
22
 
24
- StateMachines::Integrations.const_set('Custom', @integration)
25
- StateMachines::Integrations.register(StateMachines::Integrations::Custom)
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
- StateMachines::Integrations.send(:remove_const, 'Custom')
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
- @defaults = { action: :save, use_transactions: false }
5
+ module Custom
6
+ include StateMachines::Integrations::Base
7
+
8
+ @defaults = {action: :save, use_transactions: false}
9
9
 
10
- attr_reader :initialized, :with_scopes, :without_scopes, :ran_transaction
10
+ attr_reader :initialized, :with_scopes, :without_scopes, :ran_transaction
11
11
 
12
- def after_initialize
13
- @initialized = true
14
- end
12
+ def after_initialize
13
+ @initialized = true
14
+ end
15
15
 
16
- def create_with_scope(name)
17
- (@with_scopes ||= []) << name
18
- lambda {}
19
- end
16
+ def create_with_scope(name)
17
+ (@with_scopes ||= []) << name
18
+ lambda {}
19
+ end
20
20
 
21
- def create_without_scope(name)
22
- (@without_scopes ||= []) << name
23
- lambda {}
24
- end
21
+ def create_without_scope(name)
22
+ (@without_scopes ||= []) << name
23
+ lambda {}
24
+ end
25
25
 
26
- def transaction(_)
27
- @ran_transaction = true
28
- yield
29
- end
30
- end)
31
- StateMachines::Integrations.register(StateMachines::Integrations::Custom)
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
- def setup
5
- integration = Module.new do
6
- include StateMachines::Integrations::Base
4
+ module Custom
5
+ include StateMachines::Integrations::Base
7
6
 
8
- @defaults = { action: :save }
9
- end
10
- StateMachines::Integrations.const_set('Custom', integration)
11
- StateMachines::Integrations.register(StateMachines::Integrations::Custom)
7
+ @defaults = {action: :save}
8
+ end
12
9
 
13
- @machine = StateMachines::Machine.new(Class.new, action: nil, integration: :custom)
10
+ def setup
11
+ StateMachines::Integrations.register(MachineWithNilActionTest::Custom)
14
12
  end
15
13
 
16
14
  def test_should_have_a_nil_action
17
- assert_nil @machine.action
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
@@ -1,19 +1,20 @@
1
1
  require_relative '../../test_helper'
2
2
 
3
3
  class MachineCollectionFireWithValidationsTest < StateMachinesTest
4
- def setup
5
- StateMachines::Integrations.const_set('Custom', Module.new do
6
- include StateMachines::Integrations::Base
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
- def invalidate(object, _attribute, message, values = [])
9
- (object.errors ||= []) << generate_message(message, values)
10
- end
11
+ def reset(object)
12
+ object.errors = []
13
+ end
14
+ end
11
15
 
12
- def reset(object)
13
- object.errors = []
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.1.4
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-28 00:00:00.000000000 Z
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.2.2
562
+ rubygems_version: 2.4.5
563
563
  signing_key:
564
564
  specification_version: 4
565
565
  summary: State machines for attributes