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

bugfix: initialize the aasm state column after initialization of the ActiveRecord instance only if the attribute has been loaded #193

This commit is contained in:
Thorsten Böttger 2014-12-06 11:15:12 +01:00
parent adbe338582
commit e48fcc1161
4 changed files with 22 additions and 5 deletions

View file

@ -5,6 +5,10 @@
* `aasm_column` has been removed. Use `aasm.attribute_name` instead
* `aasm_human_event_name` has been removed. Use `aasm.human_event_name` instead
## 4.0.5
* bugfix: initialize the aasm state column after initialization of the _ActiveRecord_ instance only if the attribute has been loaded (see [issue #193](https://github.com/aasm/aasm/issues/193) for details)
## 4.0.4
* corrected callback order in README

View file

@ -19,7 +19,7 @@ Gem::Specification.new do |s|
# debugging
# s.add_development_dependency 'debugger'
# s.add_development_dependency 'pry'
s.add_development_dependency 'pry'
# test coverage
# s.add_development_dependency 'mime-types', '~> 1.25' # needed by coveralls (>= 2.0 needs Ruby >=1.9.2)

View file

@ -164,7 +164,9 @@ module AASM
# foo.aasm_state # => nil
#
def aasm_ensure_initial_state
aasm.enter_initial_state if send(self.class.aasm.attribute_name).blank?
if respond_to?(self.class.aasm.attribute_name) && send(self.class.aasm.attribute_name).blank?
aasm.enter_initial_state
end
end
def aasm_fire_event(name, options, *args, &block)

View file

@ -252,9 +252,20 @@ describe "instance methods" do
expect(gate.aasm.current_state).to be_nil
end
it "should initialize the aasm state on instantiation" do
expect(Gate.new.aasm_state).to eql 'opened'
expect(Gate.new.aasm.current_state).to eql :opened
context 'on initialization' do
it "should initialize the aasm state" do
expect(Gate.new.aasm_state).to eql 'opened'
expect(Gate.new.aasm.current_state).to eql :opened
end
it "should not initialize the aasm state if it has not been loaded" do
# we have to create a gate in the database, for which we only want to
# load the id, and not the state
gate = Gate.create!
# then we just load the gate ids
Gate.select(:id).where(id: gate.id).first
end
end
end