1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00

rename aasm_persist to aasm_write_state

add aasm_read_state to complete persistence
This commit is contained in:
Scott Barron 2008-02-21 11:08:55 -05:00
parent 8c02c47160
commit 91794f70fe
2 changed files with 24 additions and 7 deletions

View file

@ -43,15 +43,20 @@ module AASM
# Instance methods
def aasm_current_state
# Persistance? This won't work for activerecord objects
@aasm_current_state || self.class.aasm_initial_state
return @aasm_current_state if @aasm_current_state
if self.respond_to?(:aasm_read_state) || self.private_methods.include?('aasm_read_state')
@aasm_current_state = aasm_read_state
end
return @aasm_read_state if @aasm_current_state
self.class.aasm_initial_state
end
private
def aasm_current_state=(state)
@aasm_current_state = state
if self.respond_to?(:aasm_persist) || self.private_methods.include?('aasm_persist')
aasm_persist
if self.respond_to?(:aasm_write_state) || self.private_methods.include?('aasm_write_state')
aasm_write_state
end
end
end

View file

@ -85,14 +85,26 @@ describe AASM, '- event firing' do
foo.aasm_current_state.should == :closed
end
it 'should attempt to persist if aasm_persist is defined' do
it 'should attempt to persist if aasm_write_state is defined' do
foo = Foo.new
def foo.aasm_persist
def foo.aasm_write_state
end
foo.should_receive(:aasm_persist)
foo.should_receive(:aasm_write_state)
foo.close!
end
end
describe AASM, '- persistence' do
it 'should read the state if it has not been set and aasm_read_state is defined' do
foo = Foo.new
def foo.aasm_read_state
end
foo.should_receive(:aasm_read_state)
foo.aasm_current_state
end
end