class MachineWithConflictingHelpersBeforeDefinitionTest

Public Class Methods

human_state_event_name() click to toggle source
# File test/unit/machine_test.rb, line 1466
def self.human_state_event_name
  :human_state_event_name
end
human_state_name() click to toggle source
# File test/unit/machine_test.rb, line 1462
def self.human_state_name
  :human_state_name
end
with_state() click to toggle source
# File test/unit/machine_test.rb, line 1446
def self.with_state
  :with_state
end
with_states() click to toggle source
# File test/unit/machine_test.rb, line 1450
def self.with_states
  :with_states
end
without_state() click to toggle source
# File test/unit/machine_test.rb, line 1454
def self.without_state
  :without_state
end
without_states() click to toggle source
# File test/unit/machine_test.rb, line 1458
def self.without_states
  :without_states
end

Public Instance Methods

create_with_scope(name) click to toggle source
# File test/unit/machine_test.rb, line 1509
def create_with_scope(name)
  lambda {|klass, values| []}
end
create_without_scope(name) click to toggle source
# File test/unit/machine_test.rb, line 1513
def create_without_scope(name)
  lambda {|klass, values| []}
end
human_state_name() click to toggle source
# File test/unit/machine_test.rb, line 1488
def human_state_name
  'parked'
end
setup() click to toggle source
# File test/unit/machine_test.rb, line 1441
def setup
  require 'stringio'
  @original_stderr, $stderr = $stderr, StringIO.new
  
  @superclass = Class.new do
    def self.with_state
      :with_state
    end
    
    def self.with_states
      :with_states
    end
    
    def self.without_state
      :without_state
    end
    
    def self.without_states
      :without_states
    end
    
    def self.human_state_name
      :human_state_name
    end
    
    def self.human_state_event_name
      :human_state_event_name
    end
    
    attr_accessor :status
    
    def state
      'parked'
    end
    
    def state=(value)
      self.status = value
    end
    
    def state?
      true
    end
    
    def state_name
      :parked
    end
    
    def human_state_name
      'parked'
    end
    
    def state_events
      [:ignite]
    end
    
    def state_transitions
      [{:parked => :idling}]
    end
    
    def state_paths
      [[{:parked => :idling}]]
    end
  end
  @klass = Class.new(@superclass)
  
  StateMachine::Integrations.const_set('Custom', Module.new do
    include StateMachine::Integrations::Base
    
    def create_with_scope(name)
      lambda {|klass, values| []}
    end
    
    def create_without_scope(name)
      lambda {|klass, values| []}
    end
  end)
  
  @machine = StateMachine::Machine.new(@klass, :integration => :custom)
  @machine.state :parked, :idling
  @machine.event :ignite
  @object = @klass.new
end
state() click to toggle source
# File test/unit/machine_test.rb, line 1472
def state
  'parked'
end
state=(value) click to toggle source
# File test/unit/machine_test.rb, line 1476
def state=(value)
  self.status = value
end
state?() click to toggle source
# File test/unit/machine_test.rb, line 1480
def state?
  true
end
state_events() click to toggle source
# File test/unit/machine_test.rb, line 1492
def state_events
  [:ignite]
end
state_name() click to toggle source
# File test/unit/machine_test.rb, line 1484
def state_name
  :parked
end
state_paths() click to toggle source
# File test/unit/machine_test.rb, line 1500
def state_paths
  [[{:parked => :idling}]]
end
state_transitions() click to toggle source
# File test/unit/machine_test.rb, line 1496
def state_transitions
  [{:parked => :idling}]
end
teardown() click to toggle source
# File test/unit/machine_test.rb, line 1599
def teardown
  $stderr = @original_stderr
  StateMachine::Integrations.send(:remove_const, 'Custom')
end
test_should_not_define_attribute_predicate() click to toggle source
# File test/unit/machine_test.rb, line 1557
def test_should_not_define_attribute_predicate
  assert @object.state?
end
test_should_not_redefine_attribute_events_reader() click to toggle source
# File test/unit/machine_test.rb, line 1569
def test_should_not_redefine_attribute_events_reader
  assert_equal [:ignite], @object.state_events
end
test_should_not_redefine_attribute_human_name_reader() click to toggle source
# File test/unit/machine_test.rb, line 1565
def test_should_not_redefine_attribute_human_name_reader
  assert_equal 'parked', @object.human_state_name
end
test_should_not_redefine_attribute_name_reader() click to toggle source
# File test/unit/machine_test.rb, line 1561
def test_should_not_redefine_attribute_name_reader
  assert_equal :parked, @object.state_name
end
test_should_not_redefine_attribute_paths_reader() click to toggle source
# File test/unit/machine_test.rb, line 1577
def test_should_not_redefine_attribute_paths_reader
  assert_equal [[{:parked => :idling}]], @object.state_paths
end
test_should_not_redefine_attribute_transitions_reader() click to toggle source
# File test/unit/machine_test.rb, line 1573
def test_should_not_redefine_attribute_transitions_reader
  assert_equal [{:parked => :idling}], @object.state_transitions
end
test_should_not_redefine_attribute_writer() click to toggle source
# File test/unit/machine_test.rb, line 1548
def test_should_not_redefine_attribute_writer
  assert_equal 'parked', @object.state
end
test_should_not_redefine_human_attribute_name_reader() click to toggle source
# File test/unit/machine_test.rb, line 1540
def test_should_not_redefine_human_attribute_name_reader
  assert_equal :human_state_name, @klass.human_state_name
end
test_should_not_redefine_human_event_name_reader() click to toggle source
# File test/unit/machine_test.rb, line 1544
def test_should_not_redefine_human_event_name_reader
  assert_equal :human_state_event_name, @klass.human_state_event_name
end
test_should_not_redefine_plural_with_scope() click to toggle source
# File test/unit/machine_test.rb, line 1528
def test_should_not_redefine_plural_with_scope
  assert_equal :with_states, @klass.with_states
end
test_should_not_redefine_plural_without_scope() click to toggle source
# File test/unit/machine_test.rb, line 1536
def test_should_not_redefine_plural_without_scope
  assert_equal :without_states, @klass.without_states
end
test_should_not_redefine_singular_with_scope() click to toggle source
# File test/unit/machine_test.rb, line 1524
def test_should_not_redefine_singular_with_scope
  assert_equal :with_state, @klass.with_state
end
test_should_not_redefine_singular_without_scope() click to toggle source
# File test/unit/machine_test.rb, line 1532
def test_should_not_redefine_singular_without_scope
  assert_equal :without_state, @klass.without_state
end
test_should_output_warning() click to toggle source
# File test/unit/machine_test.rb, line 1581
def test_should_output_warning
  expected = [
    'Instance method "state_events"',
    'Instance method "state_transitions"',
    'Instance method "state_paths"',
    'Class method "human_state_name"',
    'Class method "human_state_event_name"',
    'Instance method "state_name"',
    'Instance method "human_state_name"',
    'Class method "with_state"',
    'Class method "without_state"',
    'Class method "with_states"',
    'Class method "without_states"'
  ].map {|method| "#{method} is already defined in #{@superclass.to_s}, use generic helper instead or set StateMachine::Machine.ignore_method_conflicts = true.\n"}.join
  
  assert_equal expected, $stderr.string
end