Skip to content

Commit

Permalink
fixing issue #66
Browse files Browse the repository at this point in the history
  • Loading branch information
alto committed May 15, 2013
1 parent 8a65d19 commit b602cf8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/aasm/aasm.rb
Expand Up @@ -83,7 +83,10 @@ def aasm

# may be overwritten by persistence mixins
def aasm_read_state
aasm.enter_initial_state
# all the following lines behave like @current_state ||= aasm.enter_initial_state
current = aasm.instance_variable_get("@current_state")
return current if current
aasm.instance_variable_set("@current_state", aasm.enter_initial_state)
end

# may be overwritten by persistence mixins
Expand Down
2 changes: 1 addition & 1 deletion lib/aasm/instance_base.rb
Expand Up @@ -6,7 +6,7 @@ def initialize(instance)
end

def current_state
@current_state ||= @instance.aasm_read_state
@instance.aasm_read_state
end

def current_state=(state)
Expand Down
7 changes: 7 additions & 0 deletions spec/unit/persistence/active_record_persistence_spec.rb
Expand Up @@ -122,6 +122,13 @@

describe 'transitions with persistence' do

it "should work for valid models" do
valid_object = Validator.create(:name => 'name')
valid_object.should be_sleeping
valid_object.status = :running
valid_object.should be_running
end

it 'should not store states for invalid models' do
validator = Validator.create(:name => 'name')
validator.should be_valid
Expand Down

0 comments on commit b602cf8

Please sign in to comment.