diff --git a/spec/database.rb b/spec/database.rb index ca82afd..7a7a19e 100644 --- a/spec/database.rb +++ b/spec/database.rb @@ -55,4 +55,9 @@ ActiveRecord::Migration.suppress_messages do t.string "aasm_state" t.string "type" end + + ActiveRecord::Migration.create_table "basic_active_record_two_state_machines_examples", :force => true do |t| + t.string "search" + t.string "sync" + end end diff --git a/spec/models/active_record/basic_active_record_two_state_machines_example.rb b/spec/models/active_record/basic_active_record_two_state_machines_example.rb new file mode 100644 index 0000000..1bb2169 --- /dev/null +++ b/spec/models/active_record/basic_active_record_two_state_machines_example.rb @@ -0,0 +1,25 @@ +class BasicActiveRecordTwoStateMachinesExample < ActiveRecord::Base + include AASM + + aasm :search, :column => :search do + state :initialised, :initial => true + state :queried + state :requested + + event :query do + transitions :from => [:initialised, :requested], :to => :queried + end + event :request do + transitions :from => :queried, :to => :requested + end + end + + aasm :sync, :column => :sync do + state :unsynced, :initial => true + state :synced + + event :synchronise do + transitions :from => :unsynced, :to => :synced + end + end +end diff --git a/spec/models/basic_two_state_machines_example.rb b/spec/models/basic_two_state_machines_example.rb new file mode 100644 index 0000000..c5af9d6 --- /dev/null +++ b/spec/models/basic_two_state_machines_example.rb @@ -0,0 +1,25 @@ +class BasicTwoStateMachinesExample + include AASM + + aasm :search do + state :initialised, :initial => true + state :queried + state :requested + + event :query do + transitions :from => [:initialised, :requested], :to => :queried + end + event :request do + transitions :from => :queried, :to => :requested + end + end + + aasm :sync do + state :unsynced, :initial => true + state :synced + + event :sync do + transitions :from => :unsynced, :to => :synced + end + end +end diff --git a/spec/unit/basic_two_state_machines_example_spec.rb b/spec/unit/basic_two_state_machines_example_spec.rb new file mode 100644 index 0000000..256e3ac --- /dev/null +++ b/spec/unit/basic_two_state_machines_example_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper' + +describe 'on initialization' do + let(:example) { BasicTwoStateMachinesExample.new } + + it 'should be in the initial state' do + expect(example.aasm(:search).current_state).to eql :initialised + expect(example.aasm(:sync).current_state).to eql :unsynced + end +end diff --git a/spec/unit/complex_multiple_example_spec.rb b/spec/unit/complex_multiple_example_spec.rb index 334406e..f2a043f 100644 --- a/spec/unit/complex_multiple_example_spec.rb +++ b/spec/unit/complex_multiple_example_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe 'on initialization' do let(:auth) {ComplexExampleMultiple.new} - it 'should be in the pending state' do + it 'should be in the initial state' do expect(auth.aasm(:left).current_state).to eq(:pending) expect(auth.aasm(:right).current_state).to eq(:pending) end diff --git a/spec/unit/persistence/active_record_persistence_spec.rb b/spec/unit/persistence/active_record_persistence_spec.rb index 0939b3a..fec9864 100644 --- a/spec/unit/persistence/active_record_persistence_spec.rb +++ b/spec/unit/persistence/active_record_persistence_spec.rb @@ -512,3 +512,12 @@ describe "invalid states with persistence" do end end + +describe 'basic example with two state machines' do + let(:example) { BasicActiveRecordTwoStateMachinesExample.new } + + it 'should initialise properly' do + expect(example.aasm(:search).current_state).to eql :initialised + expect(example.aasm(:sync).current_state).to eql :unsynced + end +end