statecraft 0.7.1 → 0.8.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
  SHA256:
3
- metadata.gz: b91fc7675cab350149a2e58679893b18ccdfa779cc84e2eb5a7d28c5591c265c
4
- data.tar.gz: c751611f88af3a85738877185b68de734578a353818aa130c19206d40b498b82
3
+ metadata.gz: 70f23cb88e677af1d36d2acf31fc39a1688f90a46c99d6eebef3e76c49ca4f8e
4
+ data.tar.gz: f38e777eed1a3fa3109da01a9f56eeb09f8c181c9d13e899ab33e3334c372d8b
5
5
  SHA512:
6
- metadata.gz: 42c744386532cf91f06374dc3695c4e2ee3e64602fbb428045e3b588c27dc32843959552dea944be5d98834f28036baf1d712da2c25008dba8b16766ca23310b
7
- data.tar.gz: 86822e6c1fba14b00e6a8e18efc586a7f92f35280490a168e4d96d063a6d3ecd471eac6fe877c512b9972359d1d14f4d344521dc6f0fea56235075df2bae975b
6
+ metadata.gz: 636c11b89dabc3d977f13d503ea7cc311c59dd4c677bfea917b333de36f37c045b1b1ddfec2a1f4643131c0f160dad33651ebf4371c32a365783b8e4c7f1df5f
7
+ data.tar.gz: e09b76e0ca7552f014259429ee4f16ce5ee64b75f4cd829dbffa391ec0604901ba2d9b5a23dd3375bc79f95dc3abe4ca4a77c483634de0343ed2601694bde538
data/README.md CHANGED
@@ -373,6 +373,20 @@ not with the block matcher.
373
373
  it names record-layer guards only. An input-reading `guard:` has no name
374
374
  there, and the failure message says so instead of guessing.
375
375
 
376
+ Under [`versioning:`](#stale-transitions-versioning-against-aba) the block
377
+ matcher folds the version into the same assertion — a matching transition
378
+ must also have incremented the version column — and every failure message
379
+ prints the record's standing with its version
380
+ (`Order in state :pending (state_version 3)`). Staleness stays an
381
+ exception, exactly as in production: assert the refusal of a stale token
382
+ with `raise_error`, not with a prediction matcher —
383
+
384
+ <!-- illustrative -->
385
+ ```ruby
386
+ expect { order.cancel!(seen: stale_token) }
387
+ .to raise_error(Statecraft::StaleTransition)
388
+ ```
389
+
376
390
  ## Metadata
377
391
 
378
392
  Metadata is normalized on pipeline entry with a full JSON round-trip —
@@ -14,7 +14,12 @@ module Statecraft
14
14
  end
15
15
 
16
16
  def standing(record)
17
- "#{record.class.name} in state #{current_state(record).inspect}"
17
+ "#{record.class.name} in state #{current_state(record).inspect}#{version_standing(record)}"
18
+ end
19
+
20
+ def version_standing(record)
21
+ column = record.class.statecraft_mounting.version_column
22
+ column ? " (#{column} #{record[column]})" : ""
18
23
  end
19
24
 
20
25
  def machine(record)
@@ -7,7 +7,8 @@ module Statecraft
7
7
  #
8
8
  # The transition through the eyes of a test: the state column moved to
9
9
  # the target AND exactly one log row was appended with the matching
10
- # from/to/event/metadata. A non-bang call that returned false leaves
10
+ # from/to/event/metadata and under versioning: the version column
11
+ # incremented together with the state. A non-bang call that returned false leaves
11
12
  # both untouched — the matcher fails and explains why, from the same
12
13
  # introspection the pipeline consulted. Exceptions of the bang forms
13
14
  # fly through, like with the change matcher: refusals are asserted
@@ -45,10 +46,13 @@ module Statecraft
45
46
  def matches?(block)
46
47
  raise ArgumentError, "transition(record).to(:state) — the .to target is required" unless @to_state
47
48
 
49
+ @version_column = @record.class.statecraft_mounting.version_column
48
50
  @before_state = StateReport.current_state(@record)
51
+ @before_version = @record[@version_column] if @version_column
49
52
  appended_before = @record.history.count
50
53
  block.call
51
54
  @after_state = StateReport.current_state(@record)
55
+ @after_version = @record[@version_column] if @version_column
52
56
  @appended = @record.history.offset(appended_before).to_a
53
57
  collect_failures
54
58
  @failures.empty?
@@ -84,6 +88,15 @@ module Statecraft
84
88
  @failures << "the record ended in #{@after_state.inspect}, not #{@to_state.inspect}"
85
89
  end
86
90
  collect_row_mismatches(@appended.last)
91
+ collect_version_mismatch
92
+ end
93
+
94
+ def collect_version_mismatch
95
+ return unless @version_column
96
+ return if @after_version == @before_version + 1
97
+
98
+ @failures << "the #{@version_column} column went from #{@before_version} to #{@after_version}, " \
99
+ "expected #{@before_version + 1}: a versioned transition increments the version with the state"
87
100
  end
88
101
 
89
102
  def collect_row_mismatches(row)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Statecraft
4
- VERSION = "0.7.1"
4
+ VERSION = "0.8.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statecraft
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Pugachev