Browse files

flow executor spec

  • Loading branch information...
1 parent c265e4c commit 08347f0dc0639afc00e56f869b34aa7548681f5f @kristianmandrup committed Aug 22, 2012
View
2 README.md
@@ -280,7 +280,7 @@ For Controller actions that require complex flow control, use a Flow:
```ruby
module Flows
- class CreateService < Master
+ class CreateService < Flow
# event method that returns the event to be processed by the flow handler
event do
View
17 lib/controll/flow/master/executor.rb
@@ -6,8 +6,15 @@ class Executor < Controll::Executor::Base
NoEventsDefinedError = Flow::NoEventsDefinedError
NoMappingFoundError = Flow::NoMappingFoundError
- def initialize initiator, options = {}
+ attr_reader :event, :action_handlers
+
+ def initialize initiator, options
+ raise ArgumentError, "Must take an options arg" unless options.kind_of?(Hash)
+ raise ArgumentError, "Must take an :event option" unless options[:event]
+ raise ArgumentError, "Must take an :action_handlers option" unless options[:action_handlers]
super
+ @event = options[:event]
+ @action_handlers = options[:action_handlers]
end
def execute
@@ -31,10 +38,6 @@ def errors
protected
- def event
- options[:event]
- end
-
def fallback
fallback_class.new controller, event
end
@@ -43,10 +46,6 @@ def fallback_class
Flow::ActionMapper::Fallback
end
- def action_handlers
- @action_handlers ||= options[:action_handlers]
- end
-
def handler_class action_handler
clazz = "#{initiator.class}::#{action_handler.to_s.camelize}"
clazz.constantize
View
56 spec/controll/flow/master/executor_spec.rb
@@ -0,0 +1,56 @@
+require 'spec_helper'
+
+module MyController
+ class Update
+ def render path
+ send(path) if path
+ end
+
+ def default
+ 'default'
+ end
+ end
+end
+
+describe Controll::Flow::Master::Executor do
+ include Controll::Event::Helper
+
+ let(:executor) { Controll::Flow::Master::Executor }
+ let(:controller) { MyController::Update.new }
+
+ let(:fallback_event) { create_event :unknown, :notice }
+ let(:render_event) { create_event :hello, :notice }
+ let(:redirect_event) { create_event :exit, :error }
+
+ let(:action_handlers) { [:renderer, :redirecter] }
+
+ let(:options) do
+ {event: event, action_handlers: action_handlers}
+ end
+
+ describe '.initialize controller, fallback_event' do
+ let(:event) { fallback_event }
+ subject { executor.new controller, options }
+
+ specify do
+ subject.controller.should == controller
+ end
+
+ specify do
+ subject.event.should == event
+ end
+ end
+
+ describe '.initialize controller, render_event' do
+ let(:event) { render_event }
+ subject { executor.new controller, options }
+
+ specify do
+ subject.controller.should == controller
+ end
+
+ specify do
+ subject.event.should == event
+ end
+ end
+end
View
0 spec/controll/flow/master/macros_spec.rb
No changes.

0 comments on commit 08347f0

Please sign in to comment.