Skip to content

Commit

Permalink
Merge pull request #325 from lingceng/master
Browse files Browse the repository at this point in the history
Fix #273 work right after dup
  • Loading branch information
alto committed Mar 18, 2016
2 parents 683330b + 8f4b096 commit 8cd8b6d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/aasm/aasm.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Expand Up @@ -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'
Expand Down
20 changes: 20 additions & 0 deletions spec/unit/api_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 8cd8b6d

Please sign in to comment.