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_event (setter method)

This commit is contained in:
Thorsten Böttger 2013-11-30 21:36:28 +01:00
parent 37ff3db2d8
commit 3cb9ec2e16
4 changed files with 47 additions and 30 deletions

View file

@ -57,8 +57,9 @@ module AASM
aasm.state(name, options)
end
# deprecated
# TODO remove this method in v4.0.0
def aasm_event(name, options = {}, &block)
warn ".aasm_event is deprecated and will be removed in version 4.0.0; please use .aasm.event instead!"
aasm.event(name, options, &block)
end

View file

@ -46,8 +46,6 @@ module AASM
# define an event
def event(name, options={}, &block)
# @clazz.aasm_event(name, options, &block)
@state_machine.events[name] = AASM::Event.new(name, options, &block)
# an addition over standard aasm so that, before firing an event, you can ask

View file

@ -22,10 +22,12 @@ describe 'event callbacks' do
describe "with an error callback defined" do
before do
class Foo
aasm_event :safe_close, :success => :success_callback, :error => :error_callback do
aasm do
event :safe_close, :success => :success_callback, :error => :error_callback do
transitions :to => :closed, :from => [:open]
end
end
end
@foo = Foo.new
end

View file

@ -93,9 +93,11 @@ describe 'should fire callbacks' do
describe 'success' do
it "if it's a symbol" do
ThisNameBetterNotBeInUse.instance_eval {
aasm_event :with_symbol, :success => :symbol_success_callback do
aasm do
event :with_symbol, :success => :symbol_success_callback do
transitions :to => :symbol, :from => [:initial]
end
end
}
model = ThisNameBetterNotBeInUse.new
@ -105,9 +107,11 @@ describe 'should fire callbacks' do
it "if it's a string" do
ThisNameBetterNotBeInUse.instance_eval {
aasm_event :with_string, :success => 'string_success_callback' do
aasm do
event :with_string, :success => 'string_success_callback' do
transitions :to => :string, :from => [:initial]
end
end
}
model = ThisNameBetterNotBeInUse.new
@ -117,9 +121,11 @@ describe 'should fire callbacks' do
it "if passed an array of strings and/or symbols" do
ThisNameBetterNotBeInUse.instance_eval {
aasm_event :with_array, :success => [:success_callback1, 'success_callback2'] do
aasm do
event :with_array, :success => [:success_callback1, 'success_callback2'] do
transitions :to => :array, :from => [:initial]
end
end
}
model = ThisNameBetterNotBeInUse.new
@ -130,9 +136,11 @@ describe 'should fire callbacks' do
it "if passed an array of strings and/or symbols and/or procs" do
ThisNameBetterNotBeInUse.instance_eval {
aasm_event :with_array_including_procs, :success => [:success_callback1, 'success_callback2', lambda { proc_success_callback }] do
aasm do
event :with_array_including_procs, :success => [:success_callback1, 'success_callback2', lambda { proc_success_callback }] do
transitions :to => :array, :from => [:initial]
end
end
}
model = ThisNameBetterNotBeInUse.new
@ -144,9 +152,11 @@ describe 'should fire callbacks' do
it "if it's a proc" do
ThisNameBetterNotBeInUse.instance_eval {
aasm_event :with_proc, :success => lambda { proc_success_callback } do
aasm do
event :with_proc, :success => lambda { proc_success_callback } do
transitions :to => :proc, :from => [:initial]
end
end
}
model = ThisNameBetterNotBeInUse.new
@ -158,7 +168,8 @@ describe 'should fire callbacks' do
describe 'after' do
it "if they set different ways" do
ThisNameBetterNotBeInUse.instance_eval do
aasm_event :with_afters, :after => :do_one_thing_after do
aasm do
event :with_afters, :after => :do_one_thing_after do
after do
do_another_thing_after_too
end
@ -168,6 +179,7 @@ describe 'should fire callbacks' do
transitions :to => :proc, :from => [:initial]
end
end
end
model = ThisNameBetterNotBeInUse.new
model.should_receive(:do_one_thing_after).once.ordered
@ -180,13 +192,15 @@ describe 'should fire callbacks' do
describe 'before' do
it "if it's a proc" do
ThisNameBetterNotBeInUse.instance_eval do
aasm_event :before_as_proc do
aasm do
event :before_as_proc do
before do
do_something_before
end
transitions :to => :proc, :from => [:initial]
end
end
end
model = ThisNameBetterNotBeInUse.new
model.should_receive(:do_something_before).once
@ -196,13 +210,15 @@ describe 'should fire callbacks' do
it 'in right order' do
ThisNameBetterNotBeInUse.instance_eval do
aasm_event :in_right_order, :after => :do_something_after do
aasm do
event :in_right_order, :after => :do_something_after do
before do
do_something_before
end
transitions :to => :proc, :from => [:initial]
end
end
end
model = ThisNameBetterNotBeInUse.new
model.should_receive(:do_something_before).once.ordered