From dc4abd783f35d1a225e0223444c76586cf020d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20Bo=CC=88ttger?= Date: Fri, 16 Sep 2011 17:12:10 +0200 Subject: [PATCH] added test for issue #19 --- spec/spec_helpers/models_test_helper.rb | 11 +++++++++++ spec/unit/aasm_spec.rb | 18 ++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/spec/spec_helpers/models_test_helper.rb b/spec/spec_helpers/models_test_helper.rb index c176674..8da6838 100644 --- a/spec/spec_helpers/models_test_helper.rb +++ b/spec/spec_helpers/models_test_helper.rb @@ -54,3 +54,14 @@ class Banker def initialize(balance = 0); self.balance = balance; end def rich?; self.balance >= RICH; end end + +class Argument + include AASM + aasm_initial_state :invalid + aasm_state :invalid + aasm_state :valid + + aasm_event :valid do + transitions :to => :valid, :from => [:invalid] + end +end diff --git a/spec/unit/aasm_spec.rb b/spec/unit/aasm_spec.rb index 8f63156..47521fd 100644 --- a/spec/unit/aasm_spec.rb +++ b/spec/unit/aasm_spec.rb @@ -27,6 +27,20 @@ describe AASM, '- class level definitions' do end +describe "naming" do + it "work for valid" do + Argument.aasm_states.should include(:invalid) + Argument.aasm_states.should include(:valid) + + argument = Argument.new + argument.invalid?.should be_true + argument.aasm_current_state.should == :invalid + + argument.valid! + argument.valid?.should be_true + argument.aasm_current_state.should == :valid + end +end describe AASM, '- subclassing' do it 'should have the parent states' do @@ -235,10 +249,10 @@ describe AASM, '- event callbacks' do @foo.stub!(:enter).and_raise(StandardError) lambda{@foo.safe_close!}.should raise_error(NoMethodError) end - + it "should propagate an error if no error callback is declared" do @foo.stub!(:enter).and_raise("Cannot enter safe") - lambda{@foo.close!}.should raise_error(StandardError, "Cannot enter safe") + lambda{@foo.close!}.should raise_error(StandardError, "Cannot enter safe") end end