Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
babelian committed Dec 1, 2017
1 parent 0ff2d2f commit 6085fab
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/interactor/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def after(*hooks, &block)
#
# Returns an Array of Symbols and Procs.
def around_hooks
@around_hooks ||= []
@around_hooks ||= superclass && superclass.respond_to?(:around_hooks) ? superclass.around_hooks.dup : []
end

# Internal: An Array of declared hooks to run before Interactor
Expand All @@ -162,7 +162,7 @@ def around_hooks
#
# Returns an Array of Symbols and Procs.
def before_hooks
@before_hooks ||= []
@before_hooks ||= superclass && superclass.respond_to?(:before_hooks) ? superclass.before_hooks.dup : []
end

# Internal: An Array of declared hooks to run before Interactor
Expand All @@ -181,7 +181,7 @@ def before_hooks
#
# Returns an Array of Symbols and Procs.
def after_hooks
@after_hooks ||= []
@after_hooks ||= superclass && superclass.respond_to?(:after_hooks) ? superclass.after_hooks.dup : []
end
end

Expand Down Expand Up @@ -263,4 +263,4 @@ def run_hook(hook, *args)
hook.is_a?(Symbol) ? send(hook, *args) : instance_exec(*args, &hook)
end
end
end
end
49 changes: 48 additions & 1 deletion spec/interactor/hooks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,53 @@ def add_after2
])
end
end

context "inheritance" do
context "around_hooks" do
let(:hooked) {
build_hooked do
around :add_around_before_and_around_after
around { |hooked| hooked.call }
end
}

let(:inherited) { Class.new(hooked) }

it "inherites around hooks from parent class" do
expect(inherited.around_hooks).to eq(hooked.around_hooks)
end
end

context "before_hooks" do
let(:hooked) {
build_hooked do
before :add_before
before {}
end
}

let(:inherited) { Class.new(hooked) }

it "inherites before hooks from parent class" do
expect(inherited.before_hooks).to eq(hooked.before_hooks)
end
end

context "after_hooks" do
let(:hooked) {
build_hooked do
after :add_after
after {}
end
}

let(:inherited) { Class.new(hooked) }

it "inherites after hooks from parent class" do
expect(inherited.after_hooks).to eq(hooked.after_hooks)
end
end
end
end
end
end
end

0 comments on commit 6085fab

Please sign in to comment.