state_machines-activerecord 0.10.0 → 0.40.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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -1
  3. data/lib/state_machines/integrations/active_record/locale.rb +10 -9
  4. data/lib/state_machines/integrations/active_record/version.rb +1 -1
  5. data/lib/state_machines/integrations/active_record.rb +52 -31
  6. metadata +35 -138
  7. data/test/files/en.yml +0 -5
  8. data/test/files/models/post.rb +0 -13
  9. data/test/integration_test.rb +0 -27
  10. data/test/machine_by_default_test.rb +0 -18
  11. data/test/machine_errors_test.rb +0 -21
  12. data/test/machine_multiple_test.rb +0 -19
  13. data/test/machine_nested_action_test.rb +0 -40
  14. data/test/machine_unmigrated_test.rb +0 -16
  15. data/test/machine_with_aliased_attribute_test.rb +0 -25
  16. data/test/machine_with_callbacks_test.rb +0 -174
  17. data/test/machine_with_column_state_attribute_test.rb +0 -46
  18. data/test/machine_with_complex_pluralization_scopes_test.rb +0 -18
  19. data/test/machine_with_conflicting_predicate_test.rb +0 -20
  20. data/test/machine_with_conflicting_state_name_test.rb +0 -31
  21. data/test/machine_with_custom_attribute_test.rb +0 -23
  22. data/test/machine_with_default_scope_test.rb +0 -20
  23. data/test/machine_with_different_column_default_test.rb +0 -29
  24. data/test/machine_with_different_integer_column_default_test.rb +0 -31
  25. data/test/machine_with_dirty_attribute_and_custom_attributes_during_loopback_test.rb +0 -26
  26. data/test/machine_with_dirty_attribute_and_state_events_test.rb +0 -22
  27. data/test/machine_with_dirty_attributes_and_custom_attribute_test.rb +0 -34
  28. data/test/machine_with_dirty_attributes_during_loopback_test.rb +0 -24
  29. data/test/machine_with_dirty_attributes_test.rb +0 -37
  30. data/test/machine_with_dynamic_initial_state_test.rb +0 -101
  31. data/test/machine_with_event_attributes_on_autosave_test.rb +0 -50
  32. data/test/machine_with_event_attributes_on_custom_action_test.rb +0 -43
  33. data/test/machine_with_event_attributes_on_save_bang_test.rb +0 -84
  34. data/test/machine_with_event_attributes_on_save_test.rb +0 -246
  35. data/test/machine_with_event_attributes_on_validation_test.rb +0 -145
  36. data/test/machine_with_events_test.rb +0 -15
  37. data/test/machine_with_failed_action_test.rb +0 -42
  38. data/test/machine_with_failed_after_callbacks_test.rb +0 -37
  39. data/test/machine_with_failed_before_callbacks_test.rb +0 -38
  40. data/test/machine_with_initialized_state_test.rb +0 -43
  41. data/test/machine_with_internationalization_test.rb +0 -182
  42. data/test/machine_with_loopback_test.rb +0 -24
  43. data/test/machine_with_non_column_state_attribute_defined_test.rb +0 -31
  44. data/test/machine_with_same_column_default_test.rb +0 -28
  45. data/test/machine_with_same_integer_column_default_test.rb +0 -32
  46. data/test/machine_with_scopes_and_joins_test.rb +0 -40
  47. data/test/machine_with_scopes_and_owner_subclass_test.rb +0 -29
  48. data/test/machine_with_scopes_test.rb +0 -72
  49. data/test/machine_with_state_driven_validations_test.rb +0 -32
  50. data/test/machine_with_states_test.rb +0 -15
  51. data/test/machine_with_static_initial_state_test.rb +0 -169
  52. data/test/machine_with_transactions_test.rb +0 -28
  53. data/test/machine_with_validations_and_custom_attribute_test.rb +0 -23
  54. data/test/machine_with_validations_test.rb +0 -49
  55. data/test/machine_without_database_test.rb +0 -22
  56. data/test/machine_without_transactions_test.rb +0 -28
  57. data/test/model_test.rb +0 -14
  58. data/test/test_helper.rb +0 -57
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'test_helper'
4
-
5
- class MachineWithEventAttributesOnAutosaveTest < BaseTestCase
6
- def setup
7
- @vehicle_model = new_model(:vehicle) do
8
- connection.add_column table_name, :owner_id, :integer
9
- end
10
- MachineWithEventAttributesOnAutosaveTest.const_set('Vehicle', @vehicle_model)
11
-
12
- @owner_model = new_model(:owner)
13
- MachineWithEventAttributesOnAutosaveTest.const_set('Owner', @owner_model)
14
-
15
- machine = StateMachines::Machine.new(@vehicle_model)
16
- machine.event :ignite do
17
- transition :parked => :idling
18
- end
19
-
20
- @owner = @owner_model.create
21
- @vehicle = @vehicle_model.create(:state => 'parked', :owner_id => @owner.id)
22
- end
23
-
24
- def test_should_persist_has_one_autosave
25
- @owner_model.has_one :vehicle, :class_name => 'MachineWithEventAttributesOnAutosaveTest::Vehicle', :autosave => true
26
- @owner.vehicle.state_event = 'ignite'
27
- @owner.save
28
-
29
- @vehicle.reload
30
- assert_equal 'idling', @vehicle.state
31
- end
32
-
33
- def test_should_persist_has_many_autosave
34
- @owner_model.has_many :vehicles, :class_name => 'MachineWithEventAttributesOnAutosaveTest::Vehicle', :autosave => true
35
- @owner.vehicles[0].state_event = 'ignite'
36
- @owner.save
37
-
38
- @vehicle.reload
39
- assert_equal 'idling', @vehicle.state
40
- end
41
-
42
- def teardown
43
- MachineWithEventAttributesOnAutosaveTest.class_eval do
44
- remove_const('Vehicle')
45
- remove_const('Owner')
46
- end
47
- clear_active_support_dependencies
48
- super
49
- end
50
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'test_helper'
4
-
5
- class MachineWithEventAttributesOnCustomActionTest < BaseTestCase
6
- def setup
7
- @superclass = new_model do
8
- def persist
9
- create_or_update
10
- end
11
- end
12
- @model = Class.new(@superclass)
13
- @machine = StateMachines::Machine.new(@model, :action => :persist)
14
- @machine.event :ignite do
15
- transition :parked => :idling
16
- end
17
-
18
- @record = @model.new
19
- @record.state = 'parked'
20
- @record.state_event = 'ignite'
21
- end
22
-
23
- def test_should_not_transition_on_valid?
24
- @record.valid?
25
- assert_equal 'parked', @record.state
26
- end
27
-
28
- def test_should_not_transition_on_save
29
- @record.save
30
- assert_equal 'parked', @record.state
31
- end
32
-
33
- def test_should_not_transition_on_save!
34
- @record.save!
35
- assert_equal 'parked', @record.state
36
- end
37
-
38
- def test_should_transition_on_custom_action
39
- @record.persist
40
- assert_equal 'idling', @record.state
41
- end
42
- end
43
-
@@ -1,84 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'test_helper'
4
-
5
- class MachineWithEventAttributesOnSaveBangTest < BaseTestCase
6
- def setup
7
- @model = new_model
8
- @machine = StateMachines::Machine.new(@model)
9
- @machine.event :ignite do
10
- transition :parked => :idling
11
- end
12
-
13
- @record = @model.new
14
- @record.state = 'parked'
15
- @record.state_event = 'ignite'
16
- end
17
-
18
- def test_should_fail_if_event_is_invalid
19
- @record.state_event = 'invalid'
20
- assert_raise(ActiveRecord::RecordInvalid) { @record.save! }
21
- end
22
-
23
- def test_should_fail_if_event_has_no_transition
24
- @record.state = 'idling'
25
- assert_raise(ActiveRecord::RecordInvalid) { @record.save! }
26
- end
27
-
28
- def test_should_be_successful_if_event_has_transition
29
- assert_equal true, @record.save!
30
- end
31
-
32
- def test_should_run_before_callbacks
33
- ran_callback = false
34
- @machine.before_transition { ran_callback = true }
35
-
36
- @record.save!
37
- assert ran_callback
38
- end
39
-
40
- def test_should_run_before_callbacks_once
41
- before_count = 0
42
- @machine.before_transition { before_count += 1 }
43
-
44
- @record.save!
45
- assert_equal 1, before_count
46
- end
47
-
48
- def test_should_run_around_callbacks_before_yield
49
- ran_callback = false
50
- @machine.around_transition { |block| ran_callback = true; block.call }
51
-
52
- @record.save!
53
- assert ran_callback
54
- end
55
-
56
- def test_should_run_around_callbacks_before_yield_once
57
- around_before_count = 0
58
- @machine.around_transition { |block| around_before_count += 1; block.call }
59
-
60
- @record.save!
61
- assert_equal 1, around_before_count
62
- end
63
-
64
- def test_should_persist_new_state
65
- @record.save!
66
- assert_equal 'idling', @record.state
67
- end
68
-
69
- def test_should_run_after_callbacks
70
- ran_callback = false
71
- @machine.after_transition { ran_callback = true }
72
-
73
- @record.save!
74
- assert ran_callback
75
- end
76
-
77
- def test_should_run_around_callbacks_after_yield
78
- ran_callback = false
79
- @machine.around_transition { |block| block.call; ran_callback = true }
80
-
81
- @record.save!
82
- assert ran_callback
83
- end
84
- end
@@ -1,246 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'test_helper'
4
-
5
- class MachineWithEventAttributesOnSaveTest < BaseTestCase
6
- def setup
7
- @model = new_model
8
- @machine = StateMachines::Machine.new(@model)
9
- @machine.event :ignite do
10
- transition :parked => :idling
11
- end
12
-
13
- @record = @model.new
14
- @record.state = 'parked'
15
- @record.state_event = 'ignite'
16
- end
17
-
18
- def test_should_fail_if_event_is_invalid
19
- @record.state_event = 'invalid'
20
- assert_equal false, @record.save
21
- end
22
-
23
- def test_should_fail_if_event_has_no_transition
24
- @record.state = 'idling'
25
- assert_equal false, @record.save
26
- end
27
-
28
- def test_should_run_before_callbacks
29
- ran_callback = false
30
- @machine.before_transition { ran_callback = true }
31
-
32
- @record.save
33
- assert ran_callback
34
- end
35
-
36
- def test_should_run_before_callbacks_once
37
- before_count = 0
38
- @machine.before_transition { before_count += 1 }
39
-
40
- @record.save
41
- assert_equal 1, before_count
42
- end
43
-
44
- def test_should_run_around_callbacks_before_yield
45
- ran_callback = false
46
- @machine.around_transition { |block| ran_callback = true; block.call }
47
-
48
- @record.save
49
- assert ran_callback
50
- end
51
-
52
- def test_should_run_around_callbacks_before_yield_once
53
- around_before_count = 0
54
- @machine.around_transition { |block| around_before_count += 1; block.call }
55
-
56
- @record.save
57
- assert_equal 1, around_before_count
58
- end
59
-
60
- def test_should_persist_new_state
61
- @record.save
62
- assert_equal 'idling', @record.state
63
- end
64
-
65
- def test_should_run_after_callbacks
66
- ran_callback = false
67
- @machine.after_transition { ran_callback = true }
68
-
69
- @record.save
70
- assert ran_callback
71
- end
72
-
73
- def test_should_not_run_after_callbacks_with_failures_disabled_if_fails
74
- @model.before_create { |record| abort_from_callback }
75
-
76
- ran_callback = false
77
- @machine.after_transition { ran_callback = true }
78
-
79
- begin
80
- ; @record.save;
81
- rescue;
82
- end
83
- refute ran_callback
84
- end
85
-
86
- def test_should_run_failure_callbacks__if_fails
87
- @model.before_create { |record| abort_from_callback }
88
-
89
- ran_callback = false
90
- @machine.after_failure { ran_callback = true }
91
-
92
- begin
93
- ; @record.save;
94
- rescue;
95
- end
96
- assert ran_callback
97
- end
98
-
99
- def test_should_not_run_around_callbacks_if_fails
100
- @model.before_create { |record| abort_from_callback }
101
-
102
- ran_callback = false
103
- @machine.around_transition { |block| block.call; ran_callback = true }
104
-
105
- begin
106
- ; @record.save;
107
- rescue;
108
- end
109
- refute ran_callback
110
- end
111
-
112
- def test_should_run_around_callbacks_after_yield
113
- ran_callback = false
114
- @machine.around_transition { |block| block.call; ran_callback = true }
115
-
116
- @record.save
117
- assert ran_callback
118
- end
119
-
120
- def test_should_run_before_transitions_within_transaction
121
- @machine.before_transition { @model.create; raise ActiveRecord::Rollback }
122
-
123
- begin
124
- @record.save
125
- rescue Exception
126
- end
127
-
128
- assert_equal 0, @model.count
129
- end
130
-
131
- def test_should_run_after_transitions_within_transaction
132
- @machine.after_transition { @model.create; raise ActiveRecord::Rollback }
133
-
134
- begin
135
- @record.save
136
- rescue Exception
137
- end
138
-
139
- assert_equal 0, @model.count
140
- end
141
-
142
- def test_should_run_around_transition_within_transaction
143
- @machine.around_transition { @model.create; raise ActiveRecord::Rollback }
144
-
145
- begin
146
- @record.save
147
- rescue Exception
148
- end
149
-
150
- assert_equal 0, @model.count
151
- end
152
-
153
- def test_should_allow_additional_transitions_to_new_state_in_after_transitions
154
- @machine.event :park do
155
- transition :idling => :parked
156
- end
157
-
158
- @machine.after_transition(:on => :ignite) { @record.park }
159
-
160
- @record.save
161
- assert_equal 'parked', @record.state
162
-
163
- @record.reload
164
- assert_equal 'parked', @record.state
165
- end
166
-
167
- def test_should_allow_additional_transitions_to_previous_state_in_after_transitions
168
- @machine.event :shift_up do
169
- transition :idling => :first_gear
170
- end
171
-
172
- @machine.after_transition(:on => :ignite) { @record.shift_up }
173
-
174
- @record.save
175
- assert_equal 'first_gear', @record.state
176
-
177
- @record.reload
178
- assert_equal 'first_gear', @record.state
179
- end
180
-
181
- def test_should_yield_one_model!
182
- assert_equal true, @record.save!
183
- assert_equal 1, @model.count
184
- end
185
-
186
- # explicit tests of #save and #save! to ensure expected behavior
187
- def test_should_yield_two_models_with_before
188
- @machine.before_transition { @model.create! }
189
- assert_equal true, @record.save
190
- assert_equal 2, @model.count
191
- end
192
-
193
- def test_should_yield_two_models_with_before!
194
- @machine.before_transition { @model.create! }
195
- assert_equal true, @record.save!
196
- assert_equal 2, @model.count
197
- end
198
-
199
- def test_should_raise_on_around_transition_rollback!
200
- @machine.before_transition { @model.create! }
201
- @machine.around_transition { @model.create!; raise ActiveRecord::Rollback }
202
-
203
- raised = false
204
- begin
205
- @record.save!
206
- rescue Exception
207
- raised = true
208
- end
209
-
210
- assert_equal true, raised
211
- assert_equal 0, @model.count
212
- end
213
-
214
- def test_should_return_nil_on_around_transition_rollback
215
- @machine.before_transition { @model.create! }
216
- @machine.around_transition { @model.create!; raise ActiveRecord::Rollback }
217
- assert_nil @record.save
218
- assert_equal 0, @model.count
219
- end
220
-
221
- def test_should_return_nil_on_before_transition_rollback
222
- @machine.before_transition { raise ActiveRecord::Rollback }
223
- assert_nil @record.save
224
- assert_equal 0, @model.count
225
- end
226
-
227
- #
228
- # @rosskevin - This fails and I'm not sure why, it was existing behavior.
229
- # see: https://github.com/state-machines/state_machines-activerecord/pull/26#issuecomment-112911886
230
- #
231
- # def test_should_yield_three_models_with_before_and_around_save
232
- # @machine.before_transition { @model.create!; puts "before ran, now #{@model.count}" }
233
- # @machine.around_transition { @model.create!; puts "around ran, now #{@model.count}" }
234
- #
235
- # assert_equal true, @record.save
236
- # assert_equal 3, @model.count
237
- # end
238
- #
239
- # def test_should_yield_three_models_with_before_and_around_save!
240
- # @machine.before_transition { @model.create!; puts "before ran, now #{@model.count}" }
241
- # @machine.around_transition { @model.create!; puts "around ran, now #{@model.count}" }
242
- #
243
- # assert_equal true, @record.save!
244
- # assert_equal 3, @model.count
245
- # end
246
- end
@@ -1,145 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'test_helper'
4
-
5
- class MachineWithEventAttributesOnValidationTest < BaseTestCase
6
- def setup
7
- @model = new_model
8
- @machine = StateMachines::Machine.new(@model)
9
- @machine.event :ignite do
10
- transition :parked => :idling
11
- end
12
-
13
- @record = @model.new
14
- @record.state = 'parked'
15
- @record.state_event = 'ignite'
16
- end
17
-
18
- def test_should_fail_if_event_is_invalid
19
- @record.state_event = 'invalid'
20
- refute @record.valid?
21
- assert_equal ['State event is invalid'], @record.errors.full_messages
22
- end
23
-
24
- def test_should_fail_if_event_has_no_transition
25
- @record.state = 'idling'
26
- refute @record.valid?
27
- assert_equal ['State event cannot transition when idling'], @record.errors.full_messages
28
- end
29
-
30
- def test_should_be_successful_if_event_has_transition
31
- assert @record.valid?
32
- end
33
-
34
- def test_should_run_before_callbacks
35
- ran_callback = false
36
- @machine.before_transition { ran_callback = true }
37
-
38
- @record.valid?
39
- assert ran_callback
40
- end
41
-
42
- def test_should_run_around_callbacks_before_yield
43
- ran_callback = false
44
- @machine.around_transition { |block| ran_callback = true; block.call }
45
-
46
- begin
47
- @record.valid?
48
- rescue ArgumentError
49
- raise if StateMachines::Transition.pause_supported?
50
- end
51
- assert ran_callback
52
- end
53
-
54
- def test_should_persist_new_state
55
- @record.valid?
56
- assert_equal 'idling', @record.state
57
- end
58
-
59
- def test_should_not_run_after_callbacks
60
- ran_callback = false
61
- @machine.after_transition { ran_callback = true }
62
-
63
- @record.valid?
64
- refute ran_callback
65
- end
66
-
67
- def test_should_not_run_after_callbacks_with_failures_disabled_if_validation_fails
68
- @model.class_eval do
69
- attr_accessor :seatbelt
70
- validates :seatbelt, presence: true
71
- end
72
-
73
- ran_callback = false
74
- @machine.after_transition { ran_callback = true }
75
-
76
- @record.valid?
77
- refute ran_callback
78
- end
79
-
80
- def test_should_run_after_callbacks_if_validation_fails
81
- @model.class_eval do
82
- attr_accessor :seatbelt
83
- validates :seatbelt, presence: true
84
- end
85
-
86
- ran_callback = false
87
- @machine.after_failure { ran_callback = true }
88
-
89
- @record.valid?
90
- assert ran_callback
91
- end
92
-
93
- def test_should_not_run_around_callbacks_after_yield
94
- ran_callback = false
95
- @machine.around_transition { |block| block.call; ran_callback = true }
96
-
97
- begin
98
- @record.valid?
99
- rescue ArgumentError
100
- raise if StateMachines::Transition.pause_supported?
101
- end
102
- refute ran_callback
103
- end
104
-
105
- def test_should_not_run_around_callbacks_after_yield_with_failures_disabled_if_validation_fails
106
- @model.class_eval do
107
- attr_accessor :seatbelt
108
- validates :seatbelt, presence: true
109
- end
110
-
111
- ran_callback = false
112
- @machine.around_transition { |block| block.call; ran_callback = true }
113
-
114
- @record.valid?
115
- refute ran_callback
116
- end
117
-
118
- def test_should_rollback_before_transitions_with_raise
119
- @machine.before_transition {
120
- @model.create;
121
- raise ActiveRecord::Rollback
122
- }
123
-
124
- begin
125
- @record.valid?
126
- rescue Exception
127
- end
128
-
129
- assert_equal 0, @model.count
130
- end
131
-
132
- def test_should_rollback_before_transitions_with_false
133
- @machine.before_transition {
134
- @model.create;
135
- false
136
- }
137
-
138
- begin
139
- @record.valid?
140
- rescue Exception
141
- end
142
-
143
- assert_equal 0, @model.count
144
- end
145
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'test_helper'
4
-
5
- class MachineWithEventsTest < BaseTestCase
6
- def setup
7
- @model = new_model
8
- @machine = StateMachines::Machine.new(@model)
9
- @machine.event :shift_up
10
- end
11
-
12
- def test_should_humanize_name
13
- assert_equal 'shift up', @machine.event(:shift_up).human_name
14
- end
15
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'test_helper'
4
-
5
- class MachineWithFailedActionTest < BaseTestCase
6
- def setup
7
- @model = new_model do
8
- validates_inclusion_of :state, :in => %w(first_gear)
9
- end
10
-
11
- @machine = StateMachines::Machine.new(@model)
12
- @machine.state :parked, :idling
13
- @machine.event :ignite
14
-
15
- @callbacks = []
16
- @machine.before_transition { @callbacks << :before }
17
- @machine.after_transition { @callbacks << :after }
18
- @machine.after_failure { @callbacks << :after_failure }
19
- @machine.around_transition { |block| @callbacks << :around_before; block.call; @callbacks << :around_after }
20
-
21
- @record = @model.new(:state => 'parked')
22
- @transition = StateMachines::Transition.new(@record, @machine, :ignite, :parked, :idling)
23
- @result = @transition.perform
24
- end
25
-
26
- def test_should_not_be_successful
27
- refute @result
28
- end
29
-
30
- def test_should_not_change_current_state
31
- assert_equal 'parked', @record.state
32
- end
33
-
34
- def test_should_not_save_record
35
- assert @record.new_record?
36
- end
37
-
38
- def test_should_run_before_callbacks_and_after_callbacks_with_failures
39
- assert_equal [:before, :around_before, :after_failure], @callbacks
40
- end
41
- end
42
-
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'test_helper'
4
-
5
- class MachineWithFailedAfterCallbacksTest < BaseTestCase
6
- def setup
7
- @callbacks = []
8
-
9
- @model = new_model
10
- @machine = StateMachines::Machine.new(@model)
11
- @machine.state :parked, :idling
12
- @machine.event :ignite
13
- @machine.after_transition { @callbacks << :after_1; false }
14
- @machine.after_transition { @callbacks << :after_2 }
15
- @machine.around_transition { |block| @callbacks << :around_before; block.call; @callbacks << :around_after }
16
-
17
- @record = @model.new(:state => 'parked')
18
- @transition = StateMachines::Transition.new(@record, @machine, :ignite, :parked, :idling)
19
- @result = @transition.perform
20
- end
21
-
22
- def test_should_be_successful
23
- assert @result
24
- end
25
-
26
- def test_should_change_current_state
27
- assert_equal 'idling', @record.state
28
- end
29
-
30
- def test_should_save_record
31
- refute @record.new_record?
32
- end
33
-
34
- def test_should_not_run_further_after_callbacks
35
- assert_equal [:around_before, :around_after, :after_1], @callbacks
36
- end
37
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'test_helper'
4
-
5
- class MachineWithFailedBeforeCallbacksTest < BaseTestCase
6
- def setup
7
- @callbacks = []
8
-
9
- @model = new_model
10
- @machine = StateMachines::Machine.new(@model)
11
- @machine.state :parked, :idling
12
- @machine.event :ignite
13
- @machine.before_transition { @callbacks << :before_1; false }
14
- @machine.before_transition { @callbacks << :before_2 }
15
- @machine.after_transition { @callbacks << :after }
16
- @machine.around_transition { |block| @callbacks << :around_before; block.call; @callbacks << :around_after }
17
-
18
- @record = @model.new(:state => 'parked')
19
- @transition = StateMachines::Transition.new(@record, @machine, :ignite, :parked, :idling)
20
- @result = @transition.perform
21
- end
22
-
23
- def test_should_not_be_successful
24
- refute @result
25
- end
26
-
27
- def test_should_not_change_current_state
28
- assert_equal 'parked', @record.state
29
- end
30
-
31
- def test_should_not_run_action
32
- assert @record.new_record?
33
- end
34
-
35
- def test_should_not_run_further_callbacks
36
- assert_equal [:before_1], @callbacks
37
- end
38
- end