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.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/lib/state_machines/integrations/active_record/locale.rb +10 -9
- data/lib/state_machines/integrations/active_record/version.rb +1 -1
- data/lib/state_machines/integrations/active_record.rb +52 -31
- metadata +35 -138
- data/test/files/en.yml +0 -5
- data/test/files/models/post.rb +0 -13
- data/test/integration_test.rb +0 -27
- data/test/machine_by_default_test.rb +0 -18
- data/test/machine_errors_test.rb +0 -21
- data/test/machine_multiple_test.rb +0 -19
- data/test/machine_nested_action_test.rb +0 -40
- data/test/machine_unmigrated_test.rb +0 -16
- data/test/machine_with_aliased_attribute_test.rb +0 -25
- data/test/machine_with_callbacks_test.rb +0 -174
- data/test/machine_with_column_state_attribute_test.rb +0 -46
- data/test/machine_with_complex_pluralization_scopes_test.rb +0 -18
- data/test/machine_with_conflicting_predicate_test.rb +0 -20
- data/test/machine_with_conflicting_state_name_test.rb +0 -31
- data/test/machine_with_custom_attribute_test.rb +0 -23
- data/test/machine_with_default_scope_test.rb +0 -20
- data/test/machine_with_different_column_default_test.rb +0 -29
- data/test/machine_with_different_integer_column_default_test.rb +0 -31
- data/test/machine_with_dirty_attribute_and_custom_attributes_during_loopback_test.rb +0 -26
- data/test/machine_with_dirty_attribute_and_state_events_test.rb +0 -22
- data/test/machine_with_dirty_attributes_and_custom_attribute_test.rb +0 -34
- data/test/machine_with_dirty_attributes_during_loopback_test.rb +0 -24
- data/test/machine_with_dirty_attributes_test.rb +0 -37
- data/test/machine_with_dynamic_initial_state_test.rb +0 -101
- data/test/machine_with_event_attributes_on_autosave_test.rb +0 -50
- data/test/machine_with_event_attributes_on_custom_action_test.rb +0 -43
- data/test/machine_with_event_attributes_on_save_bang_test.rb +0 -84
- data/test/machine_with_event_attributes_on_save_test.rb +0 -246
- data/test/machine_with_event_attributes_on_validation_test.rb +0 -145
- data/test/machine_with_events_test.rb +0 -15
- data/test/machine_with_failed_action_test.rb +0 -42
- data/test/machine_with_failed_after_callbacks_test.rb +0 -37
- data/test/machine_with_failed_before_callbacks_test.rb +0 -38
- data/test/machine_with_initialized_state_test.rb +0 -43
- data/test/machine_with_internationalization_test.rb +0 -182
- data/test/machine_with_loopback_test.rb +0 -24
- data/test/machine_with_non_column_state_attribute_defined_test.rb +0 -31
- data/test/machine_with_same_column_default_test.rb +0 -28
- data/test/machine_with_same_integer_column_default_test.rb +0 -32
- data/test/machine_with_scopes_and_joins_test.rb +0 -40
- data/test/machine_with_scopes_and_owner_subclass_test.rb +0 -29
- data/test/machine_with_scopes_test.rb +0 -72
- data/test/machine_with_state_driven_validations_test.rb +0 -32
- data/test/machine_with_states_test.rb +0 -15
- data/test/machine_with_static_initial_state_test.rb +0 -169
- data/test/machine_with_transactions_test.rb +0 -28
- data/test/machine_with_validations_and_custom_attribute_test.rb +0 -23
- data/test/machine_with_validations_test.rb +0 -49
- data/test/machine_without_database_test.rb +0 -22
- data/test/machine_without_transactions_test.rb +0 -28
- data/test/model_test.rb +0 -14
- data/test/test_helper.rb +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc3a76fe2fa39848f7ae9b5fc71c1fed9fae206a6cc0b0e24184415cdb760f1f
|
4
|
+
data.tar.gz: c8152e14110e863e478ec0dde3bac1a15e3cf15578deaae94e5f44062f1f67e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 982b654eb9d38edbe29bbaf2ca4f85980781575592813a4450e46cd4fbe1928f30ecc88e578aa4d879fcfb973109688fd90c942bb2a4e857420e5d94db14a602
|
7
|
+
data.tar.gz: ed2fae5f320b5f860beeca7c390e4674fd693b7ca171176a61f13e937039091cdd173a520438c1737e9ff4e2b936c91e89973ed64033635877cfcd04f4f13397
|
data/README.md
CHANGED
@@ -2,9 +2,14 @@
|
|
2
2
|
|
3
3
|
# StateMachines Active Record Integration
|
4
4
|
|
5
|
-
The Active Record
|
5
|
+
The Active Record 7.2+ integration adds support for database transactions, automatically
|
6
6
|
saving the record, named scopes, validation errors.
|
7
7
|
|
8
|
+
## Requirements
|
9
|
+
|
10
|
+
- Ruby 3.2+
|
11
|
+
- Rails 7.2+
|
12
|
+
|
8
13
|
## Installation
|
9
14
|
|
10
15
|
Add this line to your application's Gemfile:
|
@@ -63,6 +68,15 @@ Vehicle.with_state(:parked) # also plural #with_states
|
|
63
68
|
Vehicle.without_states(:first_gear, :second_gear) # also singular #without_state
|
64
69
|
```
|
65
70
|
|
71
|
+
#### Transparent Scopes
|
72
|
+
State scopes will return all records when `nil` is passed, making them perfect for search filters:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
Vehicle.with_state(nil) # Returns all vehicles
|
76
|
+
Vehicle.with_state(params[:state]) # Returns all vehicles if params[:state] is nil
|
77
|
+
Vehicle.where(color: 'red').with_state(nil) # Returns all red vehicles (chainable)
|
78
|
+
```
|
79
|
+
|
66
80
|
### State driven validations
|
67
81
|
|
68
82
|
As mentioned in `StateMachines::Machine#state`, you can define behaviors,
|
@@ -1,14 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Use lazy evaluation to avoid circular dependencies with frozen default_messages
|
4
|
+
# This ensures messages can be updated after gem loading while maintaining thread safety
|
3
5
|
{ en: {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
}
|
6
|
+
activerecord: {
|
7
|
+
errors: {
|
8
|
+
messages: {
|
9
|
+
invalid: ->(*) { StateMachines::Machine.default_messages[:invalid] },
|
10
|
+
invalid_event: ->(*) { format(StateMachines::Machine.default_messages[:invalid_event], '%<state>s') },
|
11
|
+
invalid_transition: ->(*) { format(StateMachines::Machine.default_messages[:invalid_transition], '%<event>s') }
|
12
|
+
}
|
12
13
|
}
|
14
|
+
}
|
13
15
|
} }
|
14
|
-
|
@@ -3,7 +3,7 @@ require 'active_record'
|
|
3
3
|
require 'state_machines/integrations/active_record/version'
|
4
4
|
|
5
5
|
module StateMachines
|
6
|
-
module Integrations
|
6
|
+
module Integrations # :nodoc:
|
7
7
|
# Adds support for integrating state machines with ActiveRecord models.
|
8
8
|
#
|
9
9
|
# == Examples
|
@@ -207,10 +207,10 @@ module StateMachines
|
|
207
207
|
#
|
208
208
|
# class Vehicle < ApplicationRecord
|
209
209
|
# # with_states also aliased to with_state
|
210
|
-
# scope :with_states, ->(states) { where(state: states) }
|
210
|
+
# scope :with_states, ->(states) { states.present? ? where(state: states) : all }
|
211
211
|
#
|
212
212
|
# # without_states also aliased to without_state
|
213
|
-
# scope :without_states, ->(states) { where.not(state: states) }
|
213
|
+
# scope :without_states, ->(states) { states.present? ? where.not(state: states) : all }
|
214
214
|
# end
|
215
215
|
#
|
216
216
|
# *Note*, however, that the states are converted to their stored values
|
@@ -226,6 +226,15 @@ module StateMachines
|
|
226
226
|
#
|
227
227
|
# Vehicle.with_state('parked')
|
228
228
|
#
|
229
|
+
# === Transparent Scopes
|
230
|
+
#
|
231
|
+
# When `nil` is passed to any of the state scopes, they return `all` records
|
232
|
+
# without applying any filters. This allows for more flexible scope chaining
|
233
|
+
# in search interfaces:
|
234
|
+
#
|
235
|
+
# Vehicle.with_state(params[:state]) # Returns all vehicles if params[:state] is nil
|
236
|
+
# Vehicle.where(color: 'red').with_state(nil) # Returns all red vehicles
|
237
|
+
#
|
229
238
|
# == Callbacks
|
230
239
|
#
|
231
240
|
# All before/after transition callbacks defined for ActiveRecord models
|
@@ -358,7 +367,7 @@ module StateMachines
|
|
358
367
|
include ActiveModel
|
359
368
|
|
360
369
|
# The default options to use for state machines using this integration
|
361
|
-
@defaults = {:
|
370
|
+
@defaults = { action: :save, use_transactions: true }
|
362
371
|
class << self
|
363
372
|
# Classes that inherit from ActiveRecord::Base will automatically use
|
364
373
|
# the ActiveRecord integration.
|
@@ -376,28 +385,29 @@ module StateMachines
|
|
376
385
|
|
377
386
|
# Gets the db default for the machine's attribute
|
378
387
|
def owner_class_attribute_default
|
379
|
-
|
380
|
-
|
381
|
-
|
388
|
+
return unless owner_class.connected? && owner_class.table_exists?
|
389
|
+
|
390
|
+
owner_class.column_defaults[attribute.to_s]
|
382
391
|
end
|
383
392
|
|
384
393
|
def define_state_initializer
|
385
|
-
define_helper :instance, <<-
|
394
|
+
define_helper :instance, <<-END_EVAL, __FILE__, __LINE__ + 1
|
386
395
|
def initialize(attributes = nil, *)
|
387
396
|
super(attributes) do |*args|
|
388
|
-
|
397
|
+
attributes = (attributes || {}).transform_keys { |key| self.class.attribute_aliases[key.to_s] || key }
|
398
|
+
scoped_attributes = attributes.merge(self.class.scope_attributes)
|
389
399
|
|
390
400
|
self.class.state_machines.initialize_states(self, {}, scoped_attributes)
|
391
401
|
yield(*args) if block_given?
|
392
402
|
end
|
393
403
|
end
|
394
|
-
|
404
|
+
END_EVAL
|
395
405
|
end
|
396
406
|
|
397
407
|
# Uses around callbacks to run state events if using the :save hook
|
398
408
|
def define_action_hook
|
399
409
|
if action_hook == :save
|
400
|
-
define_helper :instance, <<-
|
410
|
+
define_helper :instance, <<-END_EVAL, __FILE__, __LINE__ + 1
|
401
411
|
def save(*, **)
|
402
412
|
self.class.state_machine(#{name.inspect}).send(:around_save, self) { super }
|
403
413
|
end
|
@@ -410,34 +420,43 @@ module StateMachines
|
|
410
420
|
def changed_for_autosave?
|
411
421
|
super || self.class.state_machines.any? {|name, machine| machine.action == :save && machine.read(self, :event)}
|
412
422
|
end
|
413
|
-
|
423
|
+
END_EVAL
|
414
424
|
else
|
415
425
|
super
|
416
426
|
end
|
417
427
|
end
|
418
428
|
|
419
429
|
# Runs state events around the machine's :save action
|
420
|
-
def around_save(object)
|
421
|
-
object.class.state_machines.transitions(object, action).perform
|
430
|
+
def around_save(object, &)
|
431
|
+
object.class.state_machines.transitions(object, action).perform(&)
|
422
432
|
end
|
423
433
|
|
424
434
|
# Creates a scope for finding records *with* a particular state or
|
425
435
|
# states for the attribute
|
426
436
|
def create_with_scope(name)
|
427
|
-
|
437
|
+
attr_name = attribute
|
438
|
+
lambda do |klass, values|
|
439
|
+
if values.present?
|
440
|
+
klass.where(attr_name => values)
|
441
|
+
else
|
442
|
+
klass.all
|
443
|
+
end
|
444
|
+
end
|
428
445
|
end
|
429
446
|
|
430
447
|
# Creates a scope for finding records *without* a particular state or
|
431
448
|
# states for the attribute
|
432
449
|
def create_without_scope(name)
|
433
|
-
|
450
|
+
attr_name = attribute
|
451
|
+
lambda do |klass, values|
|
452
|
+
if values.present?
|
453
|
+
klass.where.not(attr_name => values)
|
454
|
+
else
|
455
|
+
klass.all
|
456
|
+
end
|
457
|
+
end
|
434
458
|
end
|
435
459
|
|
436
|
-
# Generates the fully-qualifed column name for this machine's attribute
|
437
|
-
def attribute_column
|
438
|
-
connection = owner_class.connection
|
439
|
-
"#{connection.quote_table_name(owner_class.table_name)}.#{connection.quote_column_name(attribute)}"
|
440
|
-
end
|
441
460
|
|
442
461
|
# Runs a new database transaction, rolling back any changes by raising
|
443
462
|
# an ActiveRecord::Rollback exception if the yielded block fails
|
@@ -456,17 +475,19 @@ module StateMachines
|
|
456
475
|
|
457
476
|
private
|
458
477
|
|
459
|
-
# Defines a new scope with the given name
|
460
|
-
def create_scope(name, scope)
|
461
|
-
lambda { |model, values| model.where(scope.call(values)) }
|
462
|
-
end
|
463
478
|
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
479
|
+
# Generates the results for the given scope based on one or more states to filter by
|
480
|
+
def run_scope(scope, machine, klass, states)
|
481
|
+
values = states.flatten.compact.map { |state| machine.states.fetch(state).value }
|
482
|
+
scope.call(klass, values)
|
483
|
+
end
|
484
|
+
|
485
|
+
# ActiveModel's use of method_missing / respond_to for attribute methods
|
486
|
+
# breaks both ancestor lookups and defined?(super). Need to special-case
|
487
|
+
# the existence of query attribute methods.
|
488
|
+
def owner_class_ancestor_has_method?(scope, method)
|
489
|
+
scope == :instance && method == "#{attribute}?" ? owner_class : super
|
490
|
+
end
|
470
491
|
end
|
471
492
|
register(ActiveRecord)
|
472
493
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: state_machines-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.40.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abdelkader Boudih
|
@@ -11,103 +11,103 @@ cert_chain: []
|
|
11
11
|
date: 1980-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '7.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '7.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: state_machines-activemodel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.10.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.10.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: appraisal
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '1'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 5.4.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 5.4.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: minitest-reporters
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: '13.0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: '13.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: sqlite3
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '1.3'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '1.3'
|
111
111
|
description: Adds support for creating state machines for attributes on ActiveRecord
|
112
112
|
email:
|
113
113
|
- terminale@gmail.com
|
@@ -122,62 +122,11 @@ files:
|
|
122
122
|
- lib/state_machines/integrations/active_record.rb
|
123
123
|
- lib/state_machines/integrations/active_record/locale.rb
|
124
124
|
- lib/state_machines/integrations/active_record/version.rb
|
125
|
-
- test/files/en.yml
|
126
|
-
- test/files/models/post.rb
|
127
|
-
- test/integration_test.rb
|
128
|
-
- test/machine_by_default_test.rb
|
129
|
-
- test/machine_errors_test.rb
|
130
|
-
- test/machine_multiple_test.rb
|
131
|
-
- test/machine_nested_action_test.rb
|
132
|
-
- test/machine_unmigrated_test.rb
|
133
|
-
- test/machine_with_aliased_attribute_test.rb
|
134
|
-
- test/machine_with_callbacks_test.rb
|
135
|
-
- test/machine_with_column_state_attribute_test.rb
|
136
|
-
- test/machine_with_complex_pluralization_scopes_test.rb
|
137
|
-
- test/machine_with_conflicting_predicate_test.rb
|
138
|
-
- test/machine_with_conflicting_state_name_test.rb
|
139
|
-
- test/machine_with_custom_attribute_test.rb
|
140
|
-
- test/machine_with_default_scope_test.rb
|
141
|
-
- test/machine_with_different_column_default_test.rb
|
142
|
-
- test/machine_with_different_integer_column_default_test.rb
|
143
|
-
- test/machine_with_dirty_attribute_and_custom_attributes_during_loopback_test.rb
|
144
|
-
- test/machine_with_dirty_attribute_and_state_events_test.rb
|
145
|
-
- test/machine_with_dirty_attributes_and_custom_attribute_test.rb
|
146
|
-
- test/machine_with_dirty_attributes_during_loopback_test.rb
|
147
|
-
- test/machine_with_dirty_attributes_test.rb
|
148
|
-
- test/machine_with_dynamic_initial_state_test.rb
|
149
|
-
- test/machine_with_event_attributes_on_autosave_test.rb
|
150
|
-
- test/machine_with_event_attributes_on_custom_action_test.rb
|
151
|
-
- test/machine_with_event_attributes_on_save_bang_test.rb
|
152
|
-
- test/machine_with_event_attributes_on_save_test.rb
|
153
|
-
- test/machine_with_event_attributes_on_validation_test.rb
|
154
|
-
- test/machine_with_events_test.rb
|
155
|
-
- test/machine_with_failed_action_test.rb
|
156
|
-
- test/machine_with_failed_after_callbacks_test.rb
|
157
|
-
- test/machine_with_failed_before_callbacks_test.rb
|
158
|
-
- test/machine_with_initialized_state_test.rb
|
159
|
-
- test/machine_with_internationalization_test.rb
|
160
|
-
- test/machine_with_loopback_test.rb
|
161
|
-
- test/machine_with_non_column_state_attribute_defined_test.rb
|
162
|
-
- test/machine_with_same_column_default_test.rb
|
163
|
-
- test/machine_with_same_integer_column_default_test.rb
|
164
|
-
- test/machine_with_scopes_and_joins_test.rb
|
165
|
-
- test/machine_with_scopes_and_owner_subclass_test.rb
|
166
|
-
- test/machine_with_scopes_test.rb
|
167
|
-
- test/machine_with_state_driven_validations_test.rb
|
168
|
-
- test/machine_with_states_test.rb
|
169
|
-
- test/machine_with_static_initial_state_test.rb
|
170
|
-
- test/machine_with_transactions_test.rb
|
171
|
-
- test/machine_with_validations_and_custom_attribute_test.rb
|
172
|
-
- test/machine_with_validations_test.rb
|
173
|
-
- test/machine_without_database_test.rb
|
174
|
-
- test/machine_without_transactions_test.rb
|
175
|
-
- test/model_test.rb
|
176
|
-
- test/test_helper.rb
|
177
125
|
homepage: https://github.com/state-machines/state_machines-activerecord/
|
178
126
|
licenses:
|
179
127
|
- MIT
|
180
|
-
metadata:
|
128
|
+
metadata:
|
129
|
+
rubygems_mfa_required: 'true'
|
181
130
|
rdoc_options: []
|
182
131
|
require_paths:
|
183
132
|
- lib
|
@@ -185,66 +134,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
185
134
|
requirements:
|
186
135
|
- - ">="
|
187
136
|
- !ruby/object:Gem::Version
|
188
|
-
version: '3.
|
137
|
+
version: '3.2'
|
189
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
139
|
requirements:
|
191
140
|
- - ">="
|
192
141
|
- !ruby/object:Gem::Version
|
193
142
|
version: '0'
|
194
143
|
requirements: []
|
195
|
-
rubygems_version: 3.6.
|
144
|
+
rubygems_version: 3.6.9
|
196
145
|
specification_version: 4
|
197
146
|
summary: State machines Active Record Integration
|
198
|
-
test_files:
|
199
|
-
- test/files/en.yml
|
200
|
-
- test/files/models/post.rb
|
201
|
-
- test/integration_test.rb
|
202
|
-
- test/machine_by_default_test.rb
|
203
|
-
- test/machine_errors_test.rb
|
204
|
-
- test/machine_multiple_test.rb
|
205
|
-
- test/machine_nested_action_test.rb
|
206
|
-
- test/machine_unmigrated_test.rb
|
207
|
-
- test/machine_with_aliased_attribute_test.rb
|
208
|
-
- test/machine_with_callbacks_test.rb
|
209
|
-
- test/machine_with_column_state_attribute_test.rb
|
210
|
-
- test/machine_with_complex_pluralization_scopes_test.rb
|
211
|
-
- test/machine_with_conflicting_predicate_test.rb
|
212
|
-
- test/machine_with_conflicting_state_name_test.rb
|
213
|
-
- test/machine_with_custom_attribute_test.rb
|
214
|
-
- test/machine_with_default_scope_test.rb
|
215
|
-
- test/machine_with_different_column_default_test.rb
|
216
|
-
- test/machine_with_different_integer_column_default_test.rb
|
217
|
-
- test/machine_with_dirty_attribute_and_custom_attributes_during_loopback_test.rb
|
218
|
-
- test/machine_with_dirty_attribute_and_state_events_test.rb
|
219
|
-
- test/machine_with_dirty_attributes_and_custom_attribute_test.rb
|
220
|
-
- test/machine_with_dirty_attributes_during_loopback_test.rb
|
221
|
-
- test/machine_with_dirty_attributes_test.rb
|
222
|
-
- test/machine_with_dynamic_initial_state_test.rb
|
223
|
-
- test/machine_with_event_attributes_on_autosave_test.rb
|
224
|
-
- test/machine_with_event_attributes_on_custom_action_test.rb
|
225
|
-
- test/machine_with_event_attributes_on_save_bang_test.rb
|
226
|
-
- test/machine_with_event_attributes_on_save_test.rb
|
227
|
-
- test/machine_with_event_attributes_on_validation_test.rb
|
228
|
-
- test/machine_with_events_test.rb
|
229
|
-
- test/machine_with_failed_action_test.rb
|
230
|
-
- test/machine_with_failed_after_callbacks_test.rb
|
231
|
-
- test/machine_with_failed_before_callbacks_test.rb
|
232
|
-
- test/machine_with_initialized_state_test.rb
|
233
|
-
- test/machine_with_internationalization_test.rb
|
234
|
-
- test/machine_with_loopback_test.rb
|
235
|
-
- test/machine_with_non_column_state_attribute_defined_test.rb
|
236
|
-
- test/machine_with_same_column_default_test.rb
|
237
|
-
- test/machine_with_same_integer_column_default_test.rb
|
238
|
-
- test/machine_with_scopes_and_joins_test.rb
|
239
|
-
- test/machine_with_scopes_and_owner_subclass_test.rb
|
240
|
-
- test/machine_with_scopes_test.rb
|
241
|
-
- test/machine_with_state_driven_validations_test.rb
|
242
|
-
- test/machine_with_states_test.rb
|
243
|
-
- test/machine_with_static_initial_state_test.rb
|
244
|
-
- test/machine_with_transactions_test.rb
|
245
|
-
- test/machine_with_validations_and_custom_attribute_test.rb
|
246
|
-
- test/machine_with_validations_test.rb
|
247
|
-
- test/machine_without_database_test.rb
|
248
|
-
- test/machine_without_transactions_test.rb
|
249
|
-
- test/model_test.rb
|
250
|
-
- test/test_helper.rb
|
147
|
+
test_files: []
|
data/test/files/en.yml
DELETED
data/test/files/models/post.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
ActiveRecord::Base.connection.create_table(:posts, :force => true) do |t|
|
4
|
-
t.string :title
|
5
|
-
t.string :content
|
6
|
-
t.string :state
|
7
|
-
end
|
8
|
-
|
9
|
-
class Post < ActiveRecord::Base
|
10
|
-
state_machine initial: :draft do
|
11
|
-
|
12
|
-
end
|
13
|
-
end
|
data/test/integration_test.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'test_helper'
|
4
|
-
|
5
|
-
class IntegrationTest < BaseTestCase
|
6
|
-
def test_should_have_an_integration_name
|
7
|
-
assert_equal :active_record, StateMachines::Integrations::ActiveRecord.integration_name
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_should_be_before_activemodel
|
11
|
-
integrations = StateMachines::Integrations.list.to_a
|
12
|
-
assert StateMachines::Integrations::ActiveRecord, integrations.first
|
13
|
-
assert StateMachines::Integrations::ActiveModel, integrations.last
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_should_match_if_class_inherits_from_active_record
|
17
|
-
assert StateMachines::Integrations::ActiveRecord.matches?(new_model)
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_should_not_match_if_class_does_not_inherit_from_active_record
|
21
|
-
refute StateMachines::Integrations::ActiveRecord.matches?(Class.new)
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_should_have_defaults
|
25
|
-
assert_equal({action: :save, use_transactions: true}, StateMachines::Integrations::ActiveRecord.defaults)
|
26
|
-
end
|
27
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'test_helper'
|
4
|
-
|
5
|
-
class MachineByDefaultTest < BaseTestCase
|
6
|
-
def setup
|
7
|
-
@model = new_model
|
8
|
-
@machine = StateMachines::Machine.new(@model)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_should_use_save_as_action
|
12
|
-
assert_equal :save, @machine.action
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_should_use_transactions
|
16
|
-
assert_equal true, @machine.use_transactions
|
17
|
-
end
|
18
|
-
end
|
data/test/machine_errors_test.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'test_helper'
|
4
|
-
|
5
|
-
class MachineErrorsTest < BaseTestCase
|
6
|
-
def setup
|
7
|
-
@model = new_model
|
8
|
-
@machine = StateMachines::Machine.new(@model)
|
9
|
-
@record = @model.new
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_should_be_able_to_describe_current_errors
|
13
|
-
@record.errors.add(:id, 'cannot be blank')
|
14
|
-
@record.errors.add(:state, 'is invalid')
|
15
|
-
assert_equal ['Id cannot be blank', 'State is invalid'], @machine.errors_for(@record).split(', ').sort
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_should_describe_as_halted_with_no_errors
|
19
|
-
assert_equal 'Transition halted', @machine.errors_for(@record)
|
20
|
-
end
|
21
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'test_helper'
|
4
|
-
|
5
|
-
class MachineMultipleTest < BaseTestCase
|
6
|
-
def setup
|
7
|
-
@model = new_model do
|
8
|
-
connection.add_column table_name, :status, :string
|
9
|
-
end
|
10
|
-
@state_machine = StateMachines::Machine.new(@model, :initial => :parked)
|
11
|
-
@status_machine = StateMachines::Machine.new(@model, :status, :initial => :idling)
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_should_should_initialize_each_state
|
15
|
-
record = @model.new
|
16
|
-
assert_equal 'parked', record.state
|
17
|
-
assert_equal 'idling', record.status
|
18
|
-
end
|
19
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'test_helper'
|
4
|
-
|
5
|
-
class MachineNestedActionTest < BaseTestCase
|
6
|
-
def setup
|
7
|
-
@callbacks = []
|
8
|
-
|
9
|
-
@model = new_model
|
10
|
-
@machine = StateMachines::Machine.new(@model)
|
11
|
-
@machine.event :ignite do
|
12
|
-
transition :parked => :idling
|
13
|
-
end
|
14
|
-
|
15
|
-
@record = @model.new(:state => 'parked')
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_should_allow_transition_prior_to_creation_if_skipping_action
|
19
|
-
record = @record
|
20
|
-
@model.before_create { record.ignite(false) }
|
21
|
-
result = @record.save
|
22
|
-
|
23
|
-
assert_equal true, result
|
24
|
-
assert_equal "idling", @record.state
|
25
|
-
@record.reload
|
26
|
-
assert_equal "idling", @record.state
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_should_allow_transition_after_creation
|
30
|
-
record = @record
|
31
|
-
@model.after_create { record.ignite }
|
32
|
-
result = @record.save
|
33
|
-
|
34
|
-
assert_equal true, result
|
35
|
-
assert_equal "idling", @record.state
|
36
|
-
@record.reload
|
37
|
-
assert_equal "idling", @record.state
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|