mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
initialize the state even if validation is skipped (for Mongoid)
This commit is contained in:
parent
d981489768
commit
09e5ae5937
2 changed files with 18 additions and 0 deletions
|
@ -36,6 +36,8 @@ module AASM
|
||||||
# Mongoid's Validatable gem dependency goes not have a before_validation_on_xxx hook yet.
|
# Mongoid's Validatable gem dependency goes not have a before_validation_on_xxx hook yet.
|
||||||
# base.before_validation_on_create :aasm_ensure_initial_state
|
# base.before_validation_on_create :aasm_ensure_initial_state
|
||||||
base.before_validation :aasm_ensure_initial_state
|
base.before_validation :aasm_ensure_initial_state
|
||||||
|
# ensure initial aasm state even when validations are skipped
|
||||||
|
base.before_create :aasm_ensure_initial_state
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
|
|
|
@ -130,6 +130,22 @@ describe 'mongoid', :if => Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
describe "instance methods" do
|
||||||
|
let(:simple) {SimpleNewDslMongoid.new}
|
||||||
|
|
||||||
|
it "should call aasm_ensure_initial_state on validation before create" do
|
||||||
|
simple.should_receive(:aasm_ensure_initial_state).and_return(true)
|
||||||
|
simple.valid?
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should call aasm_ensure_initial_state before create, even if skipping validations" do
|
||||||
|
simple.should_receive(:aasm_ensure_initial_state).and_return(true)
|
||||||
|
simple.save(:validate => false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
puts "Not running Mongoid specs because mongoid gem if not installed!!!"
|
puts "Not running Mongoid specs because mongoid gem if not installed!!!"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue