mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
Merge pull request #60 from jherdman/auto-define-state-constants
AASM defines constants for each state name
This commit is contained in:
commit
636a25f45d
3 changed files with 14 additions and 0 deletions
|
@ -1,5 +1,9 @@
|
||||||
# CHANGELOG
|
# CHANGELOG
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
|
* added autocreation of constants for each state ([@jherdman](https://github.com/jherdman))
|
||||||
|
|
||||||
## 3.0.16
|
## 3.0.16
|
||||||
|
|
||||||
* added autocreation of state scopes for Mongoid (thanks to [@jonnyshields](https://github.com/johnnyshields))
|
* added autocreation of state scopes for Mongoid (thanks to [@jonnyshields](https://github.com/johnnyshields))
|
||||||
|
|
|
@ -32,6 +32,10 @@ module AASM
|
||||||
@clazz.send(:define_method, "#{name.to_s}?") do
|
@clazz.send(:define_method, "#{name.to_s}?") do
|
||||||
aasm_current_state == name
|
aasm_current_state == name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
unless @clazz.const_defined?("STATE_#{name.to_s.upcase}")
|
||||||
|
@clazz.const_set("STATE_#{name.to_s.upcase}", name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# define an event
|
# define an event
|
||||||
|
|
|
@ -50,4 +50,10 @@ describe 'state machine' do
|
||||||
lambda {payment.fill_out}.should raise_error(AASM::InvalidTransition)
|
lambda {payment.fill_out}.should raise_error(AASM::InvalidTransition)
|
||||||
lambda {payment.fill_out!}.should raise_error(AASM::InvalidTransition)
|
lambda {payment.fill_out!}.should raise_error(AASM::InvalidTransition)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'defines constants for each state name' do
|
||||||
|
Payment::STATE_INITIALISED.should eq(:initialised)
|
||||||
|
Payment::STATE_FILLED_OUT.should eq(:filled_out)
|
||||||
|
Payment::STATE_AUTHORISED.should eq(:authorised)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue