Merge branch 'joaovitor/master'

Conflicts:
	spec/functional/conversation_spec.rb
This commit is contained in:
Travis Tilley 2009-05-27 19:55:32 -04:00
commit 56af04d5f0
11 changed files with 97 additions and 93 deletions

View File

@ -1,8 +1,8 @@
PKG_FILES = ["CHANGELOG", "MIT-LICENSE", "Rakefile", "README.rdoc", "TODO", "lib/aasm.rb", "lib/event.rb", "lib/persistence/active_record_persistence.rb", "lib/persistence.rb", "lib/state.rb", "lib/state_machine.rb", "lib/state_transition.rb", "lib/version.rb", "doc/jamis.rb"]
PKG_FILES = ["CHANGELOG", "MIT-LICENSE", "Rakefile", "README.rdoc", "TODO", "lib/aasm.rb", "lib/event.rb", "lib/persistence/active_record_persistence.rb", "lib/persistence.rb", "lib/state.rb", "lib/state_machine.rb", "lib/state_transition.rb", "doc/jamis.rb"]
Gem::Specification.new do |s|
s.name = 'aasm'
s.version = "2.0.5"
s.version = "2.0.6"
s.summary = 'State machine mixin for Ruby objects'
s.description = <<-EOF
AASM is a continuation of the acts as state machine rails plugin, built for plain Ruby objects.

View File

@ -5,7 +5,7 @@ require File.join(File.dirname(__FILE__), 'persistence')
module AASM
def self.Version
'2.0.5'
'2.0.6'
end
class InvalidTransition < RuntimeError
@ -128,6 +128,7 @@ module AASM
def aasm_fire_event(name, persist, *args)
aasm_state_object_for_state(aasm_current_state).call_action(:exit, self)
old_state = self.aasm_current_state
new_state = self.class.aasm_events[name].fire(self, *args)
unless new_state.nil?
@ -142,15 +143,15 @@ module AASM
end
if persist_successful
self.aasm_event_fired(self.aasm_current_state, new_state) if self.respond_to?(:aasm_event_fired)
self.aasm_event_fired(name, old_state, self.aasm_current_state) if self.respond_to?(:aasm_event_fired)
else
self.aasm_event_failed(name) if self.respond_to?(:aasm_event_failed)
self.aasm_event_failed(name, old_state) if self.respond_to?(:aasm_event_failed)
end
persist_successful
else
if self.respond_to?(:aasm_event_failed)
self.aasm_event_failed(name)
self.aasm_event_failed(name, old_state)
end
false

View File

@ -32,14 +32,15 @@ module AASM
@transitions.any? { |t| t.from == state }
end
def execute_success_callback(obj)
case success
def execute_success_callback(obj, success = nil)
callback = success || @success
case(callback)
when String, Symbol
obj.send(success)
when Array
success.each { |meth| obj.send(meth) }
obj.send(callback)
when Proc
success.call(obj)
callback.call(obj)
when Array
callback.each{|meth|self.execute_success_callback(obj, meth)}
end
end

View File

@ -1,4 +1,6 @@
require File.join(File.dirname(__FILE__), "..", "spec_helper")
require File.join(File.dirname(__FILE__), 'conversation')
describe Conversation, 'description' do
it '.aasm_states should contain all of the states' do
Conversation.aasm_states.should == [:needs_attention, :read, :closed, :awaiting_response, :junk]

View File

@ -255,66 +255,52 @@ describe AASM, '- getting events for a state' do
end
describe AASM, '- event callbacks' do
it 'should call aasm_event_fired if defined and successful for bang fire' do
foo = Foo.new
def foo.aasm_event_fired(from, to)
describe "with aasm_event_fired defined" do
before do
@foo = Foo.new
def @foo.aasm_event_fired(event, from, to)
end
end
foo.should_receive(:aasm_event_fired)
foo.close!
it 'should call it for successful bang fire' do
@foo.should_receive(:aasm_event_fired).with(:close, :open, :closed)
@foo.close!
end
it 'should not call aasm_event_fired if defined but persist fails for bang fire' do
foo = Foo.new
def foo.aasm_event_fired(from, to)
end
foo.stub!(:set_aasm_current_state_with_persistence).and_return(false)
foo.should_not_receive(:aasm_event_fired)
foo.close!
it 'should call it for successful non-bang fire' do
@foo.should_receive(:aasm_event_fired)
@foo.close
end
it 'should not call aasm_event_failed if defined and persist fails for bang fire' do
foo = Foo.new
def foo.aasm_event_failed(from, to)
it 'should not call it for failing bang fire' do
@foo.stub!(:set_aasm_current_state_with_persistence).and_return(false)
@foo.should_not_receive(:aasm_event_fired)
@foo.close!
end
foo.stub!(:set_aasm_current_state_with_persistence).and_return(false)
foo.should_receive(:aasm_event_failed)
foo.close!
end
it 'should call aasm_event_fired if defined and successful for non-bang fire' do
foo = Foo.new
def foo.aasm_event_fired(from, to)
describe "with aasm_event_failed defined" do
before do
@foo = Foo.new
def @foo.aasm_event_failed(event, from)
end
end
foo.should_receive(:aasm_event_fired)
foo.close
it 'should call it when transition failed for bang fire' do
@foo.should_receive(:aasm_event_failed).with(:null, :open)
@foo.null!
end
it 'should call aasm_event_failed if defined and transition failed for bang fire' do
foo = Foo.new
def foo.aasm_event_failed(event)
it 'should call it when transition failed for non-bang fire' do
@foo.should_receive(:aasm_event_failed).with(:null, :open)
@foo.null
end
foo.should_receive(:aasm_event_failed)
foo.null!
it 'should not call it if persist fails for bang fire' do
@foo.stub!(:set_aasm_current_state_with_persistence).and_return(false)
@foo.should_receive(:aasm_event_failed)
@foo.close!
end
it 'should call aasm_event_failed if defined and transition failed for non-bang fire' do
foo = Foo.new
def foo.aasm_event_failed(event)
end
foo.should_receive(:aasm_event_failed)
foo.null
end
end

View File

@ -98,6 +98,20 @@ describe AASM::SupportingClasses::Event, 'when executing the success callback' d
model.with_array!
end
it "should call each success callback 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]
end
}
model = ThisNameBetterNotBeInUse.new
model.should_receive(:success_callback1)
model.should_receive(:success_callback2)
model.should_receive(:proc_success_callback)
model.with_array_including_procs!
end
it "should call the success callback if it's a proc" do
ThisNameBetterNotBeInUse.instance_eval {
aasm_event :with_proc, :success => lambda { |obj| obj.proc_success_callback } do