diff --git a/lib/controll/flow_handler/action_mapper/action.rb b/lib/controll/flow_handler/action_mapper/action.rb index 6f40869..c59e405 100644 --- a/lib/controll/flow_handler/action_mapper/action.rb +++ b/lib/controll/flow_handler/action_mapper/action.rb @@ -1,6 +1,6 @@ module Controll::FlowHandler::ActionMapper class Action - attr_reader :path, :controller + attr_reader :path, :controller, :errors def initialize controller, path @controller = controller @@ -13,6 +13,14 @@ def action controller, event end end + def set_errors *errors + @errors = errors.flatten + end + + def errors + @errors |= [] + end + protected def controller_action diff --git a/lib/controll/flow_handler/master.rb b/lib/controll/flow_handler/master.rb index 2023231..7ccbd01 100644 --- a/lib/controll/flow_handler/master.rb +++ b/lib/controll/flow_handler/master.rb @@ -16,9 +16,9 @@ def initialize controller, options = {} # The first ActionHandler matching the event returns an appropriate Action # In case no ActionHandler matches, the Fallback action is returned def execute - executor.execute || fallback - # rescue StandardError - # fallback + @action = executor.execute || fallback + @action.set_errors errors + @action end def executor @@ -29,6 +29,8 @@ def executor_options {event: event, action_handlers: action_handlers} end + delegate :errors, to: :executor + class << self def action_handlers @action_handlers ||= [] @@ -55,8 +57,6 @@ def mapper_types protected - attr_writer :action - delegate :command!, to: :controller def action_handlers diff --git a/spec/controll/flow_handler/master_spec.rb b/spec/controll/flow_handler/master_spec.rb index a24b354..47481f1 100644 --- a/spec/controll/flow_handler/master_spec.rb +++ b/spec/controll/flow_handler/master_spec.rb @@ -48,7 +48,13 @@ def event end end +ActionMapper = Controll::FlowHandler::ActionMapper +Action = ActionMapper::Action +PathAction = ActionMapper::PathAction +Fallback = ActionMapper::Fallback +Simple = ActionMapper::Simple +Complex = ActionMapper::Complex describe Controll::FlowHandler::Master do context 'use directly without sublclassing' do @@ -84,12 +90,12 @@ def event describe '.execute' do specify do - expect { subject.execute }.to_not raise_error(NotImplementedError) + expect { subject.execute }.to_not raise_error end # since event returns nil specify do - expect { subject.execute }.to_not raise_error + subject.execute.should_not be_nil end end end @@ -109,7 +115,7 @@ def event describe '.execute' do # since event returns nil specify do - expect { subject.execute }.to_not raise_error + subject.execute.should be_a Fallback end end end @@ -133,7 +139,7 @@ def event end specify do - subject.execute.should_not be_nil + subject.execute.should be_a Fallback end end end