Skip to content

Commit

Permalink
implemented requested changes (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgesky authored and laserlemon committed Mar 31, 2017
1 parent 2d58671 commit e9a30dc
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@ Lint/HandleExceptions:
Exclude:
- lib/interactor.rb

Style/EmptyMethod:
Enabled: false

AllCops:
TargetRubyVersion: 2.1
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ gemspec
group :test do
gem "codeclimate-test-reporter", require: false
gem "rspec", "~> 3.2"
gem "rubocop", "~> 0.47.1"
end
3 changes: 1 addition & 2 deletions interactor.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ Gem::Specification.new do |spec|
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
spec.test_files = spec.files.grep(/^spec/)

spec.required_ruby_version = ">= 2.1"
spec.required_ruby_version = ">= 2.0"

spec.add_development_dependency "bundler", "~> 1.9"
spec.add_development_dependency "rake", "~> 10.4"
spec.add_development_dependency "rubocop", "~> 0.47.1"
end
6 changes: 4 additions & 2 deletions lib/interactor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,14 @@ def run!
# each interactor class.
#
# Returns nothing.
def call; end
def call
end

# Public: Reverse prior invocation of an Interactor instance. Any interactor
# class that requires undoing upon downstream failure is expected to overwrite
# the "rollback" instance method.
#
# Returns nothing.
def rollback; end
def rollback
end
end
64 changes: 47 additions & 17 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@
def build_interactor(&block)
interactor = Class.new.send(:include, Interactor)
interactor.class_eval(&block) if block
interactor.class_eval do
def unexpected_error!
raise "foo"
end
end
interactor
end

def build_organizer(options = {}, &block)
organizer = Class.new.send(:include, Interactor::Organizer)
organizer.organize(options[:organize]) if options[:organize]
organizer.class_eval(&block) if block
organizer.class_eval do
def unexpected_error!
raise "foo"
end
end
organizer
end

Expand Down Expand Up @@ -349,8 +359,11 @@ def rollback
let(:organizer) {
interactors = [organizer2, interactor3, organizer4, interactor5]
build_organizer(organize: interactors) do
around do |_interactor|
raise "foo"
around do |interactor|
unexpected_error!
context.steps << :around_before
interactor.call
context.steps << :around_after
end

before do
Expand Down Expand Up @@ -422,7 +435,8 @@ def rollback
end

before do
raise "foo"
unexpected_error!
context.steps << :before
end

after do
Expand Down Expand Up @@ -515,7 +529,8 @@ def rollback
end

after do
raise "foo"
unexpected_error!
context.steps << :after
end
end
}
Expand Down Expand Up @@ -617,7 +632,8 @@ def rollback
around do |interactor|
context.steps << :around_before
interactor.call
raise "foo"
unexpected_error!
context.steps << :around_after
end

before do
Expand Down Expand Up @@ -718,8 +734,11 @@ def rollback
context "when a nested around hook errors early" do
let(:interactor3) {
build_interactor do
around do |_interactor|
raise "foo"
around do |interactor|
unexpected_error!
context.steps << :around_before3
interactor.call
context.steps << :around_after3
end

before do
Expand Down Expand Up @@ -823,7 +842,8 @@ def rollback
end

before do
raise "foo"
unexpected_error!
context.steps << :before3
end

after do
Expand Down Expand Up @@ -932,7 +952,8 @@ def rollback
end

def call
raise "foo"
unexpected_error!
context.steps << :call3
end

def rollback
Expand Down Expand Up @@ -1030,7 +1051,8 @@ def rollback
end

after do
raise "foo"
unexpected_error!
context.steps << :after3
end

def call
Expand Down Expand Up @@ -1125,7 +1147,8 @@ def rollback
around do |interactor|
context.steps << :around_before3
interactor.call
raise "foo"
unexpected_error!
context.steps << :around_after3
end

before do
Expand Down Expand Up @@ -1228,8 +1251,11 @@ def rollback
context "when a deeply nested around hook errors early" do
let(:interactor4b) {
build_interactor do
around do |_interactor|
raise "foo"
around do |interactor|
unexpected_error!
context.steps << :around_before4b
interactor.call
context.steps << :around_after4b
end

before do
Expand Down Expand Up @@ -1343,7 +1369,8 @@ def rollback
end

before do
raise "foo"
unexpected_error!
context.steps << :before4b
end

after do
Expand Down Expand Up @@ -1462,7 +1489,8 @@ def rollback
end

def call
raise "foo"
unexpected_error!
context.steps << :call4b
end

def rollback
Expand Down Expand Up @@ -1570,7 +1598,8 @@ def rollback
end

after do
raise "foo"
unexpected_error!
context.steps << :after4b
end

def call
Expand Down Expand Up @@ -1675,7 +1704,8 @@ def rollback
around do |interactor|
context.steps << :around_before4b
interactor.call
raise "foo"
unexpected_error!
context.steps << :around_after4b
end

before do
Expand Down
5 changes: 2 additions & 3 deletions spec/support/lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@
let(:context) { double(:context) }

it "initializes a context" do
expect(
Interactor::Context
).to receive(:build).once.with(foo: "bar") { context }
expect(Interactor::Context).to receive(:build)
.once.with(foo: "bar") { context }

instance = interactor.new(foo: "bar")

Expand Down

0 comments on commit e9a30dc

Please sign in to comment.