class MachineCollectionFireAttributesWithValidationsTest

Public Class Methods

new() click to toggle source
Calls superclass method
# File test/unit/machine_collection_test.rb, line 553
def initialize
  @errors = []
  super
end

Public Instance Methods

setup() click to toggle source
# File test/unit/machine_collection_test.rb, line 549
def setup
  @klass = Class.new do
    attr_accessor :errors
    
    def initialize
      @errors = []
      super
    end
  end
  
  @machines = StateMachine::MachineCollection.new
  @machines[:state] = @machine = StateMachine::Machine.new(@klass, :state, :initial => :parked, :action => :save)
  @machine.event :ignite do
    transition :parked => :idling
  end
  
  class << @machine
    def invalidate(object, attribute, message, values = [])
      (object.errors ||= []) << generate_message(message, values)
    end
    
    def reset(object)
      object.errors = []
    end
  end
  
  @object = @klass.new
end
test_should_invalidate_if_event_is_invalid() click to toggle source
# File test/unit/machine_collection_test.rb, line 578
def test_should_invalidate_if_event_is_invalid
  @object.state_event = 'invalid'
  @machines.transitions(@object, :save)
  
  assert !@object.errors.empty?
end
test_should_invalidate_if_no_transition_exists() click to toggle source
# File test/unit/machine_collection_test.rb, line 585
def test_should_invalidate_if_no_transition_exists
  @object.state = 'idling'
  @object.state_event = 'ignite'
  @machines.transitions(@object, :save)
  
  assert !@object.errors.empty?
end
test_should_not_invalidate_if_transition_exists() click to toggle source
# File test/unit/machine_collection_test.rb, line 593
def test_should_not_invalidate_if_transition_exists
  @object.state_event = 'ignite'
  @machines.transitions(@object, :save)
  
  assert @object.errors.empty?
end