1
0
Fork 0
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:
Anil 2016-09-19 20:13:26 +05:30
parent 860cecf889
commit fc8b5efaa8
3 changed files with 17 additions and 1 deletions

View file

@ -7,3 +7,6 @@ en:
attributes:
localizer_test_model:
aasm_state/opened: "It's open now!"
errors:
messages:
record_invalid: "Invalid record"

View file

@ -6,7 +6,12 @@ class Validator < ActiveRecord::Base
:after_transaction_performed_on_run,
:before_all_transactions_performed,
: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

View file

@ -547,6 +547,14 @@ describe 'transitions with persistence' do
expect(validator.name).to eq("name")
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
validator = Validator.create(:name => 'name')
expect(validator).to be_sleeping