Skip to content

Commit

Permalink
after_commit callbacks should only run if saved
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Tse committed Jun 8, 2014
1 parent ab29f0a commit b983d47
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/aasm/persistence/active_record_persistence.rb
Expand Up @@ -142,7 +142,7 @@ def aasm_fire_event(name, options, *args, &block)
super
end

if success
if success && options[:persist]
new_state = aasm.state_object_for_name(aasm.current_state)
new_state.fire_callbacks(:after_commit, self)
end
Expand Down
8 changes: 8 additions & 0 deletions spec/unit/persistence/active_record_persistence_spec.rb
Expand Up @@ -217,6 +217,14 @@
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
validator.run
expect(validator).to be_running
expect(validator.name).to eq("name")
end

end
end
end
Expand Down

0 comments on commit b983d47

Please sign in to comment.