controll 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. data/README.md +253 -93
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/controll.gemspec +121 -84
  5. data/lib/controll/assistant/param_assistant.rb +23 -0
  6. data/lib/controll/assistant/session_assistant.rb +23 -0
  7. data/lib/controll/assistant.rb +9 -7
  8. data/lib/controll/commander.rb +16 -3
  9. data/lib/controll/enabler/macros.rb +75 -0
  10. data/lib/controll/enabler/maps.rb +15 -0
  11. data/lib/controll/enabler/notify.rb +43 -0
  12. data/lib/controll/enabler/path_handler.rb +49 -0
  13. data/lib/controll/enabler/path_resolver.rb +47 -0
  14. data/lib/controll/enabler.rb +49 -0
  15. data/lib/controll/engine.rb +9 -0
  16. data/lib/controll/errors.rb +4 -1
  17. data/lib/controll/event/helper.rb +20 -0
  18. data/lib/controll/{helper/event_matcher.rb → event/matcher.rb} +3 -3
  19. data/lib/controll/event.rb +60 -0
  20. data/lib/controll/events.rb +48 -0
  21. data/lib/controll/executor/base.rb +3 -7
  22. data/lib/controll/executor/controlled.rb +36 -0
  23. data/lib/controll/executor/delegator.rb +6 -0
  24. data/lib/controll/executor.rb +8 -1
  25. data/lib/controll/flow/action/base.rb +30 -0
  26. data/lib/controll/flow/action/fallback.rb +25 -0
  27. data/lib/controll/flow/action/path_action.rb +24 -0
  28. data/lib/controll/flow/action.rb +7 -0
  29. data/lib/controll/flow/action_mapper/base.rb +13 -0
  30. data/lib/controll/flow/action_mapper/complex.rb +52 -0
  31. data/lib/controll/flow/action_mapper/simple.rb +54 -0
  32. data/lib/controll/flow/action_mapper.rb +7 -0
  33. data/lib/controll/flow/errors.rb +16 -0
  34. data/lib/controll/flow/event_mapper/path_finder.rb +36 -0
  35. data/lib/controll/flow/event_mapper/util.rb +43 -0
  36. data/lib/controll/flow/event_mapper.rb +6 -0
  37. data/lib/controll/flow/master/executor.rb +57 -0
  38. data/lib/controll/flow/master/macros.rb +66 -0
  39. data/lib/controll/flow/master.rb +70 -0
  40. data/lib/controll/flow.rb +15 -0
  41. data/lib/controll/focused/enabler.rb +31 -0
  42. data/lib/controll/helper.rb +0 -94
  43. data/lib/controll/macros.rb +12 -0
  44. data/lib/controll/notify/base.rb +22 -43
  45. data/lib/controll/notify/flash.rb +3 -3
  46. data/lib/controll/notify/macros.rb +57 -0
  47. data/lib/controll/notify/message/handler.rb +36 -0
  48. data/lib/controll/notify/message/resolver.rb +28 -0
  49. data/lib/controll/notify/message/translator.rb +45 -0
  50. data/lib/controll/notify/message.rb +25 -0
  51. data/lib/controll/notify/typed.rb +13 -22
  52. data/lib/controll/notify.rb +11 -4
  53. data/lib/controll.rb +8 -2
  54. data/lib/generators/controll/assistant_generator.rb +27 -0
  55. data/lib/generators/controll/executor_generator.rb +23 -0
  56. data/lib/generators/controll/flow_handler_generator.rb +21 -0
  57. data/lib/generators/controll/notifier_generator.rb +21 -0
  58. data/lib/generators/controll/setup_generator.rb +37 -0
  59. data/lib/generators/controll/templates/assistant.tt +10 -0
  60. data/lib/generators/controll/templates/commander.tt +15 -0
  61. data/lib/generators/controll/templates/executor.tt +14 -0
  62. data/lib/generators/controll/templates/flow_handler.tt +26 -0
  63. data/lib/generators/controll/templates/notifier.tt +31 -0
  64. data/spec/acceptance/app_test.rb +1 -1
  65. data/spec/controll/assistant/param_assistant_spec.rb +31 -0
  66. data/spec/controll/assistant/session_assistant_spec.rb +31 -0
  67. data/spec/controll/assistant_spec.rb +26 -0
  68. data/spec/controll/command_spec.rb +4 -4
  69. data/spec/controll/enabler/macros_spec.rb +76 -0
  70. data/spec/controll/enabler/maps_spec.rb +31 -0
  71. data/spec/controll/{helper → enabler}/notify_spec.rb +7 -17
  72. data/spec/controll/enabler/path_handler_spec.rb +24 -0
  73. data/spec/controll/enabler/path_resolver_spec.rb +87 -0
  74. data/spec/controll/enabler_spec.rb +30 -0
  75. data/spec/controll/event/helper_spec.rb +33 -0
  76. data/spec/controll/{helper/event_matcher_spec.rb → event/matcher_spec.rb} +4 -3
  77. data/spec/controll/event_spec.rb +66 -0
  78. data/spec/controll/events_spec.rb +23 -0
  79. data/spec/controll/executor/controlled_spec.rb +36 -0
  80. data/spec/controll/executor/{notificator_spec.rb → delegator_spec.rb} +4 -4
  81. data/spec/controll/flow/action_mapper/complex_spec.rb +102 -0
  82. data/spec/controll/flow/action_mapper/fallback_spec.rb +34 -0
  83. data/spec/controll/{flow_handler/render_spec.rb → flow/action_mapper/simple_spec.rb} +25 -22
  84. data/spec/controll/{flow_handler/redirect/action_spec.rb → flow/event_mapper/path_finder_spec.rb} +10 -10
  85. data/spec/controll/{flow_handler/redirect/mapper_spec.rb → flow/event_mapper/util_spec.rb} +9 -9
  86. data/spec/controll/flow/master/executor_spec.rb +56 -0
  87. data/spec/{app/app/models/.gitkeep → controll/flow/master/macros_spec.rb} +0 -0
  88. data/spec/controll/flow/master_spec.rb +157 -0
  89. data/spec/controll/notify/base_spec.rb +6 -12
  90. data/spec/controll/notify/message/handler_spec.rb +27 -0
  91. data/spec/controll/notify/message/resolver_spec.rb +53 -0
  92. data/spec/controll/notify/message/translator_spec.rb +46 -0
  93. data/spec/controll/notify/message_spec.rb +4 -0
  94. data/spec/controll/notify/{message_handler.rb → services_notifier.rb} +3 -5
  95. data/spec/controll/notify/typed_spec.rb +2 -2
  96. data/spec/{app → controll_app}/.gitignore +0 -0
  97. data/spec/{app → controll_app}/Gemfile +0 -0
  98. data/spec/{app → controll_app}/Gemfile.lock +0 -0
  99. data/spec/{app → controll_app}/README.rdoc +0 -0
  100. data/spec/{app → controll_app}/Rakefile +0 -0
  101. data/spec/controll_app/app/controll/commanders/services_commander.rb +5 -0
  102. data/spec/controll_app/app/controll/executors/services_executor.rb +4 -0
  103. data/spec/controll_app/app/controll/flows/create_services.rb +9 -0
  104. data/spec/controll_app/app/controll/notifiers/services_notifier.rb +9 -0
  105. data/spec/{app → controll_app}/app/controllers/application_controller.rb +0 -1
  106. data/spec/controll_app/app/controllers/services_controller.rb +8 -0
  107. data/spec/{app/lib/assets → controll_app/app/models}/.gitkeep +0 -0
  108. data/spec/{app → controll_app}/app/models/post.rb +0 -0
  109. data/spec/{app → controll_app}/app/views/layouts/application.html.erb +0 -0
  110. data/spec/{app → controll_app}/app/views/posts/_form.html.erb +0 -0
  111. data/spec/{app → controll_app}/app/views/posts/edit.html.erb +0 -0
  112. data/spec/{app → controll_app}/app/views/posts/index.html.erb +0 -0
  113. data/spec/{app → controll_app}/app/views/posts/new.html.erb +0 -0
  114. data/spec/{app → controll_app}/app/views/posts/show.html.erb +0 -0
  115. data/spec/{app → controll_app}/config/application.rb +1 -1
  116. data/spec/{app → controll_app}/config/boot.rb +0 -0
  117. data/spec/{app → controll_app}/config/environment.rb +0 -0
  118. data/spec/{app → controll_app}/config/environments/development.rb +0 -0
  119. data/spec/{app → controll_app}/config/environments/test.rb +0 -0
  120. data/spec/{app → controll_app}/config/initializers/backtrace_silencers.rb +0 -0
  121. data/spec/{app → controll_app}/config/initializers/inflections.rb +0 -0
  122. data/spec/{app → controll_app}/config/initializers/mime_types.rb +0 -0
  123. data/spec/{app → controll_app}/config/initializers/secret_token.rb +0 -0
  124. data/spec/{app → controll_app}/config/initializers/session_store.rb +0 -0
  125. data/spec/{app → controll_app}/config/locales/en.yml +0 -0
  126. data/spec/controll_app/config/routes.rb +5 -0
  127. data/spec/{app → controll_app}/config.ru +0 -0
  128. data/spec/{app → controll_app}/db/seeds.rb +0 -0
  129. data/spec/{app/lib/tasks → controll_app/log}/.gitkeep +0 -0
  130. data/spec/{app → controll_app}/public/404.html +0 -0
  131. data/spec/{app → controll_app}/public/422.html +0 -0
  132. data/spec/{app → controll_app}/public/500.html +0 -0
  133. data/spec/{app → controll_app}/public/favicon.ico +0 -0
  134. data/spec/{app → controll_app}/public/index.html +0 -0
  135. data/spec/{app → controll_app}/public/javascripts/application.js +0 -0
  136. data/spec/{app → controll_app}/public/robots.txt +0 -0
  137. data/spec/{app → controll_app}/public/stylesheets/application.css +0 -0
  138. metadata +122 -85
  139. data/lib/controll/executor/notificator.rb +0 -12
  140. data/lib/controll/flow_handler/base.rb +0 -19
  141. data/lib/controll/flow_handler/control.rb +0 -85
  142. data/lib/controll/flow_handler/errors.rb +0 -5
  143. data/lib/controll/flow_handler/event_helper.rb +0 -18
  144. data/lib/controll/flow_handler/redirect/action.rb +0 -45
  145. data/lib/controll/flow_handler/redirect/mapper.rb +0 -41
  146. data/lib/controll/flow_handler/redirect.rb +0 -51
  147. data/lib/controll/flow_handler/render.rb +0 -51
  148. data/lib/controll/flow_handler.rb +0 -11
  149. data/lib/controll/helper/notify.rb +0 -74
  150. data/lib/controll/helper/path_resolver.rb +0 -45
  151. data/spec/app/app/controllers/posts_controller.rb +0 -52
  152. data/spec/app/config/routes.rb +0 -62
  153. data/spec/app/log/.gitkeep +0 -0
  154. data/spec/app/script/rails +0 -6
  155. data/spec/app/spec/controllers/posts_controller_spec.rb +0 -59
  156. data/spec/app/spec/isolated_spec_helper.rb +0 -6
  157. data/spec/app/spec/spec_helper.rb +0 -5
  158. data/spec/app/spec/unit/controllers/posts_controller_isolated_spec.rb +0 -63
  159. data/spec/app/spec/unit/controllers/posts_controller_spec.rb +0 -59
  160. data/spec/app/test/functional/.gitkeep +0 -0
  161. data/spec/app/test/functional/posts_controller_test.rb +0 -67
  162. data/spec/app/test/isolated_test_helper.rb +0 -7
  163. data/spec/app/test/test_helper.rb +0 -6
  164. data/spec/app/test/unit/.gitkeep +0 -0
  165. data/spec/app/test/unit/controllers/posts_controller_isolated_test.rb +0 -71
  166. data/spec/app/test/unit/controllers/posts_controller_test.rb +0 -67
  167. data/spec/app/vendor/assets/javascripts/.gitkeep +0 -0
  168. data/spec/app/vendor/assets/stylesheets/.gitkeep +0 -0
  169. data/spec/app/vendor/plugins/.gitkeep +0 -0
  170. data/spec/controll/asssistant_spec.rb +0 -5
  171. data/spec/controll/flow_handler/control_spec.rb +0 -159
  172. data/spec/controll/flow_handler/redirect_spec.rb +0 -93
  173. data/spec/controll/helper/path_resolver_spec.rb +0 -49
  174. data/spec/controll/helper_spec.rb +0 -108
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe Controll::Event do
4
+ let(:clazz) { Controll::Event }
5
+
6
+ describe '.initialize name, *args' do
7
+ context 'implicit notice' do
8
+ subject { Controll::Event.new 'sign_in' }
9
+
10
+ its(:name) { should == :sign_in }
11
+ its(:type) { should == :notice }
12
+ its(:options) { should be_blank }
13
+ end
14
+
15
+ context 'explicit notice' do
16
+ subject { Controll::Event.new 'sign_in', :notice }
17
+
18
+ its(:name) { should == :sign_in }
19
+ its(:type) { should == :notice }
20
+ its(:options) { should be_blank }
21
+ end
22
+
23
+ context 'explicit error and options' do
24
+ subject { Controll::Event.new 'sign_in', :error, {:a => 7} }
25
+
26
+ its(:name) { should == :sign_in }
27
+ its(:type) { should == :error }
28
+ its(:options) { should == {:a => 7} }
29
+ end
30
+
31
+ context 'explicit warning type in options' do
32
+ subject { Controll::Event.new 'sign_in', {:type => :warning, :a => 7} }
33
+
34
+ its(:name) { should == :sign_in }
35
+ its(:type) { should == :warning }
36
+ its(:options) { should == {:a => 7} }
37
+
38
+ describe '.warning?' do
39
+ its(:warning?) { should be_true }
40
+ its(:notice?) { should be_false }
41
+ end
42
+ end
43
+ end
44
+
45
+ context 'class methods' do
46
+ subject { clazz }
47
+
48
+ describe '.valid_types' do
49
+ its(:valid_types) { should = %w{notice error warning success} }
50
+ end
51
+
52
+ describe '.valid_types=' do
53
+ before do
54
+ clazz.valid_types = [:notice]
55
+ end
56
+ its(:valid_types) { should = [:notice] }
57
+ end
58
+
59
+ describe '.add_valid_type' do
60
+ before do
61
+ clazz.add_valid_types :remote, :invalid
62
+ end
63
+ its(:valid_types) { should include(:remote, :invalid) }
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Controll::Events do
4
+ subject { clazz.new }
5
+ let(:clazz) { Controll::Events }
6
+
7
+ include Controll::Event::Helper
8
+
9
+ let(:a_success) { create_event :success }
10
+ let(:a_warning) { create_event :warning }
11
+
12
+ describe 'class methods' do
13
+ subject { clazz }
14
+
15
+ its(:valid_types) { should == Controll::Event.valid_types }
16
+ end
17
+
18
+ describe 'last' do
19
+ subject { Controll::Events.new a_success, a_warning }
20
+
21
+ its(:last) { should == a_warning }
22
+ end
23
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ class MyControlledExec < Controll::Executor::Controlled
4
+ controller_methods :hello
5
+ end
6
+
7
+ class MyAwesomeController
8
+ def hello
9
+ "hello"
10
+ end
11
+ end
12
+
13
+ describe Controll::Executor::Controlled do
14
+ subject { MyControlledExec.new controller }
15
+
16
+ let(:controller) { MyAwesomeController.new }
17
+
18
+ describe '.method_missing' do
19
+ specify do
20
+ subject.hello.should == 'hello'
21
+ end
22
+
23
+ specify do
24
+ expect { subject.bye }.to raise_error
25
+ end
26
+ end
27
+
28
+ describe '.execute' do
29
+ end
30
+
31
+ describe '.result' do
32
+ end
33
+
34
+ describe 'self.execute &block' do
35
+ end
36
+ end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
-
4
- class MyExec < Controll::Executor::Notificator
3
+ class MyDelegator < Controll::Executor::Delegator
4
+ controller_methods :hello
5
5
  end
6
6
 
7
7
  class MyAwesomeController
@@ -10,8 +10,8 @@ class MyAwesomeController
10
10
  end
11
11
  end
12
12
 
13
- describe Controll::Executor::Notificator do
14
- subject { MyExec.new controller }
13
+ describe Controll::Executor::Delegator do
14
+ subject { MyDelegator.new controller }
15
15
 
16
16
  let(:controller) { MyAwesomeController.new }
17
17
 
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ class HelloToWelcomeRedirect < Controll::Flow::ActionMapper::Complex
4
+ event_map :welcome => [:hello, :hi]
5
+ end
6
+
7
+ class ErrorBadRedirect < Controll::Flow::ActionMapper::Complex
8
+ event_map :error, bad: ['bad_payment', 'wrong_payment']
9
+ end
10
+
11
+ class TheController
12
+ end
13
+
14
+ describe Controll::Flow::ActionMapper::Complex do
15
+
16
+ def notification name
17
+ Hashie::Mash.new(name: name.to_sym, type: :notice)
18
+ end
19
+
20
+ def error name
21
+ Hashie::Mash.new(name: name.to_sym, type: :error)
22
+ end
23
+
24
+ let(:controller) { TheController.new }
25
+
26
+ describe 'class macros' do
27
+ before :all do
28
+ ErrorBadRedirect.event_map :error, crap: ['bad_payment', 'wrong_payment']
29
+ end
30
+
31
+ specify {
32
+ ErrorBadRedirect.event_map_for(:error).should == {crap: ['bad_payment', 'wrong_payment']}
33
+ }
34
+
35
+ specify {
36
+ ErrorBadRedirect.event_maps.should == {error: {crap: ['bad_payment', 'wrong_payment']} }
37
+ }
38
+ end
39
+
40
+ context 'use directly without subclassing' do
41
+ subject { clazz.new '/' }
42
+
43
+ let(:clazz) { Controll::Flow::ActionMapper::Complex }
44
+
45
+ let(:hello) { notification :hello }
46
+
47
+ describe '.action event' do
48
+ specify do
49
+ expect { clazz.action(controller, :hello) }.to raise_error(Controll::Flow::NoMappingFoundError)
50
+ end
51
+ end
52
+ end
53
+
54
+ context 'HelloToWelcomeRedirect subclass' do
55
+ subject { clazz.new '/' }
56
+
57
+ let(:clazz) { HelloToWelcomeRedirect }
58
+
59
+ context 'has redirections' do
60
+ describe '.action event' do
61
+ specify do
62
+ expect { clazz.action(controller, :hello) }.to_not raise_error(Controll::Flow::NoMappingFoundError)
63
+ end
64
+
65
+ specify do
66
+ clazz.action(controller, :hello).should be_a Controll::Flow::Action::PathAction
67
+ end
68
+
69
+ specify do
70
+ clazz.action(controller, :hi).path.should == 'welcome'
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ context 'ErrorBadRedirect subclass' do
77
+ subject { clazz.new '/' }
78
+
79
+ let(:clazz) { ErrorBadRedirect }
80
+
81
+ before do
82
+ Controll::Event.reset_types
83
+ end
84
+
85
+ context 'has error redirections' do
86
+ describe '.action event' do
87
+ specify do
88
+ expect { clazz.action(controller, :hello) }.to raise_error(Controll::Flow::NoMappingFoundError)
89
+ end
90
+
91
+ specify do
92
+ clazz.action(controller, error(:bad_payment)).should be_a Controll::Flow::Action::PathAction
93
+ end
94
+
95
+ specify do
96
+ clazz.action(controller, error(:wrong_payment)).path.should == 'crap'
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ class FallbackController
4
+ def do_fallback fallback
5
+ "did a nice fallback :) - #{fallback.event.name}"
6
+ end
7
+ end
8
+
9
+ class BasicFallbackAction < Controll::Flow::Action::Fallback
10
+ end
11
+
12
+ describe Controll::Flow::Action::Fallback do
13
+ context 'Basic default fallback' do
14
+ subject { clazz.new controller, event }
15
+
16
+ let(:controller) { FallbackController.new }
17
+ let(:clazz) { BasicFallbackAction }
18
+ let(:event) { create_event :unknown, :notice }
19
+
20
+ include Controll::Event::Helper
21
+
22
+ describe '.action controller, event' do
23
+ specify do
24
+ clazz.action(controller, event).should be_a Controll::Flow::Action::Fallback
25
+ end
26
+ end
27
+
28
+ describe '.perform' do
29
+ specify do
30
+ clazz.action(controller, event).perform.should == "did a nice fallback :) - #{event.name}"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,38 +1,45 @@
1
1
  require 'spec_helper'
2
2
 
3
- class NoEventsRender < Controll::FlowHandler::Render
3
+ class NoEventsRender < Controll::Flow::ActionMapper::Simple
4
4
  def self.events
5
5
  []
6
6
  end
7
7
  end
8
8
 
9
- class HiRender < Controll::FlowHandler::Render
9
+ class HiRender < Controll::Flow::ActionMapper::Simple
10
10
  def self.events
11
11
  [:hi]
12
12
  end
13
13
  end
14
14
 
15
- class HelloRender < Controll::FlowHandler::Render
16
- set_events :hello, :damn
17
- set_default_path '/default'
15
+ class HelloRender < Controll::Flow::ActionMapper::Simple
16
+ events :hello, :damn
17
+ default_path '/default'
18
+ end
19
+
20
+ class NiceController
18
21
  end
19
22
 
20
23
  def notification name
21
- Hashie::Mash.new(name: name.to_sym, type: :notification)
24
+ Hashie::Mash.new(name: name.to_sym, type: :notice)
22
25
  end
23
26
 
24
- describe Controll::FlowHandler::Render do
27
+ describe Controll::Flow::ActionMapper::Simple do
28
+
29
+ Simple = Controll::Flow::ActionMapper::Simple
30
+ Complex = Controll::Flow::ActionMapper::Complex
31
+
32
+ let(:controller) { NiceController }
33
+ let(:hello) { notification :hello }
25
34
 
26
35
  context 'use directly without sublclassing' do
27
36
  subject { clazz.new '/' }
28
37
 
29
- let(:clazz) { Controll::FlowHandler::Render }
30
-
31
- let(:hello) { notification :hello }
38
+ let(:clazz) { Simple }
32
39
 
33
40
  describe '.action event' do
34
41
  specify do
35
- expect { clazz.action(:hello) }.to raise_error(Controll::FlowHandler::NoEventsDefinedError)
42
+ expect { clazz.action(controller, hello) }.to raise_error(Controll::Flow::NoEventsDefinedError)
36
43
  end
37
44
  end
38
45
  end
@@ -45,7 +52,7 @@ describe Controll::FlowHandler::Render do
45
52
  context 'empty events' do
46
53
  describe '.action event' do
47
54
  specify do
48
- expect { clazz.action(:hello) }.to raise_error(Controll::FlowHandler::NoEventsDefinedError)
55
+ expect { clazz.action(controller, hello) }.to raise_error(Controll::Flow::NoEventsDefinedError)
49
56
  end
50
57
  end
51
58
  end
@@ -62,22 +69,18 @@ describe Controll::FlowHandler::Render do
62
69
 
63
70
  describe 'does not respond to hello' do
64
71
  specify do
65
- expect { clazz.action(:hello) }.to_not raise_error(Controll::FlowHandler::Render::NoEventsDefinedError)
66
- end
67
-
68
- specify do
69
- clazz.action(event).should == nil
72
+ expect { clazz.action(controller, event) }.to_not raise_error(Controll::Flow::NoEventsDefinedError)
70
73
  end
71
74
 
72
75
  specify do
73
- clazz.action(:hello).should == nil
76
+ expect { clazz.action(controller, event) }.to raise_error Controll::Flow::NoDefaultPathDefinedError
74
77
  end
75
78
  end
76
79
 
77
80
  describe 'responds to hi' do
78
81
  # default_path not implemented!
79
82
  specify do
80
- expect { clazz.action(:hi) }.to raise_error NotImplementedError
83
+ expect { clazz.action(controller, :hi) }.to raise_error Controll::Flow::NoDefaultPathDefinedError
81
84
  end
82
85
  end
83
86
  end
@@ -94,15 +97,15 @@ describe Controll::FlowHandler::Render do
94
97
  context 'has events and default_path' do
95
98
  describe '.action event' do
96
99
  specify do
97
- clazz.action(event).should be_a HelloRender
100
+ clazz.action(controller, event).should be_a Controll::Flow::Action::PathAction
98
101
  end
99
102
 
100
103
  specify do
101
- clazz.action(event).path.should == default_path
104
+ clazz.action(controller, event).path.should == default_path
102
105
  end
103
106
 
104
107
  specify do
105
- clazz.action(event, 'other_path').path.should == 'other_path'
108
+ clazz.action(controller, event, 'other_path').path.should == 'other_path'
106
109
  end
107
110
  end
108
111
  end
@@ -1,14 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
- def notice name
4
- Hashie::Mash.new(name: name.to_sym, type: :notice)
5
- end
3
+ describe Controll::Flow::EventMapper::PathFinder do
4
+ def notice name
5
+ Hashie::Mash.new(name: name.to_sym, type: :notice)
6
+ end
6
7
 
7
- def error name
8
- Hashie::Mash.new(name: name.to_sym, type: :error)
9
- end
8
+ def error name
9
+ Hashie::Mash.new(name: name.to_sym, type: :error)
10
+ end
10
11
 
11
- describe Controll::FlowHandler::Redirect::Action do
12
12
  let(:redirections) do
13
13
  {
14
14
  :error => error_map, :notice => notice_map
@@ -29,7 +29,7 @@ describe Controll::FlowHandler::Redirect::Action do
29
29
  let(:types) { [:notice, :error] }
30
30
 
31
31
  context 'use' do
32
- let(:clazz) { Controll::FlowHandler::Redirect::Action }
32
+ let(:clazz) { Controll::Flow::EventMapper::PathFinder }
33
33
  let(:hello) { notice :hello }
34
34
  let(:bad_payment) { error :bad_payment }
35
35
 
@@ -37,11 +37,11 @@ describe Controll::FlowHandler::Redirect::Action do
37
37
  subject { clazz.new hello, redirections, types }
38
38
 
39
39
  specify do
40
- expect { subject.map }.to_not raise_error(Controll::FlowHandler::NoRedirectionFoundError)
40
+ expect { subject.map }.to_not raise_error(Controll::Flow::NoMappingFoundError)
41
41
  end
42
42
 
43
43
  specify do
44
- subject.map.should == 'welcome'
44
+ subject.path.should == 'welcome'
45
45
  end
46
46
  end
47
47
  end
@@ -8,7 +8,7 @@ def error name
8
8
  Hashie::Mash.new(name: name.to_sym, type: :error)
9
9
  end
10
10
 
11
- describe Controll::FlowHandler::Redirect::Mapper do
11
+ describe Controll::Flow::EventMapper::Util do
12
12
  let(:redirections) do
13
13
  {
14
14
  :error => error_map, :notice => notice_map
@@ -31,28 +31,28 @@ describe Controll::FlowHandler::Redirect::Mapper do
31
31
  context 'use' do
32
32
  subject { clazz.new hello, notice_map }
33
33
 
34
- let(:clazz) { Controll::FlowHandler::Redirect::Mapper }
34
+ let(:clazz) { Controll::Flow::EventMapper::Util }
35
35
  let(:hello) { notice :hello }
36
36
  let(:bad_payment) { error :bad_payment }
37
37
 
38
38
  describe '.initialize' do
39
- its(:event) { should == hello }
40
- its(:redirect_map) { should == notice_map }
39
+ its(:event) { should be_a Controll::Event }
40
+ its(:event_map) { should == notice_map }
41
41
  end
42
42
 
43
- describe '.map' do
43
+ describe '.map_event' do
44
44
  specify do
45
- subject.map.should == 'welcome'
45
+ subject.map_event.should == 'welcome'
46
46
  end
47
47
  end
48
48
 
49
- describe '.matcher event' do
49
+ describe '.matcher' do
50
50
  specify do
51
- subject.send(:matcher, hello).should be_a Controll::Helper::EventMatcher
51
+ subject.send(:matcher).should be_a Controll::Event::Matcher
52
52
  end
53
53
 
54
54
  specify do
55
- subject.send(:matcher, hello).event.should == hello
55
+ subject.send(:matcher).event.should be_a Controll::Event
56
56
  end
57
57
  end
58
58
 
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ module MyOwnController
4
+ class Update
5
+ def render path
6
+ send(path) if path
7
+ end
8
+
9
+ def default
10
+ 'default'
11
+ end
12
+ end
13
+ end
14
+
15
+ describe Controll::Flow::Master::Executor do
16
+ include Controll::Event::Helper
17
+
18
+ let(:executor) { Controll::Flow::Master::Executor }
19
+ let(:controller) { MyOwnController::Update.new }
20
+
21
+ let(:fallback_event) { create_event :unknown, :notice }
22
+ let(:render_event) { create_event :hello, :notice }
23
+ let(:redirect_event) { create_event :exit, :error }
24
+
25
+ let(:action_handlers) { [:renderer, :redirecter] }
26
+
27
+ let(:options) do
28
+ {event: event, action_handlers: action_handlers}
29
+ end
30
+
31
+ describe '.initialize with fallback_event' do
32
+ let(:event) { fallback_event }
33
+ subject { executor.new controller, options }
34
+
35
+ specify do
36
+ subject.controller.should == controller
37
+ end
38
+
39
+ specify do
40
+ subject.event.should == event
41
+ end
42
+ end
43
+
44
+ describe '.initialize with render_event' do
45
+ let(:event) { render_event }
46
+ subject { executor.new controller, options }
47
+
48
+ specify do
49
+ subject.controller.should == controller
50
+ end
51
+
52
+ specify do
53
+ subject.event.should == event
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,157 @@
1
+ require 'spec_helper'
2
+
3
+ module MasterController
4
+ class Update
5
+ def render path
6
+ send(path) if path
7
+ end
8
+
9
+ def default
10
+ 'default'
11
+ end
12
+ end
13
+ end
14
+
15
+ module Flows
16
+ class EmptyEvent < Master
17
+ def event
18
+ end
19
+ end
20
+
21
+ class UpdateEventWithoutHandler < Master
22
+ def event
23
+ :update
24
+ end
25
+ end
26
+
27
+
28
+ class UpdateEvent < Master
29
+ def event
30
+ :update
31
+ end
32
+
33
+ renderer :simple do
34
+ events :update
35
+ default_path 'default'
36
+ end
37
+ end
38
+
39
+ class UpdateEventNoMatch < Master
40
+ def event
41
+ :update
42
+ end
43
+
44
+ renderer :simple do
45
+ events :create
46
+ default_path '/default'
47
+ end
48
+ end
49
+ end
50
+
51
+ describe Controll::Flow::Master do
52
+ Fallback = Controll::Flow::Action::Fallback
53
+
54
+ context 'use directly without sublclassing' do
55
+ subject { flow.new controller }
56
+
57
+ let(:flow) { Controll::Flow::Master }
58
+ let(:controller) { MasterController::Update.new }
59
+
60
+ describe '.initialize' do
61
+ specify do
62
+ subject.controller.should == controller
63
+ end
64
+ end
65
+
66
+ describe '.execute' do
67
+ specify do
68
+ expect { subject.execute }.to raise_error(Controll::Flow::EventNotImplementedError)
69
+ end
70
+ end
71
+ end
72
+
73
+ context 'A Control Flow with empty #event method' do
74
+ subject { flow.new controller }
75
+
76
+ let(:flow) { Flows::EmptyEvent }
77
+ let(:controller) { MasterController::Update.new }
78
+
79
+ describe '.initialize' do
80
+ specify do
81
+ subject.controller.should == controller
82
+ end
83
+ end
84
+
85
+ describe '.execute' do
86
+ # since event is nil
87
+ specify do
88
+ expect { subject.execute }.to raise_error(ArgumentError)
89
+ end
90
+ end
91
+ end
92
+
93
+ context 'A Control Flow where #event returns :update notice event' do
94
+ subject { flow.new controller }
95
+
96
+ let(:flow) { Flows::UpdateEventWithoutHandler }
97
+ let(:controller) { MasterController::Update.new }
98
+
99
+ describe '.initialize' do
100
+ specify do
101
+ subject.controller.should == controller
102
+ end
103
+ end
104
+
105
+ describe '.execute' do
106
+ # since event returns nil
107
+ specify do
108
+ subject.execute.should be_a Fallback
109
+ end
110
+ end
111
+ end
112
+
113
+ context 'A Control Flow where #event returns :update notice event and has a Render class with matching mapping' do
114
+ subject { flow.new controller }
115
+
116
+ let(:flow) { Flows::UpdateEvent }
117
+ let(:controller) { MasterController::Update.new }
118
+
119
+ describe '.initialize' do
120
+ specify do
121
+ subject.controller.should == controller
122
+ end
123
+ end
124
+
125
+ describe '.execute' do
126
+ # since event returns nil
127
+ specify do
128
+ expect { subject.execute }.to_not raise_error(Controll::Flow::ActionEventError)
129
+ end
130
+
131
+ specify do
132
+ subject.execute.should be_a Fallback
133
+ end
134
+ end
135
+ end
136
+
137
+ context 'A Control Flow where #event returns :update notice event and has a Render class with NO matching mapping' do
138
+ subject { flow.new controller }
139
+
140
+ let(:flow) { Flows::UpdateEventNoMatch }
141
+ let(:controller) { MasterController::Update.new }
142
+
143
+ describe '.initialize' do
144
+ specify do
145
+ subject.controller.should == controller
146
+ end
147
+ end
148
+
149
+ describe '.execute' do
150
+ # since event returns nil
151
+ specify do
152
+ expect { subject.execute }.to_not raise_error
153
+ end
154
+ end
155
+ end
156
+
157
+ end