state_machines-activerecord 0.9.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 (60) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +16 -3
  4. data/lib/state_machines/integrations/active_record/locale.rb +12 -9
  5. data/lib/state_machines/integrations/active_record/version.rb +3 -1
  6. data/lib/state_machines/integrations/active_record.rb +71 -109
  7. data/lib/state_machines-activerecord.rb +2 -0
  8. metadata +36 -142
  9. data/test/files/en.yml +0 -5
  10. data/test/files/models/post.rb +0 -11
  11. data/test/integration_test.rb +0 -25
  12. data/test/machine_by_default_test.rb +0 -16
  13. data/test/machine_errors_test.rb +0 -19
  14. data/test/machine_multiple_test.rb +0 -17
  15. data/test/machine_nested_action_test.rb +0 -38
  16. data/test/machine_unmigrated_test.rb +0 -14
  17. data/test/machine_with_aliased_attribute_test.rb +0 -23
  18. data/test/machine_with_callbacks_test.rb +0 -172
  19. data/test/machine_with_column_state_attribute_test.rb +0 -44
  20. data/test/machine_with_complex_pluralization_scopes_test.rb +0 -16
  21. data/test/machine_with_conflicting_predicate_test.rb +0 -18
  22. data/test/machine_with_conflicting_state_name_test.rb +0 -29
  23. data/test/machine_with_custom_attribute_test.rb +0 -21
  24. data/test/machine_with_default_scope_test.rb +0 -18
  25. data/test/machine_with_different_column_default_test.rb +0 -27
  26. data/test/machine_with_different_integer_column_default_test.rb +0 -29
  27. data/test/machine_with_dirty_attribute_and_custom_attributes_during_loopback_test.rb +0 -24
  28. data/test/machine_with_dirty_attribute_and_state_events_test.rb +0 -20
  29. data/test/machine_with_dirty_attributes_and_custom_attribute_test.rb +0 -32
  30. data/test/machine_with_dirty_attributes_during_loopback_test.rb +0 -22
  31. data/test/machine_with_dirty_attributes_test.rb +0 -35
  32. data/test/machine_with_dynamic_initial_state_test.rb +0 -99
  33. data/test/machine_with_event_attributes_on_autosave_test.rb +0 -48
  34. data/test/machine_with_event_attributes_on_custom_action_test.rb +0 -41
  35. data/test/machine_with_event_attributes_on_save_bang_test.rb +0 -82
  36. data/test/machine_with_event_attributes_on_save_test.rb +0 -244
  37. data/test/machine_with_event_attributes_on_validation_test.rb +0 -143
  38. data/test/machine_with_events_test.rb +0 -13
  39. data/test/machine_with_failed_action_test.rb +0 -40
  40. data/test/machine_with_failed_after_callbacks_test.rb +0 -35
  41. data/test/machine_with_failed_before_callbacks_test.rb +0 -36
  42. data/test/machine_with_initialized_state_test.rb +0 -41
  43. data/test/machine_with_internationalization_test.rb +0 -180
  44. data/test/machine_with_loopback_test.rb +0 -22
  45. data/test/machine_with_non_column_state_attribute_defined_test.rb +0 -29
  46. data/test/machine_with_same_column_default_test.rb +0 -26
  47. data/test/machine_with_same_integer_column_default_test.rb +0 -30
  48. data/test/machine_with_scopes_and_joins_test.rb +0 -38
  49. data/test/machine_with_scopes_and_owner_subclass_test.rb +0 -27
  50. data/test/machine_with_scopes_test.rb +0 -70
  51. data/test/machine_with_state_driven_validations_test.rb +0 -30
  52. data/test/machine_with_states_test.rb +0 -13
  53. data/test/machine_with_static_initial_state_test.rb +0 -167
  54. data/test/machine_with_transactions_test.rb +0 -26
  55. data/test/machine_with_validations_and_custom_attribute_test.rb +0 -21
  56. data/test/machine_with_validations_test.rb +0 -47
  57. data/test/machine_without_database_test.rb +0 -20
  58. data/test/machine_without_transactions_test.rb +0 -26
  59. data/test/model_test.rb +0 -12
  60. data/test/test_helper.rb +0 -58
metadata CHANGED
@@ -1,114 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_machines-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.40.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
8
8
  - Aaron Pfeifer
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2023-06-30 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: state_machines-activemodel
14
+ name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
16
  requirements:
18
17
  - - ">="
19
18
  - !ruby/object:Gem::Version
20
- version: 0.9.0
19
+ version: '7.2'
21
20
  type: :runtime
22
21
  prerelease: false
23
22
  version_requirements: !ruby/object:Gem::Requirement
24
23
  requirements:
25
24
  - - ">="
26
25
  - !ruby/object:Gem::Version
27
- version: 0.9.0
26
+ version: '7.2'
28
27
  - !ruby/object:Gem::Dependency
29
- name: activerecord
28
+ name: state_machines-activemodel
30
29
  requirement: !ruby/object:Gem::Requirement
31
30
  requirements:
32
31
  - - ">="
33
32
  - !ruby/object:Gem::Version
34
- version: '6.0'
33
+ version: 0.10.0
35
34
  type: :runtime
36
35
  prerelease: false
37
36
  version_requirements: !ruby/object:Gem::Requirement
38
37
  requirements:
39
38
  - - ">="
40
39
  - !ruby/object:Gem::Version
41
- version: '6.0'
40
+ version: 0.10.0
42
41
  - !ruby/object:Gem::Dependency
43
- name: rake
42
+ name: appraisal
44
43
  requirement: !ruby/object:Gem::Requirement
45
44
  requirements:
46
- - - "~>"
45
+ - - ">="
47
46
  - !ruby/object:Gem::Version
48
- version: '13.0'
47
+ version: '1'
49
48
  type: :development
50
49
  prerelease: false
51
50
  version_requirements: !ruby/object:Gem::Requirement
52
51
  requirements:
53
- - - "~>"
52
+ - - ">="
54
53
  - !ruby/object:Gem::Version
55
- version: '13.0'
54
+ version: '1'
56
55
  - !ruby/object:Gem::Dependency
57
- name: sqlite3
56
+ name: minitest
58
57
  requirement: !ruby/object:Gem::Requirement
59
58
  requirements:
60
- - - "~>"
59
+ - - ">="
61
60
  - !ruby/object:Gem::Version
62
- version: '1.3'
61
+ version: 5.4.0
63
62
  type: :development
64
63
  prerelease: false
65
64
  version_requirements: !ruby/object:Gem::Requirement
66
65
  requirements:
67
- - - "~>"
66
+ - - ">="
68
67
  - !ruby/object:Gem::Version
69
- version: '1.3'
68
+ version: 5.4.0
70
69
  - !ruby/object:Gem::Dependency
71
- name: appraisal
70
+ name: minitest-reporters
72
71
  requirement: !ruby/object:Gem::Requirement
73
72
  requirements:
74
73
  - - ">="
75
74
  - !ruby/object:Gem::Version
76
- version: '1'
75
+ version: '0'
77
76
  type: :development
78
77
  prerelease: false
79
78
  version_requirements: !ruby/object:Gem::Requirement
80
79
  requirements:
81
80
  - - ">="
82
81
  - !ruby/object:Gem::Version
83
- version: '1'
82
+ version: '0'
84
83
  - !ruby/object:Gem::Dependency
85
- name: minitest
84
+ name: rake
86
85
  requirement: !ruby/object:Gem::Requirement
87
86
  requirements:
88
- - - ">="
87
+ - - "~>"
89
88
  - !ruby/object:Gem::Version
90
- version: 5.4.0
89
+ version: '13.0'
91
90
  type: :development
92
91
  prerelease: false
93
92
  version_requirements: !ruby/object:Gem::Requirement
94
93
  requirements:
95
- - - ">="
94
+ - - "~>"
96
95
  - !ruby/object:Gem::Version
97
- version: 5.4.0
96
+ version: '13.0'
98
97
  - !ruby/object:Gem::Dependency
99
- name: minitest-reporters
98
+ name: sqlite3
100
99
  requirement: !ruby/object:Gem::Requirement
101
100
  requirements:
102
- - - ">="
101
+ - - "~>"
103
102
  - !ruby/object:Gem::Version
104
- version: '0'
103
+ version: '1.3'
105
104
  type: :development
106
105
  prerelease: false
107
106
  version_requirements: !ruby/object:Gem::Requirement
108
107
  requirements:
109
- - - ">="
108
+ - - "~>"
110
109
  - !ruby/object:Gem::Version
111
- version: '0'
110
+ version: '1.3'
112
111
  description: Adds support for creating state machines for attributes on ActiveRecord
113
112
  email:
114
113
  - terminale@gmail.com
@@ -123,63 +122,11 @@ files:
123
122
  - lib/state_machines/integrations/active_record.rb
124
123
  - lib/state_machines/integrations/active_record/locale.rb
125
124
  - lib/state_machines/integrations/active_record/version.rb
126
- - test/files/en.yml
127
- - test/files/models/post.rb
128
- - test/integration_test.rb
129
- - test/machine_by_default_test.rb
130
- - test/machine_errors_test.rb
131
- - test/machine_multiple_test.rb
132
- - test/machine_nested_action_test.rb
133
- - test/machine_unmigrated_test.rb
134
- - test/machine_with_aliased_attribute_test.rb
135
- - test/machine_with_callbacks_test.rb
136
- - test/machine_with_column_state_attribute_test.rb
137
- - test/machine_with_complex_pluralization_scopes_test.rb
138
- - test/machine_with_conflicting_predicate_test.rb
139
- - test/machine_with_conflicting_state_name_test.rb
140
- - test/machine_with_custom_attribute_test.rb
141
- - test/machine_with_default_scope_test.rb
142
- - test/machine_with_different_column_default_test.rb
143
- - test/machine_with_different_integer_column_default_test.rb
144
- - test/machine_with_dirty_attribute_and_custom_attributes_during_loopback_test.rb
145
- - test/machine_with_dirty_attribute_and_state_events_test.rb
146
- - test/machine_with_dirty_attributes_and_custom_attribute_test.rb
147
- - test/machine_with_dirty_attributes_during_loopback_test.rb
148
- - test/machine_with_dirty_attributes_test.rb
149
- - test/machine_with_dynamic_initial_state_test.rb
150
- - test/machine_with_event_attributes_on_autosave_test.rb
151
- - test/machine_with_event_attributes_on_custom_action_test.rb
152
- - test/machine_with_event_attributes_on_save_bang_test.rb
153
- - test/machine_with_event_attributes_on_save_test.rb
154
- - test/machine_with_event_attributes_on_validation_test.rb
155
- - test/machine_with_events_test.rb
156
- - test/machine_with_failed_action_test.rb
157
- - test/machine_with_failed_after_callbacks_test.rb
158
- - test/machine_with_failed_before_callbacks_test.rb
159
- - test/machine_with_initialized_state_test.rb
160
- - test/machine_with_internationalization_test.rb
161
- - test/machine_with_loopback_test.rb
162
- - test/machine_with_non_column_state_attribute_defined_test.rb
163
- - test/machine_with_same_column_default_test.rb
164
- - test/machine_with_same_integer_column_default_test.rb
165
- - test/machine_with_scopes_and_joins_test.rb
166
- - test/machine_with_scopes_and_owner_subclass_test.rb
167
- - test/machine_with_scopes_test.rb
168
- - test/machine_with_state_driven_validations_test.rb
169
- - test/machine_with_states_test.rb
170
- - test/machine_with_static_initial_state_test.rb
171
- - test/machine_with_transactions_test.rb
172
- - test/machine_with_validations_and_custom_attribute_test.rb
173
- - test/machine_with_validations_test.rb
174
- - test/machine_without_database_test.rb
175
- - test/machine_without_transactions_test.rb
176
- - test/model_test.rb
177
- - test/test_helper.rb
178
125
  homepage: https://github.com/state-machines/state_machines-activerecord/
179
126
  licenses:
180
127
  - MIT
181
- metadata: {}
182
- post_install_message:
128
+ metadata:
129
+ rubygems_mfa_required: 'true'
183
130
  rdoc_options: []
184
131
  require_paths:
185
132
  - lib
@@ -187,67 +134,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
134
  requirements:
188
135
  - - ">="
189
136
  - !ruby/object:Gem::Version
190
- version: '3.0'
137
+ version: '3.2'
191
138
  required_rubygems_version: !ruby/object:Gem::Requirement
192
139
  requirements:
193
140
  - - ">="
194
141
  - !ruby/object:Gem::Version
195
142
  version: '0'
196
143
  requirements: []
197
- rubygems_version: 3.4.10
198
- signing_key:
144
+ rubygems_version: 3.6.9
199
145
  specification_version: 4
200
146
  summary: State machines Active Record Integration
201
- test_files:
202
- - test/files/en.yml
203
- - test/files/models/post.rb
204
- - test/integration_test.rb
205
- - test/machine_by_default_test.rb
206
- - test/machine_errors_test.rb
207
- - test/machine_multiple_test.rb
208
- - test/machine_nested_action_test.rb
209
- - test/machine_unmigrated_test.rb
210
- - test/machine_with_aliased_attribute_test.rb
211
- - test/machine_with_callbacks_test.rb
212
- - test/machine_with_column_state_attribute_test.rb
213
- - test/machine_with_complex_pluralization_scopes_test.rb
214
- - test/machine_with_conflicting_predicate_test.rb
215
- - test/machine_with_conflicting_state_name_test.rb
216
- - test/machine_with_custom_attribute_test.rb
217
- - test/machine_with_default_scope_test.rb
218
- - test/machine_with_different_column_default_test.rb
219
- - test/machine_with_different_integer_column_default_test.rb
220
- - test/machine_with_dirty_attribute_and_custom_attributes_during_loopback_test.rb
221
- - test/machine_with_dirty_attribute_and_state_events_test.rb
222
- - test/machine_with_dirty_attributes_and_custom_attribute_test.rb
223
- - test/machine_with_dirty_attributes_during_loopback_test.rb
224
- - test/machine_with_dirty_attributes_test.rb
225
- - test/machine_with_dynamic_initial_state_test.rb
226
- - test/machine_with_event_attributes_on_autosave_test.rb
227
- - test/machine_with_event_attributes_on_custom_action_test.rb
228
- - test/machine_with_event_attributes_on_save_bang_test.rb
229
- - test/machine_with_event_attributes_on_save_test.rb
230
- - test/machine_with_event_attributes_on_validation_test.rb
231
- - test/machine_with_events_test.rb
232
- - test/machine_with_failed_action_test.rb
233
- - test/machine_with_failed_after_callbacks_test.rb
234
- - test/machine_with_failed_before_callbacks_test.rb
235
- - test/machine_with_initialized_state_test.rb
236
- - test/machine_with_internationalization_test.rb
237
- - test/machine_with_loopback_test.rb
238
- - test/machine_with_non_column_state_attribute_defined_test.rb
239
- - test/machine_with_same_column_default_test.rb
240
- - test/machine_with_same_integer_column_default_test.rb
241
- - test/machine_with_scopes_and_joins_test.rb
242
- - test/machine_with_scopes_and_owner_subclass_test.rb
243
- - test/machine_with_scopes_test.rb
244
- - test/machine_with_state_driven_validations_test.rb
245
- - test/machine_with_states_test.rb
246
- - test/machine_with_static_initial_state_test.rb
247
- - test/machine_with_transactions_test.rb
248
- - test/machine_with_validations_and_custom_attribute_test.rb
249
- - test/machine_with_validations_test.rb
250
- - test/machine_without_database_test.rb
251
- - test/machine_without_transactions_test.rb
252
- - test/model_test.rb
253
- - test/test_helper.rb
147
+ test_files: []
data/test/files/en.yml DELETED
@@ -1,5 +0,0 @@
1
- en:
2
- activerecord:
3
- errors:
4
- messages:
5
- invalid_transition: "cannot transition"
@@ -1,11 +0,0 @@
1
- ActiveRecord::Base.connection.create_table(:posts, :force => true) do |t|
2
- t.string :title
3
- t.string :content
4
- t.string :state
5
- end
6
-
7
- class Post < ActiveRecord::Base
8
- state_machine initial: :draft do
9
-
10
- end
11
- end
@@ -1,25 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- class IntegrationTest < BaseTestCase
4
- def test_should_have_an_integration_name
5
- assert_equal :active_record, StateMachines::Integrations::ActiveRecord.integration_name
6
- end
7
-
8
- def test_should_be_before_activemodel
9
- integrations = StateMachines::Integrations.list.to_a
10
- assert StateMachines::Integrations::ActiveRecord, integrations.first
11
- assert StateMachines::Integrations::ActiveModel, integrations.last
12
- end
13
-
14
- def test_should_match_if_class_inherits_from_active_record
15
- assert StateMachines::Integrations::ActiveRecord.matches?(new_model)
16
- end
17
-
18
- def test_should_not_match_if_class_does_not_inherit_from_active_record
19
- refute StateMachines::Integrations::ActiveRecord.matches?(Class.new)
20
- end
21
-
22
- def test_should_have_defaults
23
- assert_equal({action: :save, use_transactions: true}, StateMachines::Integrations::ActiveRecord.defaults)
24
- end
25
- end
@@ -1,16 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- class MachineByDefaultTest < BaseTestCase
4
- def setup
5
- @model = new_model
6
- @machine = StateMachines::Machine.new(@model)
7
- end
8
-
9
- def test_should_use_save_as_action
10
- assert_equal :save, @machine.action
11
- end
12
-
13
- def test_should_use_transactions
14
- assert_equal true, @machine.use_transactions
15
- end
16
- end
@@ -1,19 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- class MachineErrorsTest < BaseTestCase
4
- def setup
5
- @model = new_model
6
- @machine = StateMachines::Machine.new(@model)
7
- @record = @model.new
8
- end
9
-
10
- def test_should_be_able_to_describe_current_errors
11
- @record.errors.add(:id, 'cannot be blank')
12
- @record.errors.add(:state, 'is invalid')
13
- assert_equal ['Id cannot be blank', 'State is invalid'], @machine.errors_for(@record).split(', ').sort
14
- end
15
-
16
- def test_should_describe_as_halted_with_no_errors
17
- assert_equal 'Transition halted', @machine.errors_for(@record)
18
- end
19
- end
@@ -1,17 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- class MachineMultipleTest < BaseTestCase
4
- def setup
5
- @model = new_model do
6
- connection.add_column table_name, :status, :string
7
- end
8
- @state_machine = StateMachines::Machine.new(@model, :initial => :parked)
9
- @status_machine = StateMachines::Machine.new(@model, :status, :initial => :idling)
10
- end
11
-
12
- def test_should_should_initialize_each_state
13
- record = @model.new
14
- assert_equal 'parked', record.state
15
- assert_equal 'idling', record.status
16
- end
17
- end
@@ -1,38 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- class MachineNestedActionTest < BaseTestCase
4
- def setup
5
- @callbacks = []
6
-
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(:state => 'parked')
14
- end
15
-
16
- def test_should_allow_transition_prior_to_creation_if_skipping_action
17
- record = @record
18
- @model.before_create { record.ignite(false) }
19
- result = @record.save
20
-
21
- assert_equal true, result
22
- assert_equal "idling", @record.state
23
- @record.reload
24
- assert_equal "idling", @record.state
25
- end
26
-
27
- def test_should_allow_transition_after_creation
28
- record = @record
29
- @model.after_create { record.ignite }
30
- result = @record.save
31
-
32
- assert_equal true, result
33
- assert_equal "idling", @record.state
34
- @record.reload
35
- assert_equal "idling", @record.state
36
- end
37
- end
38
-
@@ -1,14 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- class MachineUnmigratedTest < BaseTestCase
4
- def setup
5
- @model = new_model(false)
6
-
7
- # Drop the table so that it definitely doesn't exist
8
- @model.connection.drop_table(@model.table_name) if @model.table_exists?
9
- end
10
-
11
- def test_should_allow_machine_creation
12
- assert_nothing_raised { StateMachines::Machine.new(@model) }
13
- end
14
- end
@@ -1,23 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- class MachineWithAliasedAttributeTest < BaseTestCase
4
- def setup
5
- @model = new_model do
6
- alias_attribute :vehicle_status, :state
7
- end
8
-
9
- @machine = StateMachines::Machine.new(@model, :status, :attribute => :vehicle_status)
10
- @machine.state :parked
11
-
12
- @record = @model.new
13
- end
14
-
15
- def test_should_check_custom_attribute_for_predicate
16
- @record.vehicle_status = nil
17
- refute @record.status?(:parked)
18
-
19
- @record.vehicle_status = 'parked'
20
- assert @record.status?(:parked)
21
- end
22
- end
23
-
@@ -1,172 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- class MachineWithCallbacksTest < BaseTestCase
4
- def setup
5
- @model = new_model
6
- @machine = StateMachines::Machine.new(@model, :initial => :parked)
7
- @machine.other_states :idling
8
- @machine.event :ignite
9
-
10
- @record = @model.new(:state => 'parked')
11
- @transition = StateMachines::Transition.new(@record, @machine, :ignite, :parked, :idling)
12
- end
13
-
14
- def test_should_run_before_callbacks
15
- called = false
16
- @machine.before_transition { called = true }
17
-
18
- @transition.perform
19
- assert called
20
- end
21
-
22
- def test_should_pass_record_to_before_callbacks_with_one_argument
23
- record = nil
24
- @machine.before_transition { |arg| record = arg }
25
-
26
- @transition.perform
27
- assert_equal @record, record
28
- end
29
-
30
- def test_should_pass_record_and_transition_to_before_callbacks_with_multiple_arguments
31
- callback_args = nil
32
- @machine.before_transition { |*args| callback_args = args }
33
-
34
- @transition.perform
35
- assert_equal [@record, @transition], callback_args
36
- end
37
-
38
- def test_should_run_before_callbacks_outside_the_context_of_the_record
39
- context = nil
40
- @machine.before_transition { context = self }
41
-
42
- @transition.perform
43
- assert_equal self, context
44
- end
45
-
46
- def test_should_run_after_callbacks
47
- called = false
48
- @machine.after_transition { called = true }
49
-
50
- @transition.perform
51
- assert called
52
- end
53
-
54
- def test_should_pass_record_to_after_callbacks_with_one_argument
55
- record = nil
56
- @machine.after_transition { |arg| record = arg }
57
-
58
- @transition.perform
59
- assert_equal @record, record
60
- end
61
-
62
- def test_should_pass_record_and_transition_to_after_callbacks_with_multiple_arguments
63
- callback_args = nil
64
- @machine.after_transition { |*args| callback_args = args }
65
-
66
- @transition.perform
67
- assert_equal [@record, @transition], callback_args
68
- end
69
-
70
- def test_should_run_after_callbacks_outside_the_context_of_the_record
71
- context = nil
72
- @machine.after_transition { context = self }
73
-
74
- @transition.perform
75
- assert_equal self, context
76
- end
77
-
78
- def test_should_run_after_callbacks_if_model_callback_added_prior_to_state_machine_definition
79
- model = new_model do
80
- after_save { nil }
81
- end
82
- machine = StateMachines::Machine.new(model, :initial => :parked)
83
- machine.other_states :idling
84
- machine.event :ignite
85
- after_called = false
86
- machine.after_transition { after_called = true }
87
-
88
- record = model.new(:state => 'parked')
89
- transition = StateMachines::Transition.new(record, machine, :ignite, :parked, :idling)
90
- transition.perform
91
- assert_equal true, after_called
92
- end
93
-
94
- def test_should_run_around_callbacks
95
- before_called = false
96
- after_called = false
97
- ensure_called = 0
98
- @machine.around_transition do |block|
99
- before_called = true
100
- begin
101
- block.call
102
- ensure
103
- ensure_called += 1
104
- end
105
- after_called = true
106
- end
107
-
108
- @transition.perform
109
- assert before_called
110
- assert after_called
111
- assert_equal ensure_called, 1
112
- end
113
-
114
- def test_should_include_transition_states_in_known_states
115
- @machine.before_transition :to => :first_gear, :do => lambda {}
116
-
117
- assert_equal [:parked, :idling, :first_gear], @machine.states.map { |state| state.name }
118
- end
119
-
120
- def test_should_allow_symbolic_callbacks
121
- callback_args = nil
122
-
123
- klass = class << @record;
124
- self;
125
- end
126
- klass.send(:define_method, :after_ignite) do |*args|
127
- callback_args = args
128
- end
129
-
130
- @machine.before_transition(:after_ignite)
131
-
132
- @transition.perform
133
- assert_equal [@transition], callback_args
134
- end
135
-
136
- def test_should_allow_string_callbacks
137
- class << @record
138
- attr_reader :callback_result
139
- end
140
-
141
- @machine.before_transition('@callback_result = [1, 2, 3]')
142
- @transition.perform
143
-
144
- assert_equal [1, 2, 3], @record.callback_result
145
- end
146
-
147
- def test_should_run_in_expected_order
148
- expected = [
149
- :before_transition, :before_validation, :after_validation,
150
- :before_save, :before_create, :after_create, :after_save,
151
- :after_transition
152
- ]
153
-
154
- callbacks = []
155
- @model.before_validation { callbacks << :before_validation }
156
- @model.after_validation { callbacks << :after_validation }
157
- @model.before_save { callbacks << :before_save }
158
- @model.before_create { callbacks << :before_create }
159
- @model.after_create { callbacks << :after_create }
160
- @model.after_save { callbacks << :after_save }
161
- @model.after_commit { callbacks << :after_commit }
162
- expected << :after_commit
163
-
164
- @machine.before_transition { callbacks << :before_transition }
165
- @machine.after_transition { callbacks << :after_transition }
166
-
167
- @transition.perform
168
-
169
- assert_equal expected, callbacks
170
- end
171
- end
172
-
@@ -1,44 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- class MachineWithColumnStateAttributeTest < BaseTestCase
4
- def setup
5
- @model = new_model
6
- @machine = StateMachines::Machine.new(@model, :initial => :parked)
7
- @machine.other_states(:idling)
8
-
9
- @record = @model.new
10
- end
11
-
12
- def test_should_not_override_the_column_reader
13
- @record[:state] = 'parked'
14
- assert_equal 'parked', @record.state
15
- end
16
-
17
- def test_should_not_override_the_column_writer
18
- @record.state = 'parked'
19
- assert_equal 'parked', @record[:state]
20
- end
21
-
22
- def test_should_have_an_attribute_predicate
23
- assert @record.respond_to?(:state?)
24
- end
25
-
26
- def test_should_test_for_existence_on_predicate_without_parameters
27
- assert @record.state?
28
-
29
- @record.state = nil
30
- refute @record.state?
31
- end
32
-
33
- def test_should_return_false_for_predicate_if_does_not_match_current_value
34
- refute @record.state?(:idling)
35
- end
36
-
37
- def test_should_return_true_for_predicate_if_matches_current_value
38
- assert @record.state?(:parked)
39
- end
40
-
41
- def test_should_raise_exception_for_predicate_if_invalid_state_specified
42
- assert_raises(IndexError) { @record.state?(:invalid) }
43
- end
44
- end