Skip to content

Inheritance not working as expected #292

@h0jeZvgoxFepBQ2C

Description

@h0jeZvgoxFepBQ2C

State Machines in inherited classes cannot be overriden in child classes.

See following example:

class TestModel
  attr_accessor :state

  state_machine :initial => :parked do
    event :ignite do
      transition :parked => :idling
    end
    before_transition :parked => :idling do |m|
      puts "hihihi"
    end
  end
end

class TestModel2 < TestModel

  state_machine :initial => :parked do
    event :ignite do
      transition :parked => :idling
    end
    before_transition :parked => :idling do |m|
      puts "asdasdasd"
    end
  end
end

1.9.3p392 :001 > a = TestModel.new
 => #<TestModel:0x007f81751eb768 @state="parked">
1.9.3p392 :002 > a.ignite
hihihi
 => true
1.9.3p392 :003 > a = TestModel2.new
 => #<TestModel2:0x007f817529bcf8 @state="parked">
1.9.3p392 :004 > a.ignite
hihihi
asdasdasd
 => true
1.9.3p392 :005 >

```ruby

As you can see the "hihihi" output is wrong. We should only see "asdasdasd"...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions