diff --git a/spec/models/active_record/api.rb b/spec/models/active_record/api.rb deleted file mode 100644 index d6c33da..0000000 --- a/spec/models/active_record/api.rb +++ /dev/null @@ -1,75 +0,0 @@ -class DefaultState - attr_accessor :transient_store, :persisted_store - include AASM - aasm do - state :alpha, :initial => true - state :beta - state :gamma - event :release do - transitions :from => [:alpha, :beta, :gamma], :to => :beta - end - end -end - -class ProvidedState - attr_accessor :transient_store, :persisted_store - include AASM - aasm do - state :alpha, :initial => true - state :beta - state :gamma - event :release do - transitions :from => [:alpha, :beta, :gamma], :to => :beta - end - end - - def aasm_read_state - :beta - end - - def aasm_write_state(new_state) - @persisted_store = new_state - end - - def aasm_write_state_without_persistence(new_state) - @transient_store = new_state - end -end - -class PersistedState < ActiveRecord::Base - attr_accessor :transient_store, :persisted_store - include AASM - aasm do - state :alpha, :initial => true - state :beta - state :gamma - event :release do - transitions :from => [:alpha, :beta, :gamma], :to => :beta - end - end -end - -class ProvidedAndPersistedState < ActiveRecord::Base - attr_accessor :transient_store, :persisted_store - include AASM - aasm do - state :alpha, :initial => true - state :beta - state :gamma - event :release do - transitions :from => [:alpha, :beta, :gamma], :to => :beta - end - end - - def aasm_read_state - :gamma - end - - def aasm_write_state(new_state) - @persisted_store = new_state - end - - def aasm_write_state_without_persistence(new_state) - @transient_store = new_state - end -end diff --git a/spec/models/active_record/default_state.rb b/spec/models/active_record/default_state.rb new file mode 100644 index 0000000..e5c01d5 --- /dev/null +++ b/spec/models/active_record/default_state.rb @@ -0,0 +1,12 @@ +class DefaultState + attr_accessor :transient_store, :persisted_store + include AASM + aasm do + state :alpha, :initial => true + state :beta + state :gamma + event :release do + transitions :from => [:alpha, :beta, :gamma], :to => :beta + end + end +end diff --git a/spec/models/active_record/persisted_state.rb b/spec/models/active_record/persisted_state.rb new file mode 100644 index 0000000..9d11a61 --- /dev/null +++ b/spec/models/active_record/persisted_state.rb @@ -0,0 +1,12 @@ +class PersistedState < ActiveRecord::Base + attr_accessor :transient_store, :persisted_store + include AASM + aasm do + state :alpha, :initial => true + state :beta + state :gamma + event :release do + transitions :from => [:alpha, :beta, :gamma], :to => :beta + end + end +end diff --git a/spec/models/active_record/provided_and_persisted_state.rb b/spec/models/active_record/provided_and_persisted_state.rb new file mode 100644 index 0000000..1f4e011 --- /dev/null +++ b/spec/models/active_record/provided_and_persisted_state.rb @@ -0,0 +1,24 @@ +class ProvidedAndPersistedState < ActiveRecord::Base + attr_accessor :transient_store, :persisted_store + include AASM + aasm do + state :alpha, :initial => true + state :beta + state :gamma + event :release do + transitions :from => [:alpha, :beta, :gamma], :to => :beta + end + end + + def aasm_read_state + :gamma + end + + def aasm_write_state(new_state) + @persisted_store = new_state + end + + def aasm_write_state_without_persistence(new_state) + @transient_store = new_state + end +end diff --git a/spec/models/active_record/provided_state.rb b/spec/models/active_record/provided_state.rb new file mode 100644 index 0000000..0013a8e --- /dev/null +++ b/spec/models/active_record/provided_state.rb @@ -0,0 +1,24 @@ +class ProvidedState + attr_accessor :transient_store, :persisted_store + include AASM + aasm do + state :alpha, :initial => true + state :beta + state :gamma + event :release do + transitions :from => [:alpha, :beta, :gamma], :to => :beta + end + end + + def aasm_read_state + :beta + end + + def aasm_write_state(new_state) + @persisted_store = new_state + end + + def aasm_write_state_without_persistence(new_state) + @transient_store = new_state + end +end diff --git a/spec/unit/api_spec.rb b/spec/unit/api_spec.rb index 5da2a9e..20fb73b 100644 --- a/spec/unit/api_spec.rb +++ b/spec/unit/api_spec.rb @@ -1,5 +1,10 @@ require 'spec_helper' -require 'models/active_record/api.rb' +require 'models/active_record/default_state.rb' +require 'models/active_record/provided_state.rb' +require 'models/active_record/persisted_state.rb' +require 'models/active_record/provided_and_persisted_state.rb' + +load_schema describe "reading the current state" do it "uses the AASM default" do