Skip to content

Instantly share code, notes, and snippets.

@siannopollo
Created January 27, 2009 14:51
Show Gist options
  • Select an option

  • Save siannopollo/53370 to your computer and use it in GitHub Desktop.

Select an option

Save siannopollo/53370 to your computer and use it in GitHub Desktop.
class Request < ActiveRecord::Base
state_machine :state, :initial => :pending_owner_approval do
event :approve do
transition :from => :pending_owner_approval, :to => :pending_shipping_confirmation
end
event :deny do
transition :from => :pending_owner_approval, :to => :denied
end
event :shipping_confirmed do
transition :from => :pending_shipping_confirmation, :to => :in_transit
end
event :received do
transition :from => :in_transit, :to => :complete
end
end
end
...
describe 'lifecycle' do
it 'should start out as pending owner approval' do
@model.should be_pending_owner_approval
end
it 'should be approved' do
@model.approve
@model.should be_pending_shipping_confirmation
end
it 'should be denied' do
@model.deny
@model.should be_denied
end
it 'should allow shipping to be confirmed' do
@model.approve
@model.shipping_confirmed
@model.should be_in_transit
end
it 'should allow receipt of the item' do
@model.approve
@model.shipping_confirmed
@model.received
@model.should be_complete
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment