From 23981af963397757b0292f205cf23ec3cae5f095 Mon Sep 17 00:00:00 2001 From: Eugeniy Belyaev Date: Mon, 27 May 2013 21:35:00 +0400 Subject: [PATCH] ActiveRecord integrations now using transactions respecting "use_transactions" config --- lib/state_machine/integrations/active_record.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/state_machine/integrations/active_record.rb b/lib/state_machine/integrations/active_record.rb index bb19f09c..592fdea8 100644 --- a/lib/state_machine/integrations/active_record.rb +++ b/lib/state_machine/integrations/active_record.rb @@ -525,11 +525,15 @@ def attribute_column # an ActiveRecord::Rollback exception if the yielded block fails # (i.e. returns false). def transaction(object) - result = nil - object.class.transaction do - raise ::ActiveRecord::Rollback unless result = yield + if object.class.state_machines[name].use_transactions + result = nil + object.class.transaction do + raise ::ActiveRecord::Rollback unless result = yield + end + result + else + yield end - result end # Defines a new named scope with the given name