mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
another README example
This commit is contained in:
parent
12227e7525
commit
a696afb5e0
4 changed files with 39 additions and 2 deletions
|
@ -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
|
||||
|
|
21
spec/models/active_record/readme_job.rb
Normal file
21
spec/models/active_record/readme_job.rb
Normal 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
|
|
@ -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
|
||||
|
|
|
@ -23,7 +23,6 @@ describe 'testing the README examples' do
|
|||
transitions :from => [:running, :cleaning], :to => :sleeping
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
job = Job.new
|
||||
|
|
Loading…
Add table
Reference in a new issue