diff --git a/CHANGELOG b/CHANGELOG index 9898a48..7c84192 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Added aasm_states_for_select that will return a select friendly collection of states. + * Add some event callbacks, #aasm_event_fired(from, to), and #aasm_event_failed(event) Based on transition logging suggestion [Artem Vasiliev] and timestamp column suggestion [Mike Ferrier] diff --git a/lib/aasm.rb b/lib/aasm.rb index 9a2f6ef..85aae4b 100644 --- a/lib/aasm.rb +++ b/lib/aasm.rb @@ -64,6 +64,11 @@ module AASM def aasm_events @aasm_events ||= {} end + + def aasm_states_for_select + aasm_states.collect { |state| [state.to_s.gsub(/_/, ' ').capitalize, state] } + end + end # Instance methods diff --git a/spec/unit/aasm_spec.rb b/spec/unit/aasm_spec.rb index b418bf5..9a0582e 100644 --- a/spec/unit/aasm_spec.rb +++ b/spec/unit/aasm_spec.rb @@ -27,17 +27,37 @@ end describe AASM, '- class level definitions' do - it 'should define a class level initial_state() method on its including class' do + it 'should define a class level aasm_initial_state() method on its including class' do Foo.should respond_to(:aasm_initial_state) end - it 'should define a class level state() method on its including class' do + it 'should define a class level aasm_state() method on its including class' do Foo.should respond_to(:aasm_state) end - it 'should define a class level event() method on its including class' do + it 'should define a class level aasm_event() method on its including class' do Foo.should respond_to(:aasm_event) end + + it 'should define a class level aasm_states() method on its including class' do + Foo.should respond_to(:aasm_states) + end + + it 'should define a class level aasm_states_for_select() method on its including class' do + Foo.should respond_to(:aasm_states_for_select) + end + + it 'should define a class level aasm_events() method on its including class' do + Foo.should respond_to(:aasm_events) + end + +end + + +describe AASM, '- aasm_states_for_select' do + it "should return a select friendly array of states in the form of [['Friendly name', :state_name]]" do + Foo.aasm_states_for_select.should == [['Open', :open], ['Closed', :closed]] + end end describe AASM, '- instance level definitions' do