Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inheritance not working as expected #292

Open
h0jeZvgoxFepBQ2C opened this issue Dec 12, 2013 · 1 comment
Open

Inheritance not working as expected #292

h0jeZvgoxFepBQ2C opened this issue Dec 12, 2013 · 1 comment

Comments

@h0jeZvgoxFepBQ2C
Copy link

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"...
@the8472
Copy link

the8472 commented Dec 12, 2013

Your expectations are wrong in this case, not the gem.

Since any number of before and after transition handlers can be registered - nowhere does the documentation state that there is only one singleton handler which gets substituted in place.

You can modify the callbacks array of the machine, or use the :do => :method syntax and override the method instead of trying to replace a nameless proc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants