class MachineFinderWithExistingMachineOnSuperclassTest

Public Class Methods

matches?(klass) click to toggle source
# File test/unit/machine_test.rb, line 3041
def self.matches?(klass)
  false
end

Public Instance Methods

setup() click to toggle source
# File test/unit/machine_test.rb, line 3037
def setup
  integration = Module.new do
    include StateMachine::Integrations::Base
    
    def self.matches?(klass)
      false
    end
  end
  StateMachine::Integrations.const_set('Custom', integration)
  
  @base_class = Class.new
  @base_machine = StateMachine::Machine.new(@base_class, :status, :action => :save, :integration => :custom)
  @base_machine.event(:ignite) {}
  @base_machine.before_transition(lambda {})
  @base_machine.after_transition(lambda {})
  @base_machine.around_transition(lambda {})
  
  @klass = Class.new(@base_class)
  @machine = StateMachine::Machine.find_or_create(@klass, :status) {}
end
teardown() click to toggle source
# File test/unit/machine_test.rb, line 3110
def teardown
  StateMachine::Integrations.send(:remove_const, 'Custom')
end
test_should_accept_a_block() click to toggle source
# File test/unit/machine_test.rb, line 3058
def test_should_accept_a_block
  called = false
  StateMachine::Machine.find_or_create(Class.new(@base_class)) do
    called = respond_to?(:event)
  end
  
  assert called
end
test_should_copy_after_transitions() click to toggle source
# File test/unit/machine_test.rb, line 3102
def test_should_copy_after_transitions
  assert_equal @base_machine.callbacks[:after], @machine.callbacks[:after]
end
test_should_copy_before_callbacks() click to toggle source
# File test/unit/machine_test.rb, line 3098
def test_should_copy_before_callbacks
  assert_equal @base_machine.callbacks[:before], @machine.callbacks[:before]
end
test_should_copy_events() click to toggle source
# File test/unit/machine_test.rb, line 3093
def test_should_copy_events
  # Can't assert equal arrays since their machines change
  assert_equal 1, @machine.events.length
end
test_should_copy_the_base_attribute() click to toggle source
# File test/unit/machine_test.rb, line 3085
def test_should_copy_the_base_attribute
  assert_equal :status, @machine.attribute
end
test_should_copy_the_base_configuration() click to toggle source
# File test/unit/machine_test.rb, line 3089
def test_should_copy_the_base_configuration
  assert_equal :save, @machine.action
end
test_should_create_a_new_machine_if_given_block() click to toggle source
# File test/unit/machine_test.rb, line 3080
def test_should_create_a_new_machine_if_given_block
  assert_not_nil @machine
  assert_not_same @machine, @base_machine
end
test_should_create_a_new_machine_if_given_options() click to toggle source
# File test/unit/machine_test.rb, line 3073
def test_should_create_a_new_machine_if_given_options
  machine = StateMachine::Machine.find_or_create(@klass, :status, :initial => :parked)
  
  assert_not_nil machine
  assert_not_same machine, @base_machine
end
test_should_not_create_a_new_machine_if_no_block_or_options() click to toggle source
# File test/unit/machine_test.rb, line 3067
def test_should_not_create_a_new_machine_if_no_block_or_options
  machine = StateMachine::Machine.find_or_create(Class.new(@base_class), :status)
  
  assert_same machine, @base_machine
end
test_should_use_the_same_integration() click to toggle source
# File test/unit/machine_test.rb, line 3106
def test_should_use_the_same_integration
  assert (class << @machine; ancestors; end).include?(StateMachine::Integrations::Custom)
end