Permalink
Browse files

master spec works

  • Loading branch information...
1 parent 6b1a2e8 commit 495736244810b9120458a3122e14914c82caa2d7 @kristianmandrup committed Aug 21, 2012
@@ -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
@@ -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
@@ -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

0 comments on commit 4957362

Please sign in to comment.