mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
Fix #273 work right after dup
See: http://www.jonathanleighton.com/articles/2011/initialize_clone-initialize_dup-and-initialize_copy-in-ruby/
This commit is contained in:
parent
e750b83696
commit
8f4b096985
3 changed files with 26 additions and 0 deletions
|
@ -67,6 +67,11 @@ module AASM
|
|||
@aasm[name.to_sym] ||= AASM::InstanceBase.new(self, name.to_sym)
|
||||
end
|
||||
|
||||
def initialize_dup(other)
|
||||
@aasm = {}
|
||||
super
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Takes args and a from state and removes the first
|
||||
|
|
|
@ -3,6 +3,7 @@ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib
|
|||
require 'aasm'
|
||||
require 'rspec'
|
||||
require 'aasm/rspec'
|
||||
require 'pry'
|
||||
|
||||
# require 'ruby-debug'; Debugger.settings[:autoeval] = true; debugger; rubys_debugger = 'annoying'
|
||||
# require 'ruby-debug/completion'
|
||||
|
|
|
@ -22,6 +22,26 @@ describe "reading the current state" do
|
|||
it "uses the provided method even if persisted" do
|
||||
expect(ProvidedAndPersistedState.new.aasm.current_state).to eql :gamma
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
describe "writing and persisting the current state" do
|
||||
|
|
Loading…
Reference in a new issue