1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00

deprecate usage of AASM.aasm_state (setter method)

This commit is contained in:
Thorsten Böttger 2013-11-30 21:30:07 +01:00
parent 15a8db6db0
commit cbb3d78a80
9 changed files with 29 additions and 128 deletions

View file

@ -53,6 +53,7 @@ module AASM
# deprecated
def aasm_state(name, options={})
warn ".aasm_state is deprecated and will be removed in version 4.0.0; please use .aasm.state instead!"
aasm.state(name, options)
end

View file

@ -1,41 +0,0 @@
class CallbackOldDsl
include AASM
aasm_initial_state :open
aasm_state :open,
:before_enter => :before_enter_open,
:after_enter => :after_enter_open,
:before_exit => :before_exit_open,
:exit => :exit_open,
:after_exit => :after_exit_open
aasm_state :closed,
:before_enter => :before_enter_closed,
:enter => :enter_closed,
:after_enter => :after_enter_closed,
:before_exit => :before_exit_closed,
:after_exit => :after_exit_closed
aasm_event :close, :before => :before, :after => :after do
transitions :to => :closed, :from => [:open]
end
aasm_event :open, :before => :before, :after => :after do
transitions :to => :open, :from => :closed
end
def before_enter_open; end
def before_exit_open; end
def after_enter_open; end
def after_exit_open; end
def before_enter_closed; end
def before_exit_closed; end
def after_enter_closed; end
def after_exit_closed; end
def before; end
def after; end
def enter_closed; end
def exit_open; end
end

View file

@ -4,7 +4,8 @@ class SimpleMongoid
field :status, type: String
aasm_column :status
aasm_state :unknown_scope
aasm_state :new
aasm column: :status do
state :unknown_scope
state :new
end
end

View file

@ -2,16 +2,18 @@ module Models
class Process
include AASM
aasm_state :sleeping
aasm_state :running
aasm_state :suspended
aasm do
state :sleeping
state :running
state :suspended
aasm_event :start do
transitions :from => :sleeping, :to => :running
end
event :start do
transitions :from => :sleeping, :to => :running
end
aasm_event :stop do
transitions :from => :running, :to => :suspended
event :stop do
transitions :from => :running, :to => :suspended
end
end
end

View file

@ -36,13 +36,6 @@ class Transient < ActiveRecord::Base
include AASM
end
class Simple < ActiveRecord::Base
include AASM
aasm_column :status
aasm_state :unknown_scope
aasm_state :new
end
class SimpleNewDsl < ActiveRecord::Base
include AASM
aasm :column => :status
@ -59,9 +52,6 @@ class NoScope < ActiveRecord::Base
end
end
class Derivate < Simple
end
class DerivateNewDsl < SimpleNewDsl
end
@ -73,7 +63,9 @@ class Thief < ActiveRecord::Base
end
include AASM
aasm_initial_state Proc.new { |thief| thief.skilled ? :rich : :jailed }
aasm_state :rich
aasm_state :jailed
aasm do
state :rich
state :jailed
end
attr_accessor :skilled, :aasm_state
end

View file

@ -1,23 +1,5 @@
require 'spec_helper'
describe 'callbacks for the old DSL' do
let(:callback) {CallbackOldDsl.new}
it "should get close callbacks" do
callback.should_receive(:exit_open).once.ordered
callback.should_receive(:before).once.ordered
callback.should_receive(:before_exit_open).once.ordered # these should be before the state changes
callback.should_receive(:before_enter_closed).once.ordered
callback.should_receive(:enter_closed).once.ordered
callback.should_receive(:aasm_write_state).once.ordered.and_return(true) # this is when the state changes
callback.should_receive(:after_exit_open).once.ordered # these should be after the state changes
callback.should_receive(:after_enter_closed).once.ordered
callback.should_receive(:after).once.ordered
callback.close!
end
end
describe 'callbacks for the new DSL' do
let(:callback) {CallbackNewDsl.new}

View file

@ -1,19 +1,6 @@
require 'spec_helper'
describe 'inspection for common cases' do
it 'should support the old DSL' do
Foo.should respond_to(:aasm_states)
Foo.aasm_states.should include(:open)
Foo.aasm_states.should include(:closed)
Foo.should respond_to(:aasm_initial_state)
Foo.aasm_initial_state.should == :open
Foo.should respond_to(:aasm_events)
Foo.aasm_events.should include(:close)
Foo.aasm_events.should include(:null)
end
it 'should support the new DSL' do
Foo.aasm.should respond_to(:states)
Foo.aasm.states.should include(:open)
@ -74,8 +61,8 @@ end
describe "special cases" do
it "should support valid a state name" do
Argument.aasm_states.should include(:invalid)
Argument.aasm_states.should include(:valid)
Argument.aasm.states.should include(:invalid)
Argument.aasm.states.should include(:valid)
argument = Argument.new
argument.invalid?.should be_true

View file

@ -10,12 +10,12 @@ class LocalizerTestModel < ActiveRecord::Base
attr_accessor :aasm_state
aasm_initial_state :opened
aasm_state :opened
aasm_state :closed
aasm_event :close
aasm_event :open
aasm do
state :opened, initial: true
state :closed
event :close
event :open
end
end
describe 'localized state names' do

View file

@ -59,15 +59,11 @@ end
describe 'subclasses' do
it "should have the same states as its parent class" do
Derivate.aasm_states.should == Simple.aasm_states
DerivateNewDsl.aasm.states.should == SimpleNewDsl.aasm.states
end
it "should have the same events as its parent class" do
Derivate.aasm_events.should == Simple.aasm_events
end
it "should have the same column as its parent class" do
Derivate.aasm_column.should == :status
DerivateNewDsl.aasm.events.should == SimpleNewDsl.aasm.events
end
it "should have the same column as its parent even for the new dsl" do
@ -76,26 +72,7 @@ describe 'subclasses' do
end
end
describe "named scopes with the old DSL" do
context "Does not already respond_to? the scope name" do
it "should add a scope" do
Simple.should respond_to(:unknown_scope)
SimpleNewDsl.unknown_scope.is_a?(ActiveRecord::Relation).should be_true
end
end
context "Already respond_to? the scope name" do
it "should not add a scope" do
Simple.should respond_to(:new)
Simple.new.class.should == Simple
end
end
end
describe "named scopes with the new DSL" do
context "Does not already respond_to? the scope name" do
it "should add a scope" do
SimpleNewDsl.should respond_to(:unknown_scope)