diff --git a/lib/aasm/aasm.rb b/lib/aasm/aasm.rb index ea913ab3..07852d00 100644 --- a/lib/aasm/aasm.rb +++ b/lib/aasm/aasm.rb @@ -70,6 +70,11 @@ def aasm(name=:default) @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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 58fd663d..4f0c650c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,6 +3,7 @@ require 'aasm' require 'rspec' require 'aasm/rspec' +require 'pry' # require 'ruby-debug'; Debugger.settings[:autoeval] = true; debugger; rubys_debugger = 'annoying' # require 'ruby-debug/completion' diff --git a/spec/unit/api_spec.rb b/spec/unit/api_spec.rb index 56cadd67..e16850df 100644 --- a/spec/unit/api_spec.rb +++ b/spec/unit/api_spec.rb @@ -22,6 +22,26 @@ 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