File: machine_nested_action_test.rb

package info (click to toggle)
ruby-state-machines-activerecord 0.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 340 kB
  • sloc: ruby: 1,922; makefile: 5
file content (38 lines) | stat: -rw-r--r-- 900 bytes parent folder | download | duplicates (5)
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
32
33
34
35
36
37
38
require_relative 'test_helper'

class MachineNestedActionTest < BaseTestCase
  def setup
    @callbacks = []

    @model = new_model
    @machine = StateMachines::Machine.new(@model)
    @machine.event :ignite do
      transition :parked => :idling
    end

    @record = @model.new(:state => 'parked')
  end

  def test_should_allow_transition_prior_to_creation_if_skipping_action
    record = @record
    @model.before_create { record.ignite(false) }
    result = @record.save

    assert_equal true, result
    assert_equal "idling", @record.state
    @record.reload
    assert_equal "idling", @record.state
  end

  def test_should_allow_transition_after_creation
    record = @record
    @model.after_create { record.ignite }
    result = @record.save

    assert_equal true, result
    assert_equal "idling", @record.state
    @record.reload
    assert_equal "idling", @record.state
  end
end