class StateContextProxyWithIfConditionTest

Public Instance Methods

setup() click to toggle source
# File test/unit/state_context_test.rb, line 195
def setup
  @klass = Class.new(Validateable)
  machine = StateMachine::Machine.new(@klass, :initial => :parked)
  state = machine.state :parked
  
  @state_context = StateMachine::StateContext.new(state)
  @object = @klass.new
  
  @condition_result = nil
  @options = @state_context.validate(:if => lambda {@condition_result})[0]
end
test_should_be_false_if_original_condition_is_false() click to toggle source
# File test/unit/state_context_test.rb, line 216
def test_should_be_false_if_original_condition_is_false
  @condition_result = false
  assert !@options[:if].call(@object)
end
test_should_be_false_if_state_is_different() click to toggle source
# File test/unit/state_context_test.rb, line 211
def test_should_be_false_if_state_is_different
  @object.state = nil
  assert !@options[:if].call(@object)
end
test_should_be_true_if_state_matches_and_original_condition_is_true() click to toggle source
# File test/unit/state_context_test.rb, line 221
def test_should_be_true_if_state_matches_and_original_condition_is_true
  @condition_result = true
  assert @options[:if].call(@object)
end
test_should_evaluate_string_condition() click to toggle source
# File test/unit/state_context_test.rb, line 241
def test_should_evaluate_string_condition
  @klass.class_eval do
    attr_accessor :callback
  end
  
  options = @state_context.validate(:if => '@callback')[0]
  
  object = @klass.new
  object.callback = false
  assert !options[:if].call(object)
  
  object.callback = true
  assert options[:if].call(object)
end
test_should_evaluate_symbol_condition() click to toggle source
# File test/unit/state_context_test.rb, line 226
def test_should_evaluate_symbol_condition
  @klass.class_eval do
    attr_accessor :callback
  end
  
  options = @state_context.validate(:if => :callback)[0]
  
  object = @klass.new
  object.callback = false
  assert !options[:if].call(object)
  
  object.callback = true
  assert options[:if].call(object)
end
test_should_have_if_option() click to toggle source
# File test/unit/state_context_test.rb, line 207
def test_should_have_if_option
  assert_not_nil @options[:if]
end