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,21 @@
1
+ module Controll
2
+ module Generators
3
+ class FlowGenerator < ::Rails::Generators::NamedBase
4
+ desc 'Generates a Flow'
5
+
6
+ def main_flow
7
+ template 'flow.tt', "app/controll/flows/#{file_name}.rb"
8
+ end
9
+
10
+ protected
11
+
12
+ def parent_class
13
+ name.include?('::') ? "::Controll::Flow::#{parent_class_name}" : parent_class_name
14
+ end
15
+
16
+ def parent_class_name
17
+ 'Control'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Controll
2
+ module Generators
3
+ class NotifierGenerator < ::Rails::Generators::NamedBase
4
+ desc 'Generates a Notifier'
5
+
6
+ def main_flow
7
+ template 'notifier.tt', "app/controll/notifiers/#{file_name}.rb"
8
+ end
9
+
10
+ protected
11
+
12
+ def parent_class
13
+ name.include?('::') ? "::Controll::Notify::#{parent_class_name}" : parent_class_name
14
+ end
15
+
16
+ def parent_class_name
17
+ 'Typed'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,37 @@
1
+ module Controll
2
+ module Generators
3
+ class SetupGenerator < ::Rails::Generators::Base
4
+ desc 'Sets up a Rails 3 prooject with a folder structure in app for controll artifacts'
5
+
6
+ argument :folders, type: :array, required: false, desc: 'creates specific folders for controll artifacts'
7
+
8
+ def main_flow
9
+ empty_directory "app/controll"
10
+ inside "app/controll" do
11
+ create_folders.each do |folder|
12
+ empty_directory folder
13
+ end
14
+ end
15
+ end
16
+
17
+ protected
18
+
19
+ def create_folders
20
+ return mapper_folders unless folders.empty?
21
+ valid_folders
22
+ end
23
+
24
+ def mapper_folders
25
+ @mapper_folders ||= folders.map {|f| f.to_s.underscore }.select{|f| valid_artifact? f }
26
+ end
27
+
28
+ def valid_folder? folder
29
+ valid_folders.include? folder.to_s.underscore
30
+ end
31
+
32
+ def valid_folders
33
+ %w{executors flows notifiers commanders assistants}
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,10 @@
1
+ module Assistants
2
+ class <%= class_name %> < <%= parent_class %>
3
+ # public methods here
4
+ # def do_stuff
5
+ # ... if current_user
6
+ # end
7
+
8
+ # controller_methods :current_user
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ module Commanders
2
+ class <%= class_name %> < <%= parent_class %>
3
+ # create basic command methods
4
+ # command_methods :cancel_commit, :create_account, :signout
5
+
6
+ # create custom command method with custom argument hash
7
+
8
+ # command_method :sign_out do
9
+ # end
10
+
11
+ # controller delegations
12
+ # controller_methods :auth_hash, :user_id
13
+ end
14
+ end
15
+ ```
@@ -0,0 +1,14 @@
1
+ module Executors
2
+ class <%= class_name %> < <%= parent_class %>
3
+ def execute
4
+ # creates an error notification named :error
5
+ error and return unless valid_params?
6
+
7
+ # creates an error notification named :auth_invalid
8
+ # error(:auth_invalid) and return unless auth_valid?
9
+
10
+ # command! :sign_in
11
+ # result
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ module Flows
2
+ class <%= class_name %> < <%= parent_class %>
3
+ fallback do
4
+ # event == :no_auth ? do_render(:text => omniauth.to_yaml) : fallback_action
5
+ end
6
+
7
+ event do
8
+ # Executors::Authenticator.new(controller).execute
9
+ end
10
+
11
+ renderer do
12
+ # default_path :signup_services_path
13
+ # events :signed_in_new_user, :signed_in
14
+ end
15
+
16
+ redirecter do
17
+ redirections :notice do
18
+ {
19
+ # signup_services_path: :signed_in_new_user
20
+ }
21
+ end
22
+
23
+ # redirections :error, signin_path: [:error, :invalid, :auth_error]
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ module Notifiers
2
+ class <%= class_name %> < <%= parent_class %>
3
+ handler :notice do
4
+ # ...
5
+ end
6
+
7
+ handler :error do
8
+ messages do
9
+ {
10
+ must_sign_in: 'You need to sign in before accessing this page!',
11
+
12
+ auth_service_error: %q{There was an error at the remote authentication service.
13
+ You have not been signed in.},
14
+
15
+ cant_delete_current_account: 'You are currently signed in with this account!',
16
+ user_save_error: 'This is embarrassing! There was an error while creating your account from which we were not able to recover.',
17
+ }
18
+ end
19
+
20
+ msg :auth_error! do
21
+ "Error while authenticating via #{service_name}. The service did not return valid data."
22
+ end
23
+
24
+ msg :auth_invalid! do
25
+ 'Error while authenticating via {{full_route}}. The service returned invalid data for the user id.'
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+
@@ -22,7 +22,7 @@ Capybara.app_host = "http://127.0.0.1:#{FocusedController::Test.port}"
22
22
 
23
23
  describe 'acceptance test' do
24
24
  def app_root
25
- TEST_ROOT + '/app'
25
+ TEST_ROOT + '/controll_app'
26
26
  end
27
27
 
28
28
  def within_test_app
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ class ParamAssistant < Controll::ParamAssistant
4
+ param_methods :id
5
+ end
6
+
7
+ class MyController
8
+ include Controll::ParamAssistant::Helper
9
+
10
+ def params
11
+ {:id => 7}
12
+ end
13
+
14
+ param_assistant ::ParamAssistant
15
+ end
16
+
17
+ describe Controll::Assistant do
18
+ context 'Param assistant' do
19
+ subject { ParamAssistant.new controller }
20
+
21
+ let(:controller) { MyController.new }
22
+
23
+ its(:controller) { should == controller }
24
+ its(:params) { should == {:id => 7} }
25
+ its(:id) { should == 7 }
26
+
27
+ specify do
28
+ controller.param(:id).should == 7
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ class SessionAssistant < Controll::SessionAssistant
4
+ session_methods :name
5
+ end
6
+
7
+ class MyController
8
+ include Controll::SessionAssistant::Helper
9
+
10
+ def session
11
+ {:name => 'kris'}
12
+ end
13
+
14
+ session_assistant ::SessionAssistant
15
+ end
16
+
17
+ describe Controll::Assistant do
18
+ context 'Session assistant' do
19
+ subject { SessionAssistant.new controller }
20
+
21
+ let(:controller) { MyController.new }
22
+
23
+ its(:controller) { should == controller }
24
+ its(:session) { should == {:name => 'kris'} }
25
+ its(:name) { should == 'kris' }
26
+
27
+ specify do
28
+ controller.sess(:name).should == 'kris'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ class MyAssistant < Controll::Assistant
4
+ controller_methods :params
5
+ end
6
+
7
+ class MyController
8
+ def params
9
+ {:id => 7}
10
+ end
11
+
12
+ def my_assistant
13
+ @my_assistant ||= MyAssistant.new self
14
+ end
15
+ end
16
+
17
+ describe Controll::Assistant do
18
+ context 'My assistant with params delegation' do
19
+ subject { MyAssistant.new controller }
20
+
21
+ let(:controller) { MyController.new }
22
+
23
+ its(:controller) { should == controller }
24
+ its(:params) { should == {:id => 7} }
25
+ end
26
+ end
@@ -6,7 +6,7 @@ class NiceController
6
6
  end
7
7
  end
8
8
 
9
- class SignInCommand < Controll::Command
9
+ class SignOffCommand < Controll::Command
10
10
  attribute :parent_id, String
11
11
 
12
12
  def perform
@@ -15,7 +15,7 @@ class SignInCommand < Controll::Command
15
15
  end
16
16
 
17
17
  class NiceCommander < Controll::Commander
18
- command_method(:sign_in, name: 'kris') { {parent_id: parent_id} }
18
+ command_method(:sign_off, name: 'kris') { {parent_id: parent_id} }
19
19
 
20
20
  def params
21
21
  {:id => 7}
@@ -43,13 +43,13 @@ describe Controll::Command do
43
43
 
44
44
  describe '.command name, *args' do
45
45
  specify do
46
- subject.command(:sign_in).should be_a Controll::Command
46
+ subject.command(:sign_off).should be_a Controll::Command
47
47
  end
48
48
  end
49
49
 
50
50
  describe '.command! name, *args' do
51
51
  specify do
52
- subject.command!(:sign_in).should == {id: 7, parent: 'my parent', user_id: 1 }
52
+ subject.command!(:sign_off).should == {id: 7, parent: 'my parent', user_id: 1 }
53
53
  end
54
54
  end
55
55
  end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ class MyController
4
+ include Controll::Enabler::Macros
5
+
6
+ # Mocking!
7
+ def render path
8
+ path
9
+ end
10
+ alias_method :redirect_to, :render
11
+ end
12
+
13
+ module Executors
14
+ class Services < Controlled
15
+ end
16
+ end
17
+
18
+ module Commanders
19
+ class Services < Commander
20
+ end
21
+ end
22
+
23
+ module Notifiers
24
+ class Services < Typed
25
+ end
26
+ end
27
+
28
+ module Assistants
29
+ class Services < Assistant
30
+ end
31
+ end
32
+
33
+ module Flows
34
+ class Services < Master
35
+ end
36
+ end
37
+
38
+ describe Controll::Enabler do
39
+ subject { controller.new }
40
+ let(:controller) { MyController }
41
+
42
+ describe 'class level macros' do
43
+
44
+ describe '.commander name, options = {}' do
45
+ before :all do
46
+ controller.commander :services
47
+ end
48
+
49
+ its(:commander) { should be_a Commanders::Services }
50
+ end
51
+
52
+ describe '.commander name, options = {}' do
53
+ before :all do
54
+ controller.notifier :services
55
+ end
56
+
57
+ its(:notifier) { should be_a Notifiers::Services }
58
+ end
59
+
60
+ describe '.assistant name, options = {}' do
61
+ before :all do
62
+ controller.assistant :services
63
+ end
64
+
65
+ its(:assistant) { should be_a Assistants::Services }
66
+ end
67
+
68
+ describe '.flow name, options = {}' do
69
+ before :all do
70
+ controller.flow :services
71
+ end
72
+
73
+ its(:flow) { should be_a Flows::Services }
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ class SweetController
4
+ include Controll::Enabler::Maps
5
+ end
6
+
7
+ describe Controll::Enabler::Maps do
8
+ subject { controller.new }
9
+
10
+ let(:controller) { SweetController }
11
+
12
+ describe '.redirect_map {}' do
13
+ before :all do
14
+ controller.redirect_map :index => %w{alpha beta}
15
+ end
16
+
17
+ specify do
18
+ controller.redirect_map.should == {:index => ['alpha', 'beta'] }
19
+ end
20
+ end
21
+
22
+ describe '.render_map {}' do
23
+ before :all do
24
+ controller.render_map :index => %w{alpha zeta}
25
+ end
26
+
27
+ specify do
28
+ controller.render_map.should == {:index => ['alpha', 'zeta'] }
29
+ end
30
+ end
31
+ end
@@ -1,31 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  class Notifier
4
- include Controll::Helper::Notify
4
+ include Controll::Enabler::Notify
5
5
  end
6
6
 
7
- describe Controll::Helper::Notify do
7
+ describe Controll::Enabler::Notify do
8
8
  subject { Notifier.new }
9
9
 
10
10
  context 'initial state' do
11
- describe '.notifications' do
12
- its(:notifications) { should be_empty }
13
- end
14
-
15
11
  describe '.main_event' do
16
- its(:main_event) { should be_a Hashie::Mash }
17
- end
18
-
19
- describe '.create_notification' do
20
- specify { subject.send(:create_notification, :updated).should be_a Hashie::Mash }
12
+ its(:main_event) { should be_a Controll::Event }
21
13
  end
22
14
 
23
- describe '.create_event' do
24
- specify { subject.send(:create_event, :updated).should be_a Hashie::Mash }
25
- end
26
-
27
- describe '.create_notice' do
28
- specify { subject.send(:create_notice,:updated).should be_a Hashie::Mash }
15
+ Controll::Event.valid_types.each do |type|
16
+ describe ".create_#{type}" do
17
+ specify { subject.send(:"create_#{type}",:updated).should be_a Controll::Event }
18
+ end
29
19
  end
30
20
 
31
21
  describe '.notify' do
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ class MySweetController
4
+ include Controll::Enabler
5
+
6
+ redirect_map :index => %w{success}
7
+
8
+ render_map :show => %w{success}
9
+
10
+ # Mocking!
11
+ def render path
12
+ path
13
+ end
14
+ alias_method :redirect_to, :render
15
+ end
16
+
17
+ describe Controll::Enabler::PathHandler do
18
+ subject { Controll::Enabler::PathHandler.new controller }
19
+
20
+ let(:controller) { MySweetController.new }
21
+
22
+ describe '.execute *args' do
23
+ end
24
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ class MySweetController
4
+ include Controll::Enabler
5
+
6
+ def fallback_path
7
+ 'root'
8
+ end
9
+
10
+ def away
11
+ 'away'
12
+ end
13
+
14
+ def perfect
15
+ 'perfect'
16
+ end
17
+ end
18
+
19
+ ActionMapper = Controll::Flow::ActionMapper
20
+ Action = Controll::Flow::Action
21
+
22
+ class Redirecter < ActionMapper::Complex
23
+ event_map 'inperfect' => [:cool, :sweet], 'away' => [:success]
24
+ end
25
+
26
+ class Renderer < ActionMapper::Simple
27
+ events %w{perfect}
28
+ end
29
+
30
+ describe Controll::Enabler::PathResolver do
31
+ def notice name
32
+ Hashie::Mash.new(name: name.to_sym, type: :notice)
33
+ end
34
+
35
+ def error name
36
+ Hashie::Mash.new(name: name.to_sym, type: :error)
37
+ end
38
+
39
+ let(:controller) { MySweetController.new }
40
+
41
+ let(:render_map) { {'perfect' => [:cool, :sweet], 'home' => [:success] }}
42
+ let(:redirect_map) { {'inperfect' => [:cool, :sweet], 'away' => [:success] } }
43
+
44
+ let(:fallback_action) { Action::Fallback.new controller }
45
+
46
+ context 'initialize controller, render_map' do
47
+ subject { Controll::Enabler::PathResolver.new controller, render_map }
48
+
49
+ its(:caller) { should == controller }
50
+ its(:controller) { should == controller }
51
+ its(:event_map) { should == render_map }
52
+
53
+ describe '.resolve' do
54
+ specify do
55
+ subject.resolve.should == 'home'
56
+ end
57
+
58
+ describe '.resolve :cool' do
59
+ specify do
60
+ subject.resolve(:cool).should == 'perfect'
61
+ end
62
+ end
63
+
64
+ describe '.resolve sweet' do
65
+ specify do
66
+ subject.resolve(:sweet).should == 'perfect'
67
+ end
68
+ end
69
+
70
+ describe '.resolve :uncool' do
71
+ specify do
72
+ subject.resolve(:uncool).should_not == 'perfect'
73
+ end
74
+
75
+ specify do
76
+ subject.resolve(:uncool).should == nil
77
+ end
78
+ end
79
+
80
+ describe '.resolve Fallback Action' do
81
+ specify do
82
+ subject.resolve(fallback_action).should == nil
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ class MyController
4
+ include Controll::Enabler
5
+
6
+ # Mocking!
7
+ def render path
8
+ path
9
+ end
10
+ alias_method :redirect_to, :render
11
+ end
12
+
13
+ describe Controll::Enabler do
14
+ subject { controller.new }
15
+ let(:controller) { MyController }
16
+
17
+ context 'instance' do
18
+ describe 'do_redirect' do
19
+ specify do
20
+ expect { subject.do_redirect }.to raise_error(ArgumentError)
21
+ end
22
+ end
23
+
24
+ describe 'do_render' do
25
+ specify do
26
+ expect { subject.do_render }.to raise_error(ArgumentError)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ class Container
4
+ include Controll::Event::Helper
5
+ end
6
+
7
+ describe Controll::Event::Helper do
8
+ subject { Container.new }
9
+
10
+ let(:events) { %w{sign_in sign_out} }
11
+ let(:bad_events) { %w{bad stuff} }
12
+
13
+ let(:event) { 'sign_in' }
14
+ let(:bad_event) { 'unknown' }
15
+
16
+ describe '.normalize event' do
17
+ context 'Controll::Event' do
18
+ specify { subject.normalize(Controll::Event.new(:x)).should be_a Controll::Event }
19
+ end
20
+
21
+ context 'Symbol' do
22
+ specify { subject.normalize(:x).should be_a Controll::Event }
23
+ end
24
+
25
+ context 'Hash' do
26
+ specify { subject.normalize(:name => :y).should be_a Controll::Event }
27
+ end
28
+ end
29
+
30
+ describe '.create_event' do
31
+ specify { subject.create_event(:x).should be_a Controll::Event }
32
+ end
33
+ end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Controll::Helper::EventMatcher do
4
- subject { Controll::Helper::EventMatcher.new event }
3
+ describe Controll::Event::Matcher do
4
+ subject { Controll::Event::Matcher.new event }
5
5
 
6
6
  let(:events) { %w{sign_in sign_out} }
7
7
  let(:bad_events) { %w{bad stuff} }
@@ -10,7 +10,8 @@ describe Controll::Helper::EventMatcher do
10
10
  let(:bad_event) { 'unknown' }
11
11
 
12
12
  describe '.initialize event' do
13
- its(:event) { should == 'sign_in' }
13
+ its(:event) { should be_a Controll::Event }
14
+ its('event.name') { should == :sign_in }
14
15
  end
15
16
 
16
17
  describe '.match? events' do