1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00

bugfix: support reloading development environment in Rails #148

This commit is contained in:
Thorsten Böttger 2014-08-17 18:42:19 +02:00
parent edbb71d8d0
commit ca6f524a98
4 changed files with 45 additions and 1 deletions

View file

@ -4,6 +4,10 @@
* deprecated old aasm_* class methods (old-style DSL), in preparation for AASM v4.0.0
## 3.3.3 (not yet released)
* bugfix: support reloading development environment in Rails (see [issue #148](https://github.com/aasm/aasm/issues/148))
## 3.3.2
* bugfix: avoid conflicts with `failed` and `fired` event names (see [issue #157](https://github.com/aasm/aasm/issues/157)), thanks to [@MichaelXavier](https://github.com/MichaelXavier)

View file

@ -28,7 +28,11 @@ module AASM
def add_state(name, klass, options)
set_initial_state(name, options)
@states << AASM::State.new(name, klass, options) unless @states.include?(name)
# allow reloading, extending or redefining a state
@states.delete(name) if @states.include?(name)
@states << AASM::State.new(name, klass, options)
end
private

View file

@ -0,0 +1,21 @@
class DoubleDefiner
include AASM
aasm do
state :started
state :finished
event :finish do
transitions :from => :started, :to => :finished
end
# simulating a reload
state :finished, :enter => :do_enter
event :finish do
transitions :from => :started, :to => :finished, :on_transition => :do_on_transition
end
end
def do_enter; end
def do_on_transition; end
end

View file

@ -0,0 +1,15 @@
require 'spec_helper'
describe 'callbacks for the new DSL' do
let(:definer) { DoubleDefiner.new }
it "allows extending states" do
expect(definer).to receive(:do_enter)
definer.finish
end
it "allows extending events" do
expect(definer).to receive(:do_on_transition)
definer.finish
end
end