controll 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +19 -0
  4. data/Gemfile.lock +134 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.md +320 -0
  7. data/Rakefile +49 -0
  8. data/VERSION +1 -0
  9. data/controll.gemspec +184 -0
  10. data/lib/controll.rb +14 -0
  11. data/lib/controll/assistant.rb +19 -0
  12. data/lib/controll/command.rb +24 -0
  13. data/lib/controll/commander.rb +24 -0
  14. data/lib/controll/errors.rb +1 -0
  15. data/lib/controll/executor.rb +6 -0
  16. data/lib/controll/executor/base.rb +16 -0
  17. data/lib/controll/executor/notificator.rb +12 -0
  18. data/lib/controll/flow_handler.rb +11 -0
  19. data/lib/controll/flow_handler/base.rb +19 -0
  20. data/lib/controll/flow_handler/control.rb +85 -0
  21. data/lib/controll/flow_handler/errors.rb +5 -0
  22. data/lib/controll/flow_handler/event_helper.rb +18 -0
  23. data/lib/controll/flow_handler/redirect.rb +51 -0
  24. data/lib/controll/flow_handler/redirect/action.rb +45 -0
  25. data/lib/controll/flow_handler/redirect/mapper.rb +41 -0
  26. data/lib/controll/flow_handler/render.rb +51 -0
  27. data/lib/controll/helper.rb +101 -0
  28. data/lib/controll/helper/event_matcher.rb +21 -0
  29. data/lib/controll/helper/hash_access.rb +26 -0
  30. data/lib/controll/helper/notify.rb +74 -0
  31. data/lib/controll/helper/params.rb +20 -0
  32. data/lib/controll/helper/path_resolver.rb +45 -0
  33. data/lib/controll/helper/session.rb +20 -0
  34. data/lib/controll/notify.rb +7 -0
  35. data/lib/controll/notify/base.rb +75 -0
  36. data/lib/controll/notify/flash.rb +52 -0
  37. data/lib/controll/notify/typed.rb +39 -0
  38. data/spec/acceptance/app_test.rb +156 -0
  39. data/spec/app/.gitignore +15 -0
  40. data/spec/app/Gemfile +6 -0
  41. data/spec/app/Gemfile.lock +108 -0
  42. data/spec/app/README.rdoc +261 -0
  43. data/spec/app/Rakefile +7 -0
  44. data/spec/app/app/controllers/application_controller.rb +6 -0
  45. data/spec/app/app/controllers/posts_controller.rb +52 -0
  46. data/spec/app/app/models/.gitkeep +0 -0
  47. data/spec/app/app/models/post.rb +88 -0
  48. data/spec/app/app/views/layouts/application.html.erb +13 -0
  49. data/spec/app/app/views/posts/_form.html.erb +31 -0
  50. data/spec/app/app/views/posts/edit.html.erb +6 -0
  51. data/spec/app/app/views/posts/index.html.erb +23 -0
  52. data/spec/app/app/views/posts/new.html.erb +5 -0
  53. data/spec/app/app/views/posts/show.html.erb +8 -0
  54. data/spec/app/config.ru +4 -0
  55. data/spec/app/config/application.rb +16 -0
  56. data/spec/app/config/boot.rb +6 -0
  57. data/spec/app/config/environment.rb +5 -0
  58. data/spec/app/config/environments/development.rb +21 -0
  59. data/spec/app/config/environments/test.rb +29 -0
  60. data/spec/app/config/initializers/backtrace_silencers.rb +7 -0
  61. data/spec/app/config/initializers/inflections.rb +15 -0
  62. data/spec/app/config/initializers/mime_types.rb +5 -0
  63. data/spec/app/config/initializers/secret_token.rb +7 -0
  64. data/spec/app/config/initializers/session_store.rb +8 -0
  65. data/spec/app/config/locales/en.yml +5 -0
  66. data/spec/app/config/routes.rb +62 -0
  67. data/spec/app/db/seeds.rb +7 -0
  68. data/spec/app/lib/assets/.gitkeep +0 -0
  69. data/spec/app/lib/tasks/.gitkeep +0 -0
  70. data/spec/app/log/.gitkeep +0 -0
  71. data/spec/app/public/404.html +26 -0
  72. data/spec/app/public/422.html +26 -0
  73. data/spec/app/public/500.html +25 -0
  74. data/spec/app/public/favicon.ico +0 -0
  75. data/spec/app/public/index.html +241 -0
  76. data/spec/app/public/javascripts/application.js +9663 -0
  77. data/spec/app/public/robots.txt +5 -0
  78. data/spec/app/public/stylesheets/application.css +83 -0
  79. data/spec/app/script/rails +6 -0
  80. data/spec/app/spec/controllers/posts_controller_spec.rb +59 -0
  81. data/spec/app/spec/isolated_spec_helper.rb +6 -0
  82. data/spec/app/spec/spec_helper.rb +5 -0
  83. data/spec/app/spec/unit/controllers/posts_controller_isolated_spec.rb +63 -0
  84. data/spec/app/spec/unit/controllers/posts_controller_spec.rb +59 -0
  85. data/spec/app/test/functional/.gitkeep +0 -0
  86. data/spec/app/test/functional/posts_controller_test.rb +67 -0
  87. data/spec/app/test/isolated_test_helper.rb +7 -0
  88. data/spec/app/test/test_helper.rb +6 -0
  89. data/spec/app/test/unit/.gitkeep +0 -0
  90. data/spec/app/test/unit/controllers/posts_controller_isolated_test.rb +71 -0
  91. data/spec/app/test/unit/controllers/posts_controller_test.rb +67 -0
  92. data/spec/app/vendor/assets/javascripts/.gitkeep +0 -0
  93. data/spec/app/vendor/assets/stylesheets/.gitkeep +0 -0
  94. data/spec/app/vendor/plugins/.gitkeep +0 -0
  95. data/spec/controll/asssistant_spec.rb +5 -0
  96. data/spec/controll/command_spec.rb +56 -0
  97. data/spec/controll/commander_spec.rb +68 -0
  98. data/spec/controll/executor/notificator_spec.rb +27 -0
  99. data/spec/controll/flow_handler/control_spec.rb +159 -0
  100. data/spec/controll/flow_handler/redirect/action_spec.rb +48 -0
  101. data/spec/controll/flow_handler/redirect/mapper_spec.rb +69 -0
  102. data/spec/controll/flow_handler/redirect_spec.rb +93 -0
  103. data/spec/controll/flow_handler/render_spec.rb +110 -0
  104. data/spec/controll/helper/event_matcher_spec.rb +21 -0
  105. data/spec/controll/helper/hash_access_spec.rb +25 -0
  106. data/spec/controll/helper/notify_spec.rb +48 -0
  107. data/spec/controll/helper/params_spec.rb +28 -0
  108. data/spec/controll/helper/path_resolver_spec.rb +49 -0
  109. data/spec/controll/helper/session_spec.rb +28 -0
  110. data/spec/controll/helper_spec.rb +108 -0
  111. data/spec/controll/notify/base_spec.rb +123 -0
  112. data/spec/controll/notify/flash_spec.rb +27 -0
  113. data/spec/controll/notify/message_handler.rb +72 -0
  114. data/spec/controll/notify/typed_spec.rb +28 -0
  115. data/spec/functional_test_helper.rb +25 -0
  116. data/spec/helper.rb +33 -0
  117. data/spec/rspec_controller_class.rb +15 -0
  118. data/spec/rspec_functional_helper.rb +25 -0
  119. data/spec/rspec_helper.rb +42 -0
  120. data/spec/spec_helper.rb +11 -0
  121. data/spec/test_helper.rb +183 -0
  122. data/spec/unit/functional_test_helper_test.rb +65 -0
  123. data/spec/unit/macros_test.rb +43 -0
  124. data/spec/unit/mixin_test.rb +147 -0
  125. data/spec/unit/rspec_functional_helper.rb +42 -0
  126. data/spec/unit/rspec_helper_test.rb +91 -0
  127. data/spec/unit/test_helper_test.rb +235 -0
  128. metadata +289 -0
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ def notice name
4
+ Hashie::Mash.new(name: name.to_sym, type: :notice)
5
+ end
6
+
7
+ def error name
8
+ Hashie::Mash.new(name: name.to_sym, type: :error)
9
+ end
10
+
11
+ describe Controll::FlowHandler::Redirect::Mapper do
12
+ let(:redirections) do
13
+ {
14
+ :error => error_map, :notice => notice_map
15
+ }
16
+ end
17
+
18
+ let(:notice_map) do
19
+ {:welcome => valid_events }
20
+ end
21
+
22
+ let(:valid_events) { [:hello, :hi] }
23
+ let(:invalid_events) { [:blip, :blap] }
24
+
25
+ let(:error_map) do
26
+ {bad: ['bad_payment', 'wrong_payment'] }
27
+ end
28
+
29
+ let(:types) { [:notice, :error] }
30
+
31
+ context 'use' do
32
+ subject { clazz.new hello, notice_map }
33
+
34
+ let(:clazz) { Controll::FlowHandler::Redirect::Mapper }
35
+ let(:hello) { notice :hello }
36
+ let(:bad_payment) { error :bad_payment }
37
+
38
+ describe '.initialize' do
39
+ its(:event) { should == hello }
40
+ its(:redirect_map) { should == notice_map }
41
+ end
42
+
43
+ describe '.map' do
44
+ specify do
45
+ subject.map.should == 'welcome'
46
+ end
47
+ end
48
+
49
+ describe '.matcher event' do
50
+ specify do
51
+ subject.send(:matcher, hello).should be_a Controll::Helper::EventMatcher
52
+ end
53
+
54
+ specify do
55
+ subject.send(:matcher, hello).event.should == hello
56
+ end
57
+ end
58
+
59
+ describe '.valid?' do
60
+ specify do
61
+ subject.send(:valid?, valid_events).should be_true
62
+ end
63
+
64
+ specify do
65
+ subject.send(:valid?, invalid_events).should be_false
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+
3
+ class HelloToWelcomeRedirect < Controll::FlowHandler::Redirect
4
+ set_redirections :welcome => [:hello, :hi]
5
+ end
6
+
7
+ class ErrorBadRedirect < Controll::FlowHandler::Redirect
8
+ set_redirections :error, bad: ['bad_payment', 'wrong_payment']
9
+ end
10
+
11
+ def notification name
12
+ Hashie::Mash.new(name: name.to_sym, type: :notice)
13
+ end
14
+
15
+ def error name
16
+ Hashie::Mash.new(name: name.to_sym, type: :error)
17
+ end
18
+
19
+ describe Controll::FlowHandler::Redirect do
20
+
21
+ describe 'class macros' do
22
+ before :all do
23
+ ErrorBadRedirect.set_redirections :error, crap: ['bad_payment', 'wrong_payment']
24
+ end
25
+
26
+ specify {
27
+ ErrorBadRedirect.redirections_for(:error).should == {crap: ['bad_payment', 'wrong_payment']}
28
+ }
29
+
30
+ specify {
31
+ ErrorBadRedirect.redirections.should == {error: {crap: ['bad_payment', 'wrong_payment']} }
32
+ }
33
+ end
34
+
35
+ # context 'use directly without subclassing' do
36
+ # subject { clazz.new '/' }
37
+
38
+ # let(:clazz) { Controll::FlowHandler::Redirect }
39
+
40
+ # let(:hello) { notification :hello }
41
+
42
+ # describe '.action event' do
43
+ # specify do
44
+ # expect { clazz.action(:hello) }.to raise_error(Controll::FlowHandler::Redirect::NoRedirectionFoundError)
45
+ # end
46
+ # end
47
+ # end
48
+
49
+ # context 'HelloToWelcomeRedirect subclass' do
50
+ # subject { clazz.new '/' }
51
+
52
+ # let(:clazz) { HelloToWelcomeRedirect }
53
+
54
+ # context 'has redirections' do
55
+ # describe '.action event' do
56
+ # specify do
57
+ # expect { clazz.action(:hello) }.to_not raise_error(Controll::FlowHandler::Redirect::NoRedirectionFoundError)
58
+ # end
59
+
60
+ # specify do
61
+ # clazz.action(:hello).should be_a HelloToWelcomeRedirect
62
+ # end
63
+
64
+ # specify do
65
+ # clazz.action(:hi).path.should == 'welcome'
66
+ # end
67
+ # end
68
+ # end
69
+ # end
70
+
71
+ context 'ErrorBadRedirect subclass' do
72
+ subject { clazz.new '/' }
73
+
74
+ let(:clazz) { ErrorBadRedirect }
75
+
76
+ context 'has error redirections' do
77
+ describe '.action event' do
78
+ specify do
79
+ expect { clazz.action(:hello) }.to raise_error(Controll::FlowHandler::NoRedirectionFoundError)
80
+ end
81
+
82
+ specify do
83
+ clazz.action(error :bad_payment).should be_a ErrorBadRedirect
84
+ end
85
+
86
+ specify do
87
+ clazz.action(error :wrong_payment).path.should == 'crap'
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ end
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+
3
+ class NoEventsRender < Controll::FlowHandler::Render
4
+ def self.events
5
+ []
6
+ end
7
+ end
8
+
9
+ class HiRender < Controll::FlowHandler::Render
10
+ def self.events
11
+ [:hi]
12
+ end
13
+ end
14
+
15
+ class HelloRender < Controll::FlowHandler::Render
16
+ set_events :hello, :damn
17
+ set_default_path '/default'
18
+ end
19
+
20
+ def notification name
21
+ Hashie::Mash.new(name: name.to_sym, type: :notification)
22
+ end
23
+
24
+ describe Controll::FlowHandler::Render do
25
+
26
+ context 'use directly without sublclassing' do
27
+ subject { clazz.new '/' }
28
+
29
+ let(:clazz) { Controll::FlowHandler::Render }
30
+
31
+ let(:hello) { notification :hello }
32
+
33
+ describe '.action event' do
34
+ specify do
35
+ expect { clazz.action(:hello) }.to raise_error(Controll::FlowHandler::NoEventsDefinedError)
36
+ end
37
+ end
38
+ end
39
+
40
+ context 'NoEventsRender subclass' do
41
+ subject { clazz.new '/' }
42
+
43
+ let(:clazz) { NoEventsRender }
44
+
45
+ context 'empty events' do
46
+ describe '.action event' do
47
+ specify do
48
+ expect { clazz.action(:hello) }.to raise_error(Controll::FlowHandler::NoEventsDefinedError)
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ context 'HiRender subclass' do
55
+ subject { clazz.new '/' }
56
+
57
+ let(:clazz) { HiRender }
58
+ let(:event) { notification :hello }
59
+
60
+ context 'has events' do
61
+ describe '.action event' do
62
+
63
+ describe 'does not respond to hello' do
64
+ 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
70
+ end
71
+
72
+ specify do
73
+ clazz.action(:hello).should == nil
74
+ end
75
+ end
76
+
77
+ describe 'responds to hi' do
78
+ # default_path not implemented!
79
+ specify do
80
+ expect { clazz.action(:hi) }.to raise_error NotImplementedError
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ context 'HelloRender subclass' do
88
+ subject { clazz.new default_path }
89
+
90
+ let(:clazz) { HelloRender }
91
+ let(:event) { notification :hello }
92
+ let(:default_path) { '/default' }
93
+
94
+ context 'has events and default_path' do
95
+ describe '.action event' do
96
+ specify do
97
+ clazz.action(event).should be_a HelloRender
98
+ end
99
+
100
+ specify do
101
+ clazz.action(event).path.should == default_path
102
+ end
103
+
104
+ specify do
105
+ clazz.action(event, 'other_path').path.should == 'other_path'
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Controll::Helper::EventMatcher do
4
+ subject { Controll::Helper::EventMatcher.new event }
5
+
6
+ let(:events) { %w{sign_in sign_out} }
7
+ let(:bad_events) { %w{bad stuff} }
8
+
9
+ let(:event) { 'sign_in' }
10
+ let(:bad_event) { 'unknown' }
11
+
12
+ describe '.initialize event' do
13
+ its(:event) { should == 'sign_in' }
14
+ end
15
+
16
+ describe '.match? events' do
17
+ specify { subject.match?(events).should be_true }
18
+
19
+ specify { subject.match?(bad_events).should be_false }
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ class Hasher
4
+ include Controll::Helper::HashAccess
5
+
6
+ attr_reader :params
7
+
8
+ def initialize params = nil
9
+ @params = params || {name: 'kris'}
10
+ end
11
+ end
12
+
13
+ describe Controll::Helper::HashAccess do
14
+
15
+ subject { clazz.new }
16
+ let(:clazz) { Hasher }
17
+
18
+ describe '.hash_access_methods *args' do
19
+ before :all do
20
+ clazz.hash_access_methods :name, hash: :params
21
+ end
22
+
23
+ specify { subject.name.should == 'kris' }
24
+ end
25
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ class Notifier
4
+ include Controll::Helper::Notify
5
+ end
6
+
7
+ describe Controll::Helper::Notify do
8
+ subject { Notifier.new }
9
+
10
+ context 'initial state' do
11
+ describe '.notifications' do
12
+ its(:notifications) { should be_empty }
13
+ end
14
+
15
+ 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 }
21
+ end
22
+
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 }
29
+ end
30
+
31
+ describe '.notify' do
32
+ describe '.with name only' do
33
+ specify { subject.notify(:updated).main_event.type.should == :notice }
34
+ end
35
+
36
+ describe 'name and :error type' do
37
+ specify { subject.notify(:updated, :error).main_event.type.should == :error }
38
+ end
39
+
40
+ describe 'name and unknown type' do
41
+ specify do
42
+ expect { subject.notify(:updated, :unknown) }.to raise_error
43
+ end
44
+ end
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ class Parameters
4
+ include Controll::Helper::Params
5
+
6
+ attr_reader :params
7
+
8
+ def initialize params = nil
9
+ @params = params || {name: 'kris', shoe_size: 43, gender: 'male' }
10
+ end
11
+ end
12
+
13
+ describe Controll::Helper::Params do
14
+
15
+ subject { clazz.new }
16
+ let(:clazz) { Parameters }
17
+
18
+ describe '.param_methods *args' do
19
+ before :all do
20
+ clazz.param_methods :name, :shoe_size
21
+ clazz.param_method :gender
22
+ end
23
+
24
+ its(:name) { should == 'kris' }
25
+ its(:shoe_size) { should == 43 }
26
+ its(:gender) { should == 'male' }
27
+ end
28
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ class MySweetController
4
+ include Controll::Helper
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::Helper::PathResolver do
18
+ subject { Controll::Helper::PathResolver.new controller }
19
+
20
+ let(:controller) { MySweetController.new }
21
+
22
+ describe '.extract_path' do
23
+ describe ':redirect_map' do
24
+ specify do
25
+ subject.extract_path(:redirect_map).should == 'index'
26
+ end
27
+ end
28
+
29
+ describe ':render_paths' do
30
+ specify do
31
+ subject.extract_path(:render_paths).should == 'show'
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '.resolve_path' do
37
+ describe ':redirect_map' do
38
+ specify do
39
+ subject.resolve_path(:redirect_map).should == 'index'
40
+ end
41
+ end
42
+
43
+ describe ':render_paths' do
44
+ specify do
45
+ subject.resolve_path(:render_paths).should == 'show'
46
+ end
47
+ end
48
+ end
49
+ end