From e8671ae44844c23a546549053697cb5fcc03ea1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20Bo=CC=88ttger?= Date: Fri, 26 Oct 2012 22:40:57 +1300 Subject: [PATCH] refactored inspection spec --- aasm.gemspec | 1 + lib/aasm/supporting_classes/state.rb | 8 ++++++++ spec/unit/aasm_spec.rb | 2 +- spec/unit/conversation_spec.rb | 7 ------- spec/unit/inspection_spec.rb | 7 +++++++ 5 files changed, 17 insertions(+), 8 deletions(-) delete mode 100644 spec/unit/conversation_spec.rb create mode 100644 spec/unit/inspection_spec.rb diff --git a/aasm.gemspec b/aasm.gemspec index 6ec4ae4..92074a2 100644 --- a/aasm.gemspec +++ b/aasm.gemspec @@ -21,6 +21,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'shoulda' s.add_development_dependency 'sqlite3' s.add_development_dependency 'minitest' + # s.add_development_dependency 'debugger' s.add_development_dependency 'ruby-debug-completion' s.files = `git ls-files`.split("\n") diff --git a/lib/aasm/supporting_classes/state.rb b/lib/aasm/supporting_classes/state.rb index 8155a06..ed7e5ab 100644 --- a/lib/aasm/supporting_classes/state.rb +++ b/lib/aasm/supporting_classes/state.rb @@ -16,6 +16,14 @@ module AASM end end + def <=>(state) + if state.is_a? Symbol + name <=> state + else + name <=> state.name + end + end + def fire_callbacks(action, record) action = @options[action] catch :halt_aasm_chain do diff --git a/spec/unit/aasm_spec.rb b/spec/unit/aasm_spec.rb index a6fb699..9001623 100644 --- a/spec/unit/aasm_spec.rb +++ b/spec/unit/aasm_spec.rb @@ -41,7 +41,7 @@ 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 + it "should return a select friendly array of states" do Foo.aasm_states_for_select.should == [['Open', 'open'], ['Closed', 'closed']] end end diff --git a/spec/unit/conversation_spec.rb b/spec/unit/conversation_spec.rb deleted file mode 100644 index 579d55d..0000000 --- a/spec/unit/conversation_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) - -describe 'aasm_states' do - it 'should contain all of the states' do - Conversation.aasm_states.should == [:needs_attention, :read, :closed, :awaiting_response, :junk] - end -end diff --git a/spec/unit/inspection_spec.rb b/spec/unit/inspection_spec.rb new file mode 100644 index 0000000..2c0559c --- /dev/null +++ b/spec/unit/inspection_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +describe 'inspecting AASM' do + it 'should support listing all states in the order they have been defined' do + Conversation.aasm_states.should == [:needs_attention, :read, :closed, :awaiting_response, :junk] + end +end