Skip to content

Commit

Permalink
Implement Router#resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
apexatoll committed Sep 22, 2023
1 parent b27e1b0 commit 1d12ef7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/kangaru/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def initialize(command, namespace: Object)
validate_action_defined!
end

def resolve
controller_class.new(command).execute
end

private

def controller_class
Expand Down
2 changes: 2 additions & 0 deletions sig/kangaru/router.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module Kangaru

def initialize: (Command, ?namespace: Module) -> void

def resolve: -> void

private

@controller_class: untyped
Expand Down
20 changes: 20 additions & 0 deletions spec/kangaru/router_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,24 @@
end
end
end

describe "#resolve" do
subject(:resolve) { router.resolve }

let(:controller_spy) { instance_spy(controller_class) }

before do
allow(controller_class).to receive(:new).and_return(controller_spy)
end

it "instantiates a controller instance" do
resolve
expect(controller_class).to have_received(:new).with(command)
end

it "triggers the controller to execute the command" do
resolve
expect(controller_spy).to have_received(:execute).once
end
end
end

0 comments on commit 1d12ef7

Please sign in to comment.