mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
deprecate usage of aasm_current_state (getter method)
This commit is contained in:
parent
12e7d98ee4
commit
41ca5679bf
11 changed files with 44 additions and 49 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -71,10 +71,10 @@ module AASM
|
|||
# Writes <tt>state</tt> 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 <tt>state</tt> 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)
|
||||
|
|
|
@ -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 <tt>state</tt> 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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue