File: machine_with_failed_after_callbacks_test.rb

package info (click to toggle)
ruby-state-machines-activemodel 0.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 276 kB
  • sloc: ruby: 860; makefile: 5
file content (31 lines) | stat: -rw-r--r-- 974 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require_relative 'test_helper'

class MachineWithFailedAfterCallbacksTest < BaseTestCase
  def setup
    @callbacks = []

    @model = new_model
    @machine = StateMachines::Machine.new(@model, integration: :active_model)
    @machine.state :parked, :idling
    @machine.event :ignite
    @machine.after_transition { @callbacks << :after_1; false }
    @machine.after_transition { @callbacks << :after_2 }
    @machine.around_transition { |block| @callbacks << :around_before; block.call; @callbacks << :around_after }

    @record = @model.new(state: 'parked')
    @transition = StateMachines::Transition.new(@record, @machine, :ignite, :parked, :idling)
    @result = @transition.perform
  end

  def test_should_be_successful
    assert @result
  end

  def test_should_change_current_state
    assert_equal 'idling', @record.state
  end

  def test_should_not_run_further_after_callbacks
    assert_equal [:around_before, :around_after, :after_1], @callbacks
  end
end