Skip to content

Commit

Permalink
master spec works
Browse files Browse the repository at this point in the history
  • Loading branch information
kristianmandrup committed Aug 21, 2012
1 parent 6b1a2e8 commit 4957362
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
10 changes: 9 additions & 1 deletion 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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/controll/flow_handler/master.rb
Expand Up @@ -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
Expand All @@ -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 ||= []
Expand All @@ -55,8 +57,6 @@ def mapper_types

protected

attr_writer :action

delegate :command!, to: :controller

def action_handlers
Expand Down
14 changes: 10 additions & 4 deletions spec/controll/flow_handler/master_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -133,7 +139,7 @@ def event
end

specify do
subject.execute.should_not be_nil
subject.execute.should be_a Fallback
end
end
end
Expand Down

0 comments on commit 4957362

Please sign in to comment.