From 41ca5679bf9fecfef60429ccc6a9bec55935ddc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20B=C3=B6ttger?= Date: Sat, 30 Nov 2013 20:46:36 +0100 Subject: [PATCH] deprecate usage of aasm_current_state (getter method) --- lib/aasm/aasm.rb | 4 ++-- lib/aasm/event.rb | 2 +- .../persistence/active_record_persistence.rb | 16 ++++++++-------- lib/aasm/persistence/mongoid_persistence.rb | 16 ++++++++-------- spec/unit/complex_example_spec.rb | 8 ++++---- spec/unit/event_spec.rb | 17 +++++++---------- spec/unit/initial_state_spec.rb | 7 +++---- spec/unit/inspection_spec.rb | 4 ++-- .../active_record_persistence_spec.rb | 12 ++++++------ spec/unit/simple_example_spec.rb | 3 +-- spec/unit/subclassing_spec.rb | 4 ++-- 11 files changed, 44 insertions(+), 49 deletions(-) diff --git a/lib/aasm/aasm.rb b/lib/aasm/aasm.rb index 09385ca..7dc266d 100644 --- a/lib/aasm/aasm.rb +++ b/lib/aasm/aasm.rb @@ -103,9 +103,9 @@ module AASM true end - # deprecated + # deprecated, remove in v4.0.0 def aasm_current_state - # warn "#aasm_current_state is deprecated and will be removed in version 3.2.0; please use #aasm.state instead!" + warn "#aasm_current_state is deprecated and will be removed in version 4.0.0; please use #aasm.current_state instead!" aasm.current_state end diff --git a/lib/aasm/event.rb b/lib/aasm/event.rb index 7a3c8d5..b565267 100644 --- a/lib/aasm/event.rb +++ b/lib/aasm/event.rb @@ -68,7 +68,7 @@ module AASM def _fire(obj, test, to_state=nil, *args) result = test ? false : nil if @transitions.map(&:from).any? - transitions = @transitions.select { |t| t.from == obj.aasm_current_state } + transitions = @transitions.select { |t| t.from == obj.aasm.current_state } return result if transitions.size == 0 else transitions = @transitions diff --git a/lib/aasm/persistence/active_record_persistence.rb b/lib/aasm/persistence/active_record_persistence.rb index 5adb45c..8ea4044 100644 --- a/lib/aasm/persistence/active_record_persistence.rb +++ b/lib/aasm/persistence/active_record_persistence.rb @@ -71,10 +71,10 @@ module AASM # Writes state to the state column and persists it to the database # # foo = Foo.find(1) - # foo.aasm_current_state # => :opened + # foo.aasm.current_state # => :opened # foo.close! - # foo.aasm_current_state # => :closed - # Foo.find(1).aasm_current_state # => :closed + # foo.aasm.current_state # => :closed + # Foo.find(1).aasm.current_state # => :closed # # NOTE: intended to be called from an event def aasm_write_state(state) @@ -97,13 +97,13 @@ module AASM # Writes state to the state column, but does not persist it to the database # # foo = Foo.find(1) - # foo.aasm_current_state # => :opened + # foo.aasm.current_state # => :opened # foo.close - # foo.aasm_current_state # => :closed - # Foo.find(1).aasm_current_state # => :opened + # foo.aasm.current_state # => :closed + # Foo.find(1).aasm.current_state # => :opened # foo.save - # foo.aasm_current_state # => :closed - # Foo.find(1).aasm_current_state # => :closed + # foo.aasm.current_state # => :closed + # Foo.find(1).aasm.current_state # => :closed # # NOTE: intended to be called from an event def aasm_write_state_without_persistence(state) diff --git a/lib/aasm/persistence/mongoid_persistence.rb b/lib/aasm/persistence/mongoid_persistence.rb index 082f112..44f9864 100644 --- a/lib/aasm/persistence/mongoid_persistence.rb +++ b/lib/aasm/persistence/mongoid_persistence.rb @@ -66,10 +66,10 @@ module AASM # using update_attribute (which bypasses validation) # # foo = Foo.find(1) - # foo.aasm_current_state # => :opened + # foo.aasm.current_state # => :opened # foo.close! - # foo.aasm_current_state # => :closed - # Foo.find(1).aasm_current_state # => :closed + # foo.aasm.current_state # => :closed + # Foo.find(1).aasm.current_state # => :closed # # NOTE: intended to be called from an event def aasm_write_state(state) @@ -87,13 +87,13 @@ module AASM # Writes state to the state column, but does not persist it to the database # # foo = Foo.find(1) - # foo.aasm_current_state # => :opened + # foo.aasm.current_state # => :opened # foo.close - # foo.aasm_current_state # => :closed - # Foo.find(1).aasm_current_state # => :opened + # foo.aasm.current_state # => :closed + # Foo.find(1).aasm.current_state # => :opened # foo.save - # foo.aasm_current_state # => :closed - # Foo.find(1).aasm_current_state # => :closed + # foo.aasm.current_state # => :closed + # Foo.find(1).aasm.current_state # => :closed # # NOTE: intended to be called from an event def aasm_write_state_without_persistence(state) diff --git a/spec/unit/complex_example_spec.rb b/spec/unit/complex_example_spec.rb index b743349..89e1884 100644 --- a/spec/unit/complex_example_spec.rb +++ b/spec/unit/complex_example_spec.rb @@ -4,7 +4,7 @@ describe 'on initialization' do let(:auth) {AuthMachine.new} it 'should be in the pending state' do - auth.aasm_current_state.should == :pending + auth.aasm.current_state.should == :pending end it 'should have an activation code' do @@ -55,14 +55,14 @@ describe 'when being unsuspended' do auth.suspend! auth.unsuspend! - auth.aasm_current_state.should == :active + auth.aasm.current_state.should == :active end it 'should be pending if not previously activated, but an activation code is present' do auth.suspend! auth.unsuspend! - auth.aasm_current_state.should == :pending + auth.aasm.current_state.should == :pending end it 'should be passive if not previously activated and there is no activation code' do @@ -70,6 +70,6 @@ describe 'when being unsuspended' do auth.suspend! auth.unsuspend! - auth.aasm_current_state.should == :passive + auth.aasm.current_state.should == :passive end end diff --git a/spec/unit/event_spec.rb b/spec/unit/event_spec.rb index 936c66b..5601a94 100644 --- a/spec/unit/event_spec.rb +++ b/spec/unit/event_spec.rb @@ -60,8 +60,7 @@ end describe 'firing an event' do it 'should return nil if the transitions are empty' do - obj = double('object') - obj.stub(:aasm_current_state) + obj = double('object', aasm: double('aasm', current_state: 'open')) event = AASM::Event.new(:event) event.fire(obj).should be_nil @@ -72,8 +71,7 @@ describe 'firing an event' do transitions :to => :closed, :from => [:open, :received] end - obj = double('object') - obj.stub(:aasm_current_state).and_return(:open) + obj = double('object', aasm: double('aasm', current_state: :open)) event.fire(obj).should == :closed end @@ -83,8 +81,7 @@ describe 'firing an event' do transitions :to => :closed, :from => [:open, :received], :guard => :guard_fn end - obj = double('object') - obj.stub(:aasm_current_state).and_return(:open) + obj = double('object', aasm: double('aasm', current_state: :open)) obj.should_receive(:guard_fn).with('arg1', 'arg2').and_return(true) event.fire(obj, nil, 'arg1', 'arg2').should == :closed @@ -219,22 +216,22 @@ describe 'parametrised events' do it 'should transition to specified next state (sleeping to showering)' do pe.wakeup!(:showering) - pe.aasm_current_state.should == :showering + pe.aasm.current_state.should == :showering end it 'should transition to specified next state (sleeping to working)' do pe.wakeup!(:working) - pe.aasm_current_state.should == :working + pe.aasm.current_state.should == :working end it 'should transition to default (first or showering) state' do pe.wakeup! - pe.aasm_current_state.should == :showering + pe.aasm.current_state.should == :showering end it 'should transition to default state when on_transition invoked' do pe.dress!(nil, 'purple', 'dressy') - pe.aasm_current_state.should == :working + pe.aasm.current_state.should == :working end it 'should call on_transition method with args' do diff --git a/spec/unit/initial_state_spec.rb b/spec/unit/initial_state_spec.rb index f5afef9..85c5da0 100644 --- a/spec/unit/initial_state_spec.rb +++ b/spec/unit/initial_state_spec.rb @@ -17,12 +17,11 @@ describe 'initial states' do let(:bar) {Bar.new} it 'should use the first state defined if no initial state is given' do - bar.aasm_current_state.should == :read - # bar.aasm.current_state.should == :read # not yet supported + bar.aasm.current_state.should == :read end it 'should determine initial state from the Proc results' do - Banker.new(Banker::RICH - 1).aasm_current_state.should == :selling_bad_mortgages - Banker.new(Banker::RICH + 1).aasm_current_state.should == :retired + Banker.new(Banker::RICH - 1).aasm.current_state.should == :selling_bad_mortgages + Banker.new(Banker::RICH + 1).aasm.current_state.should == :retired end end diff --git a/spec/unit/inspection_spec.rb b/spec/unit/inspection_spec.rb index 8d245c2..2d51fa3 100644 --- a/spec/unit/inspection_spec.rb +++ b/spec/unit/inspection_spec.rb @@ -79,11 +79,11 @@ describe "special cases" do argument = Argument.new argument.invalid?.should be_true - argument.aasm_current_state.should == :invalid + argument.aasm.current_state.should == :invalid argument.valid! argument.valid?.should be_true - argument.aasm_current_state.should == :valid + argument.aasm.current_state.should == :valid end end diff --git a/spec/unit/persistence/active_record_persistence_spec.rb b/spec/unit/persistence/active_record_persistence_spec.rb index 8cb202c..f162cf8 100644 --- a/spec/unit/persistence/active_record_persistence_spec.rb +++ b/spec/unit/persistence/active_record_persistence_spec.rb @@ -24,24 +24,24 @@ describe "instance methods" do end it "should return the initial state when new and the aasm field is nil" do - gate.aasm_current_state.should == :opened + gate.aasm.current_state.should == :opened end it "should return the aasm column when new and the aasm field is not nil" do gate.aasm_state = "closed" - gate.aasm_current_state.should == :closed + gate.aasm.current_state.should == :closed end it "should return the aasm column when not new and the aasm_column is not nil" do gate.stub(:new_record?).and_return(false) gate.aasm_state = "state" - gate.aasm_current_state.should == :state + gate.aasm.current_state.should == :state end it "should allow a nil state" do gate.stub(:new_record?).and_return(false) gate.aasm_state = nil - gate.aasm_current_state.should be_nil + gate.aasm.current_state.should be_nil end it "should call aasm_ensure_initial_state on validation before create" do @@ -119,8 +119,8 @@ end describe 'initial states' do it 'should support conditions' do - Thief.new(:skilled => true).aasm_current_state.should == :rich - Thief.new(:skilled => false).aasm_current_state.should == :jailed + Thief.new(:skilled => true).aasm.current_state.should == :rich + Thief.new(:skilled => false).aasm.current_state.should == :jailed end end diff --git a/spec/unit/simple_example_spec.rb b/spec/unit/simple_example_spec.rb index b7a5c61..3d88c65 100644 --- a/spec/unit/simple_example_spec.rb +++ b/spec/unit/simple_example_spec.rb @@ -20,8 +20,7 @@ describe 'state machine' do let(:payment) {Payment.new} it 'starts with an initial state' do - payment.aasm_current_state.should == :initialised - # payment.aasm.current_state.should == :initialised # not yet supported + payment.aasm.current_state.should == :initialised payment.should respond_to(:initialised?) payment.should be_initialised end diff --git a/spec/unit/subclassing_spec.rb b/spec/unit/subclassing_spec.rb index 7ceb44d..cf31466 100644 --- a/spec/unit/subclassing_spec.rb +++ b/spec/unit/subclassing_spec.rb @@ -24,8 +24,8 @@ describe 'subclassing' do it 'should not break if I call Son#update_state' do son.update_state - son.aasm_current_state.should == :pending_details_confirmation + son.aasm.current_state.should == :pending_details_confirmation end - + end