1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00

another README example

This commit is contained in:
Thorsten Böttger 2015-09-21 22:18:14 +12:00
parent 12227e7525
commit a696afb5e0
4 changed files with 39 additions and 2 deletions

View file

@ -1,5 +1,5 @@
ActiveRecord::Migration.suppress_messages do
%w{gates multiple_gates readers writers transients simples no_scopes multiple_no_scopes no_direct_assignments multiple_no_direct_assignments thieves multiple_thieves localizer_test_models persisted_states provided_and_persisted_states with_enums with_true_enums with_false_enums false_states multiple_with_enums multiple_with_true_enums multiple_with_false_enums multiple_false_states}.each do |table_name|
%w{gates multiple_gates readers writers transients simples no_scopes multiple_no_scopes no_direct_assignments multiple_no_direct_assignments thieves multiple_thieves localizer_test_models persisted_states provided_and_persisted_states with_enums with_true_enums with_false_enums false_states multiple_with_enums multiple_with_true_enums multiple_with_false_enums multiple_false_states readme_jobs}.each do |table_name|
ActiveRecord::Migration.create_table table_name, :force => true do |t|
t.string "aasm_state"
end

View file

@ -0,0 +1,21 @@
class ReadmeJob < ActiveRecord::Base
include AASM
aasm do
state :sleeping, :initial => true
state :running
state :cleaning
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

View file

@ -521,3 +521,20 @@ describe 'basic example with two state machines' do
expect(example.aasm(:sync).current_state).to eql :unsynced
end
end
describe 'testing the README examples' do
it 'Usage' do
job = ReadmeJob.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

View file

@ -23,7 +23,6 @@ describe 'testing the README examples' do
transitions :from => [:running, :cleaning], :to => :sleeping
end
end
end
job = Job.new