mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
bugfix: false is treated as uninitialised state (same as nil) #195
This commit is contained in:
parent
bb01034c1a
commit
cdc3d5e829
5 changed files with 32 additions and 3 deletions
|
@ -7,7 +7,8 @@
|
|||
|
||||
## 4.0.5 (not yet released)
|
||||
|
||||
* an event's `:error` callback now retrieves all arguments passed to the event (see [issue #196](https://github.com/aasm/aasm/issues/196) for details)
|
||||
* bugfix: `false` is treated as uninitialised state (same as `nil`) (see [issue #195](https://github.com/aasm/aasm/issues/195) for details)
|
||||
* bugfix: an event's `:error` callback now retrieves all arguments passed to the event (see [issue #196](https://github.com/aasm/aasm/issues/196) for details)
|
||||
|
||||
## 4.0.5
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ module AASM
|
|||
if new_record?
|
||||
state.blank? ? aasm.determine_state_name(self.class.aasm.initial_state) : state.to_sym
|
||||
else
|
||||
state.nil? ? nil : state.to_sym
|
||||
state.blank? ? nil : state.to_sym
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
ActiveRecord::Migration.suppress_messages do
|
||||
%w{gates readers writers transients simples no_scopes no_direct_assignments thieves localizer_test_models persisted_states provided_and_persisted_states with_enums with_true_enums with_false_enums}.each do |table_name|
|
||||
%w{gates readers writers transients simples no_scopes no_direct_assignments thieves localizer_test_models persisted_states provided_and_persisted_states with_enums with_true_enums with_false_enums false_states}.each do |table_name|
|
||||
ActiveRecord::Migration.create_table table_name, :force => true do |t|
|
||||
t.string "aasm_state"
|
||||
end
|
||||
|
|
|
@ -18,6 +18,24 @@ class Gate < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
class FalseState < ActiveRecord::Base
|
||||
include AASM
|
||||
|
||||
def initialize(*args)
|
||||
super
|
||||
self.aasm_state = false
|
||||
end
|
||||
|
||||
aasm do
|
||||
state :opened
|
||||
state :closed
|
||||
|
||||
event :view do
|
||||
transitions :to => :read, :from => [:needs_attention]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class WithEnum < ActiveRecord::Base
|
||||
include AASM
|
||||
|
||||
|
|
|
@ -270,6 +270,16 @@ describe "instance methods" do
|
|||
|
||||
end
|
||||
|
||||
describe "direct state column access" do
|
||||
it "accepts false states" do
|
||||
f = FalseState.create!
|
||||
expect(f.aasm_state).to eql false
|
||||
expect {
|
||||
f.aasm.events.map(&:name)
|
||||
}.to_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe 'subclasses' do
|
||||
it "should have the same states as its parent class" do
|
||||
expect(DerivateNewDsl.aasm.states).to eq(SimpleNewDsl.aasm.states)
|
||||
|
|
Loading…
Reference in a new issue