mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
fixed event specs
This commit is contained in:
parent
82b5d84452
commit
50e7a252c9
1 changed files with 98 additions and 77 deletions
|
@ -92,9 +92,9 @@ describe 'firing an event' do
|
|||
|
||||
end
|
||||
|
||||
describe 'executing the success callback' do
|
||||
|
||||
it "should send the success callback if it's a symbol" do
|
||||
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
|
||||
transitions :to => :symbol, :from => [:initial]
|
||||
|
@ -106,7 +106,7 @@ describe 'executing the success callback' do
|
|||
model.with_symbol!
|
||||
end
|
||||
|
||||
it "should send the success callback if it's a string" do
|
||||
it "if it's a string" do
|
||||
ThisNameBetterNotBeInUse.instance_eval {
|
||||
aasm_event :with_string, :success => 'string_success_callback' do
|
||||
transitions :to => :string, :from => [:initial]
|
||||
|
@ -118,7 +118,7 @@ describe 'executing the success callback' do
|
|||
model.with_string!
|
||||
end
|
||||
|
||||
it "should call each success callback if passed an array of strings and/or symbols" 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
|
||||
transitions :to => :array, :from => [:initial]
|
||||
|
@ -131,7 +131,7 @@ describe 'executing the success callback' do
|
|||
model.with_array!
|
||||
end
|
||||
|
||||
it "should call each success callback if passed an array of strings and/or symbols and/or procs" 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 { |obj| obj.proc_success_callback }] do
|
||||
transitions :to => :array, :from => [:initial]
|
||||
|
@ -145,7 +145,7 @@ describe 'executing the success callback' do
|
|||
model.with_array_including_procs!
|
||||
end
|
||||
|
||||
it "should call the success callback if it's a proc" do
|
||||
it "if it's a proc" do
|
||||
ThisNameBetterNotBeInUse.instance_eval {
|
||||
aasm_event :with_proc, :success => lambda { |obj| obj.proc_success_callback } do
|
||||
transitions :to => :proc, :from => [:initial]
|
||||
|
@ -156,23 +156,10 @@ describe 'executing the success callback' do
|
|||
model.should_receive(:proc_success_callback)
|
||||
model.with_proc!
|
||||
end
|
||||
|
||||
it "should call the before callback if it's a proc" do
|
||||
ThisNameBetterNotBeInUse.instance_eval do
|
||||
aasm_event :with_proc do
|
||||
before do
|
||||
do_something_before
|
||||
end
|
||||
transitions :to => :proc, :from => [:initial]
|
||||
end
|
||||
end
|
||||
|
||||
model = ThisNameBetterNotBeInUse.new
|
||||
model.should_receive(:do_something_before).once
|
||||
model.with_proc!
|
||||
end
|
||||
|
||||
it "should call the after callbacks if they set different ways" 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
|
||||
after do
|
||||
|
@ -191,6 +178,40 @@ describe 'executing the success callback' do
|
|||
model.should_receive(:do_third_thing_at_last).once.ordered
|
||||
model.with_afters!
|
||||
end
|
||||
end
|
||||
|
||||
describe 'before' do
|
||||
it "if it's a proc" do
|
||||
ThisNameBetterNotBeInUse.instance_eval do
|
||||
aasm_event :before_as_proc do
|
||||
before do
|
||||
do_something_before
|
||||
end
|
||||
transitions :to => :proc, :from => [:initial]
|
||||
end
|
||||
end
|
||||
|
||||
model = ThisNameBetterNotBeInUse.new
|
||||
model.should_receive(:do_something_before).once
|
||||
model.before_as_proc!
|
||||
end
|
||||
end
|
||||
|
||||
it 'in right order' do
|
||||
ThisNameBetterNotBeInUse.instance_eval do
|
||||
aasm_event :in_right_order, :after => :do_something_after do
|
||||
before do
|
||||
do_something_before
|
||||
end
|
||||
transitions :to => :proc, :from => [:initial]
|
||||
end
|
||||
end
|
||||
|
||||
model = ThisNameBetterNotBeInUse.new
|
||||
model.should_receive(:do_something_before).once.ordered
|
||||
model.should_receive(:do_something_after).once.ordered
|
||||
model.in_right_order!
|
||||
end
|
||||
end
|
||||
|
||||
describe 'parametrised events' do
|
||||
|
|
Loading…
Reference in a new issue