Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove transactions #213

Merged
merged 2 commits into from
Aug 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ end
You may have noticed that ActiveInteraction::Base quacks like
ActiveRecord::Base. It can use validations from your Rails application
and check option validity with `valid?`. Any errors are added to
`errors` which works exactly like an ActiveRecord model. By default,
everything within the `execute` method is run in a transaction if
ActiveRecord is available.
`errors` which works exactly like an ActiveRecord model.

## How do I call an interaction?

Expand Down
1 change: 0 additions & 1 deletion lib/active_interaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
require 'active_interaction/concerns/active_modelable'
require 'active_interaction/concerns/hashable'
require 'active_interaction/concerns/missable'
require 'active_interaction/concerns/transactable'
require 'active_interaction/concerns/runnable'

require 'active_interaction/grouped_input'
Expand Down
25 changes: 1 addition & 24 deletions lib/active_interaction/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,6 @@ class << self
#
# @raise (see ActiveInteraction::Runnable::ClassMethods#run!)

# @!method transaction(enable, options = {})
# Configure transactions by enabling or disabling them and setting
# their options.
#
# @example Disable transactions
# Class.new(ActiveInteraction::Base) do
# transaction false
# end
#
# @example Use different transaction options
# Class.new(ActiveInteraction::Base) do
# transaction true, isolation: :serializable
# end
#
# @param enable [Boolean] Should transactions be enabled?
# @param options [Hash] Options to pass to
# `ActiveRecord::Base.transaction`.
#
# @return [nil]
#
# @since 1.2.0

# Get or set the description.
#
# @example
Expand Down Expand Up @@ -220,8 +198,7 @@ def column_for_attribute(name)
#
# Runs the business logic associated with the interaction. This method is
# only run when there are no validation errors. The return value is
# placed into {#result}. By default, this method is run in a transaction
# if ActiveRecord is available (see {.transaction}).
# placed into {#result}.
#
# @raise (see ActiveInteraction::Runnable#execute)

Expand Down
8 changes: 2 additions & 6 deletions lib/active_interaction/concerns/runnable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ module ActiveInteraction
#
# @note Must be included after `ActiveModel::Validations`.
#
# Runs code in transactions and provides the result.
# Runs code and provides the result.
#
# @private
module Runnable
extend ActiveSupport::Concern
include ActiveModel::Validations
include ActiveInteraction::Transactable

included do
define_callbacks :execute
Expand Down Expand Up @@ -76,15 +75,12 @@ def compose(other, *args)
def run
return unless valid?

self.result = transaction do
self.result =
begin
run_callbacks(:execute) { execute }
rescue Interrupt => interrupt
merge_errors_onto_base(interrupt.outcome.errors)

raise ActiveRecord::Rollback if self.class.transaction?
end
end
end

def merge_errors_onto_base(new_errors)
Expand Down
79 changes: 0 additions & 79 deletions lib/active_interaction/concerns/transactable.rb

This file was deleted.

6 changes: 0 additions & 6 deletions spec/active_interaction/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,6 @@ def execute
it 'sets the result' do
expect(result[:thing]).to eql thing
end

it 'calls #transaction' do
expect_any_instance_of(described_class).to receive(:transaction)
.once.with(no_args)
outcome
end
end
end

Expand Down
32 changes: 0 additions & 32 deletions spec/active_interaction/concerns/runnable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,38 +180,6 @@
end
end

context 'with an execute where composition fails' do
before do
interaction = Class.new(TestInteraction) do
validate { errors.add(:base) }
end

klass.send(:define_method, :execute) { compose(interaction) }
end

it 'rolls back the transaction' do
instance = klass.new

allow(instance).to receive(:raise)
instance.send(:run)
expect(instance).to have_received(:raise)
.with(ActiveRecord::Rollback)
end

context 'without a transaction' do
before { klass.transaction(false) }

it 'does not roll back' do
instance = klass.new

allow(instance).to receive(:raise)
instance.send(:run)
expect(instance).to_not have_received(:raise)
.with(ActiveRecord::Rollback)
end
end
end

context 'with invalid post-execution state' do
before do
klass.class_exec do
Expand Down
135 changes: 0 additions & 135 deletions spec/active_interaction/concerns/transactable_spec.rb

This file was deleted.