mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
Add spec to make sure that :after_commit callback
does not get triggered if validation failed when auto-save (bang) method is used.
This commit is contained in:
parent
860cecf889
commit
fc8b5efaa8
3 changed files with 17 additions and 1 deletions
|
@ -7,3 +7,6 @@ en:
|
||||||
attributes:
|
attributes:
|
||||||
localizer_test_model:
|
localizer_test_model:
|
||||||
aasm_state/opened: "It's open now!"
|
aasm_state/opened: "It's open now!"
|
||||||
|
errors:
|
||||||
|
messages:
|
||||||
|
record_invalid: "Invalid record"
|
||||||
|
|
|
@ -6,7 +6,12 @@ class Validator < ActiveRecord::Base
|
||||||
:after_transaction_performed_on_run,
|
:after_transaction_performed_on_run,
|
||||||
:before_all_transactions_performed,
|
:before_all_transactions_performed,
|
||||||
:before_transaction_performed_on_fail,
|
:before_transaction_performed_on_fail,
|
||||||
:before_transaction_performed_on_run
|
:before_transaction_performed_on_run,
|
||||||
|
:invalid
|
||||||
|
|
||||||
|
validate do |model|
|
||||||
|
errors.add(:validator, "invalid") if invalid
|
||||||
|
end
|
||||||
|
|
||||||
include AASM
|
include AASM
|
||||||
|
|
||||||
|
|
|
@ -547,6 +547,14 @@ describe 'transitions with persistence' do
|
||||||
expect(validator.name).to eq("name")
|
expect(validator.name).to eq("name")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should not fire :after_commit if validation failed when saving object" do
|
||||||
|
validator = Validator.create(:name => 'name')
|
||||||
|
validator.invalid = true
|
||||||
|
expect { validator.run! }.to raise_error(ActiveRecord::RecordInvalid, 'Invalid record')
|
||||||
|
expect(validator).to be_sleeping
|
||||||
|
expect(validator.name).to eq("name")
|
||||||
|
end
|
||||||
|
|
||||||
it "should not fire if not saving" do
|
it "should not fire if not saving" do
|
||||||
validator = Validator.create(:name => 'name')
|
validator = Validator.create(:name => 'name')
|
||||||
expect(validator).to be_sleeping
|
expect(validator).to be_sleeping
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue