File: state_without_cached_lambda_value_test.rb

package info (click to toggle)
ruby-state-machines 0.100.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,600 kB
  • sloc: ruby: 18,854; sh: 17; makefile: 4
file content (30 lines) | stat: -rw-r--r-- 746 bytes parent folder | download
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
# frozen_string_literal: true

require 'test_helper'

class StateWithoutCachedLambdaValueTest < StateMachinesTest
  def setup
    @klass = Class.new
    @machine = StateMachines::Machine.new(@klass)
    @dynamic_value = -> { 'value'.dup }
    @machine.states << @state = StateMachines::State.new(@machine, :parked, value: @dynamic_value)
  end

  def test_should_not_be_caching
    refute @state.cache
  end

  def test_should_evaluate_value_each_time
    value1 = @state.value
    value2 = @state.value

    refute_same value1, value2
  end

  def test_should_not_update_value_index_for_state_collection
    @state.value

    assert_nil @machine.states['value', :value]
    assert_equal @state, @machine.states[@dynamic_value, :value]
  end
end