2013-04-24 06:57:06 -04:00
|
|
|
require 'spec_helper'
|
2015-05-15 06:37:28 -04:00
|
|
|
require 'models/default_state.rb'
|
|
|
|
require 'models/provided_state.rb'
|
2015-05-15 06:32:40 -04:00
|
|
|
require 'models/active_record/persisted_state.rb'
|
|
|
|
require 'models/active_record/provided_and_persisted_state.rb'
|
|
|
|
|
|
|
|
load_schema
|
2013-04-24 06:57:06 -04:00
|
|
|
|
2013-04-24 07:51:21 -04:00
|
|
|
describe "reading the current state" do
|
2013-04-24 06:57:06 -04:00
|
|
|
it "uses the AASM default" do
|
2014-01-07 13:35:51 -05:00
|
|
|
expect(DefaultState.new.aasm.current_state).to eql :alpha
|
2013-04-24 06:57:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "uses the provided method" do
|
2014-01-07 13:35:51 -05:00
|
|
|
expect(ProvidedState.new.aasm.current_state).to eql :beta
|
2013-04-24 06:57:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "uses the persistence storage" do
|
2014-01-07 13:35:51 -05:00
|
|
|
expect(PersistedState.new.aasm.current_state).to eql :alpha
|
2013-04-24 06:57:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "uses the provided method even if persisted" do
|
2014-01-07 13:35:51 -05:00
|
|
|
expect(ProvidedAndPersistedState.new.aasm.current_state).to eql :gamma
|
2013-04-24 06:57:06 -04:00
|
|
|
end
|
2016-02-18 02:01:52 -05:00
|
|
|
|
|
|
|
context "after dup" do
|
|
|
|
it "uses the persistence storage" do
|
|
|
|
source = PersistedState.create!
|
|
|
|
copy = source.dup
|
|
|
|
copy.save!
|
|
|
|
|
|
|
|
copy.release!
|
|
|
|
|
|
|
|
expect(source.aasm_state).to eql 'alpha'
|
|
|
|
expect(source.aasm.current_state).to eql :alpha
|
|
|
|
|
|
|
|
source2 = PersistedState.find(source.id)
|
|
|
|
expect(source2.reload.aasm_state).to eql 'alpha'
|
|
|
|
expect(source2.aasm.current_state).to eql :alpha
|
|
|
|
|
|
|
|
expect(copy.aasm_state).to eql 'beta'
|
|
|
|
expect(copy.aasm.current_state).to eql :beta
|
|
|
|
end
|
|
|
|
end
|
2013-04-24 06:57:06 -04:00
|
|
|
end
|
2013-04-24 07:51:21 -04:00
|
|
|
|
2013-04-24 08:19:02 -04:00
|
|
|
describe "writing and persisting the current state" do
|
2013-04-24 07:51:21 -04:00
|
|
|
it "uses the AASM default" do
|
|
|
|
o = DefaultState.new
|
|
|
|
o.release!
|
2014-01-07 13:35:51 -05:00
|
|
|
expect(o.persisted_store).to be_nil
|
2013-04-24 07:51:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "uses the provided method" do
|
|
|
|
o = ProvidedState.new
|
|
|
|
o.release!
|
2014-01-07 13:35:51 -05:00
|
|
|
expect(o.persisted_store).to eql :beta
|
2013-04-24 07:51:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "uses the persistence storage" do
|
|
|
|
o = PersistedState.new
|
|
|
|
o.release!
|
2014-01-07 13:35:51 -05:00
|
|
|
expect(o.persisted_store).to be_nil
|
2013-04-24 07:51:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "uses the provided method even if persisted" do
|
|
|
|
o = ProvidedAndPersistedState.new
|
|
|
|
o.release!
|
2014-01-07 13:35:51 -05:00
|
|
|
expect(o.persisted_store).to eql :beta
|
2013-04-24 08:19:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "writing the current state without persisting it" do
|
|
|
|
it "uses the AASM default" do
|
|
|
|
o = DefaultState.new
|
|
|
|
o.release
|
2014-01-07 13:35:51 -05:00
|
|
|
expect(o.transient_store).to be_nil
|
2013-04-24 08:19:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "uses the provided method" do
|
|
|
|
o = ProvidedState.new
|
|
|
|
o.release
|
2014-01-07 13:35:51 -05:00
|
|
|
expect(o.transient_store).to eql :beta
|
2013-04-24 08:19:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "uses the persistence storage" do
|
|
|
|
o = PersistedState.new
|
|
|
|
o.release
|
2014-01-07 13:35:51 -05:00
|
|
|
expect(o.transient_store).to be_nil
|
2013-04-24 08:19:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "uses the provided method even if persisted" do
|
|
|
|
o = ProvidedAndPersistedState.new
|
|
|
|
o.release
|
2014-01-07 13:35:51 -05:00
|
|
|
expect(o.transient_store).to eql :beta
|
2013-04-24 07:51:21 -04:00
|
|
|
end
|
|
|
|
end
|