2015-09-17 02:05:30 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'testing the README examples' do
|
|
|
|
|
|
|
|
it 'Usage' do
|
|
|
|
class Job
|
|
|
|
include AASM
|
|
|
|
|
|
|
|
aasm do
|
|
|
|
state :sleeping, :initial => true
|
2015-12-02 04:38:56 -05:00
|
|
|
state :running, :cleaning
|
2015-09-17 02:05:30 -04:00
|
|
|
|
|
|
|
event :run do
|
|
|
|
transitions :from => :sleeping, :to => :running
|
|
|
|
end
|
|
|
|
|
|
|
|
event :clean do
|
|
|
|
transitions :from => :running, :to => :cleaning
|
|
|
|
end
|
|
|
|
|
|
|
|
event :sleep do
|
|
|
|
transitions :from => [:running, :cleaning], :to => :sleeping
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
job = Job.new
|
|
|
|
|
|
|
|
expect(job.sleeping?).to eql true
|
|
|
|
expect(job.may_run?).to eql true
|
|
|
|
|
|
|
|
job.run
|
|
|
|
|
|
|
|
expect(job.running?).to eql true
|
|
|
|
expect(job.sleeping?).to eql false
|
|
|
|
expect(job.may_run?).to eql false
|
|
|
|
|
|
|
|
expect { job.run }.to raise_error(AASM::InvalidTransition)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|