mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
make sure to use override configuration options if state machine is defined more than once (see #287)
This commit is contained in:
parent
543c1f3bb8
commit
4b32ab1a4e
4 changed files with 25 additions and 3 deletions
|
@ -1,5 +1,9 @@
|
|||
# CHANGELOG
|
||||
|
||||
## unreleased
|
||||
|
||||
* make sure to use override configuration options if state machine is defined more than once (see [issue #287](https://github.com/aasm/aasm/issues/287) for details)
|
||||
|
||||
## 4.5.0
|
||||
|
||||
* add RSpec matchers `have_state`, `allow_event` and `allow_transition_to` (see [issue #147](https://github.com/aasm/aasm/issues/147) for details)
|
||||
|
|
|
@ -39,7 +39,20 @@ module AASM
|
|||
AASM::StateMachine[self][state_machine_name] ||= AASM::StateMachine.new(state_machine_name)
|
||||
|
||||
@aasm ||= {}
|
||||
@aasm[state_machine_name] ||= AASM::Base.new(self, state_machine_name, AASM::StateMachine[self][state_machine_name], options)
|
||||
if @aasm[state_machine_name]
|
||||
# make sure to use provided options
|
||||
options.each do |key, value|
|
||||
@aasm[state_machine_name].state_machine.config.send("#{key}=", value)
|
||||
end
|
||||
else
|
||||
# create a new base
|
||||
@aasm[state_machine_name] = AASM::Base.new(
|
||||
self,
|
||||
state_machine_name,
|
||||
AASM::StateMachine[self][state_machine_name],
|
||||
options
|
||||
)
|
||||
end
|
||||
@aasm[state_machine_name].instance_eval(&block) if block # new DSL
|
||||
@aasm[state_machine_name]
|
||||
end
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
class Silencer
|
||||
include AASM
|
||||
|
||||
# yes, this line is here on purpose
|
||||
# by this, we test if overriding configuration options works if
|
||||
# the state machine is "re-opened"
|
||||
aasm :whiny_transitions => true
|
||||
|
||||
aasm :whiny_transitions => false do
|
||||
state :silent, :initial => true
|
||||
state :crying
|
||||
|
|
|
@ -31,7 +31,7 @@ describe 'transitions' do
|
|||
expect(silencer).to be_smiling
|
||||
end
|
||||
|
||||
it 'should call the block when success' do
|
||||
it 'should call the block on success' do
|
||||
silencer = Silencer.new
|
||||
success = false
|
||||
expect {
|
||||
|
@ -41,7 +41,7 @@ describe 'transitions' do
|
|||
}.to change { success }.to(true)
|
||||
end
|
||||
|
||||
it 'should not call the block when failure' do
|
||||
it 'should not call the block on failure' do
|
||||
silencer = Silencer.new
|
||||
success = false
|
||||
expect {
|
||||
|
|
Loading…
Add table
Reference in a new issue