statesman 7.4.1 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +4 -2
- data/lib/generators/statesman/generator_helpers.rb +10 -2
- data/lib/statesman/adapters/active_record.rb +9 -11
- data/lib/statesman/adapters/active_record_queries.rb +5 -1
- data/lib/statesman/version.rb +1 -1
- data/spec/statesman/adapters/active_record_queries_spec.rb +25 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aeab084afcfb068e82eae390dbac202fb8167884b3a58610429ca2efb30a8b46
|
4
|
+
data.tar.gz: 65f10904ea38a716a26f7acd6d6809a484f4cb51eb5458b98f94d2b29acfd746
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36a6a95abb071113a8a17e59982db8c0c1e82cd189d2b5c0d59e4825f894dfde59a0051357a935ff9c3070520541461a69177a08003c7734252c4c1ae42946b6
|
7
|
+
data.tar.gz: 96887197a7551e0fe65269b727cff3cba0318c459e895836d05969120cd22d6b17f1f9052935ce768f91ff4af9a0d33aff43af025e41bba28f24a1948e188056
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
## v8.0.0 6th January 2021
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
- Use AR Arel table to type cast booleans in order to avoid deprecation warning [#421](https://github.com/gocardless/statesman/pull/421)
|
6
|
+
- Support relationships that doesn't use `id` as a Primary Key
|
7
|
+
[#422](https://github.com/gocardless/statesman/pull/422)
|
8
|
+
|
9
|
+
## v7.4.1 11th November 2020
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
- Add #reset method to state machine and adapter interfaces
|
14
|
+
[#417](https://github.com/gocardless/statesman/pull/417)
|
15
|
+
|
1
16
|
## v7.4.0 26th August 2020
|
2
17
|
|
3
18
|
### Added
|
data/README.md
CHANGED
@@ -404,10 +404,12 @@ Model.in_state(:state_1).or(
|
|
404
404
|
#### Storing the state on the model object
|
405
405
|
|
406
406
|
If you wish to store the model state on the model directly, you can keep it up
|
407
|
-
to date using an `after_transition` hook
|
407
|
+
to date using an `after_transition` hook.
|
408
|
+
Combine it with the `after_commit` option to ensure the model state will only be
|
409
|
+
saved once the transition has made it irreversibly to the database:
|
408
410
|
|
409
411
|
```ruby
|
410
|
-
after_transition do |model, transition|
|
412
|
+
after_transition(after_commit: true) do |model, transition|
|
411
413
|
model.state = transition.to_state
|
412
414
|
model.save!
|
413
415
|
end
|
@@ -39,8 +39,16 @@ module Statesman
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def mysql?
|
42
|
-
|
43
|
-
|
42
|
+
configuration.try(:[], "adapter").try(:match, /mysql/)
|
43
|
+
end
|
44
|
+
|
45
|
+
# [] is deprecated and will be removed in 6.2
|
46
|
+
def configuration
|
47
|
+
if ActiveRecord::Base.configurations.respond_to?(:configs_for)
|
48
|
+
ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).first
|
49
|
+
else
|
50
|
+
ActiveRecord::Base.configurations[Rails.env]
|
51
|
+
end
|
44
52
|
end
|
45
53
|
|
46
54
|
def database_supports_partial_indexes?
|
@@ -305,23 +305,21 @@ module Statesman
|
|
305
305
|
end
|
306
306
|
|
307
307
|
def db_true
|
308
|
-
|
309
|
-
true,
|
310
|
-
transition_class.columns_hash["most_recent"],
|
311
|
-
)
|
312
|
-
::ActiveRecord::Base.connection.quote(value)
|
308
|
+
::ActiveRecord::Base.connection.quote(type_cast(true))
|
313
309
|
end
|
314
310
|
|
315
311
|
def db_false
|
316
|
-
|
317
|
-
false,
|
318
|
-
transition_class.columns_hash["most_recent"],
|
319
|
-
)
|
320
|
-
::ActiveRecord::Base.connection.quote(value)
|
312
|
+
::ActiveRecord::Base.connection.quote(type_cast(false))
|
321
313
|
end
|
322
314
|
|
323
315
|
def db_null
|
324
|
-
|
316
|
+
type_cast(nil)
|
317
|
+
end
|
318
|
+
|
319
|
+
# Type casting against a column is deprecated and will be removed in Rails 6.2.
|
320
|
+
# See https://github.com/rails/arel/commit/6160bfbda1d1781c3b08a33ec4955f170e95be11
|
321
|
+
def type_cast(value)
|
322
|
+
::ActiveRecord::Base.connection.type_cast(value)
|
325
323
|
end
|
326
324
|
|
327
325
|
# Check whether the `most_recent` column allows null values. If it doesn't, set old
|
@@ -104,7 +104,7 @@ module Statesman
|
|
104
104
|
|
105
105
|
def most_recent_transition_join
|
106
106
|
"LEFT OUTER JOIN #{model_table} AS #{most_recent_transition_alias} " \
|
107
|
-
"ON #{model.table_name}
|
107
|
+
"ON #{model.table_name}.#{model_primary_key} = " \
|
108
108
|
"#{most_recent_transition_alias}.#{model_foreign_key} " \
|
109
109
|
"AND #{most_recent_transition_alias}.most_recent = #{db_true}"
|
110
110
|
end
|
@@ -127,6 +127,10 @@ module Statesman
|
|
127
127
|
"and #{transition_class}."
|
128
128
|
end
|
129
129
|
|
130
|
+
def model_primary_key
|
131
|
+
transition_reflection.active_record_primary_key
|
132
|
+
end
|
133
|
+
|
130
134
|
def model_foreign_key
|
131
135
|
transition_reflection.foreign_key
|
132
136
|
end
|
data/lib/statesman/version.rb
CHANGED
@@ -154,6 +154,31 @@ describe Statesman::Adapters::ActiveRecordQueries, active_record: true do
|
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
|
+
context "with a custom primary key for the model" do
|
158
|
+
before do
|
159
|
+
# Switch to using OtherActiveRecordModelTransition, so the existing
|
160
|
+
# relation with MyActiveRecordModelTransition doesn't interfere with
|
161
|
+
# this spec.
|
162
|
+
# Configure the relationship to use a different primary key,
|
163
|
+
MyActiveRecordModel.send(:has_many,
|
164
|
+
:custom_name,
|
165
|
+
class_name: "OtherActiveRecordModelTransition",
|
166
|
+
primary_key: :external_id)
|
167
|
+
|
168
|
+
MyActiveRecordModel.class_eval do
|
169
|
+
def self.transition_class
|
170
|
+
OtherActiveRecordModelTransition
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe ".in_state" do
|
176
|
+
subject(:query) { MyActiveRecordModel.in_state(:succeeded) }
|
177
|
+
|
178
|
+
specify { expect { query }.to_not raise_error }
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
157
182
|
context "after_commit transactional integrity" do
|
158
183
|
before do
|
159
184
|
MyStateMachine.class_eval do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statesman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 8.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GoCardless
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ammeter
|
@@ -303,7 +303,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
303
303
|
- !ruby/object:Gem::Version
|
304
304
|
version: '0'
|
305
305
|
requirements: []
|
306
|
-
rubygems_version: 3.2
|
306
|
+
rubygems_version: 3.1.2
|
307
307
|
signing_key:
|
308
308
|
specification_version: 4
|
309
309
|
summary: A statesman-like state machine library
|