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,67 @@
1
+ require 'test_helper'
2
+
3
+ module PostsController
4
+ class TestCase < ActiveSupport::TestCase
5
+ include FocusedController::TestHelper
6
+
7
+ setup do
8
+ @post = Post.create(:title => 'Hello', :body => 'Omg')
9
+ end
10
+ end
11
+
12
+ class IndexTest < TestCase
13
+ test "should get index" do
14
+ req
15
+ assert_response :success
16
+ assert_not_nil controller.posts
17
+ end
18
+ end
19
+
20
+ class NewTest < TestCase
21
+ test "should get new" do
22
+ req
23
+ assert_response :success
24
+ end
25
+ end
26
+
27
+ class CreateTest < TestCase
28
+ test "should create post" do
29
+ assert_difference('Post.count') do
30
+ req :post => @post.attributes
31
+ end
32
+
33
+ assert_redirected_to post_path(controller.post)
34
+ end
35
+ end
36
+
37
+ class ShowTest < TestCase
38
+ test "should show post" do
39
+ req :id => @post.id
40
+ assert_response :success
41
+ end
42
+ end
43
+
44
+ class EditTest < TestCase
45
+ test "should get edit" do
46
+ req :id => @post.id
47
+ assert_response :success
48
+ end
49
+ end
50
+
51
+ class UpdateTest < TestCase
52
+ test "should update post" do
53
+ req :id => @post.id
54
+ assert_redirected_to post_path(controller.post)
55
+ end
56
+ end
57
+
58
+ class DestroyTest < TestCase
59
+ test "should destroy post" do
60
+ assert_difference('Post.count', -1) do
61
+ req :id => @post.id
62
+ end
63
+
64
+ assert_redirected_to posts_path
65
+ end
66
+ end
67
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Controll::Assistant do
4
+ pending 'TODO'
5
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ class NiceController
4
+ def flash
5
+ @flash ||= Hash.new
6
+ end
7
+ end
8
+
9
+ class SignInCommand < Controll::Command
10
+ attribute :parent_id, String
11
+
12
+ def perform
13
+ {id: params[:id], parent: parent_id, user_id: session[:user_id] }
14
+ end
15
+ end
16
+
17
+ class NiceCommander < Controll::Commander
18
+ command_method(:sign_in, name: 'kris') { {parent_id: parent_id} }
19
+
20
+ def params
21
+ {:id => 7}
22
+ end
23
+
24
+ def session
25
+ {:user_id => 1}
26
+ end
27
+
28
+ def parent_id
29
+ 'my parent'
30
+ end
31
+ end
32
+
33
+ describe Controll::Command do
34
+
35
+ context 'Commander instance' do
36
+ subject { commander_clazz.new controller, options }
37
+ let(:commander_clazz) { NiceCommander }
38
+
39
+ let(:controller) { NiceController.new }
40
+ let(:options) do
41
+ {name: 'nice' }
42
+ end
43
+
44
+ describe '.command name, *args' do
45
+ specify do
46
+ subject.command(:sign_in).should be_a Controll::Command
47
+ end
48
+ end
49
+
50
+ describe '.command! name, *args' do
51
+ specify do
52
+ subject.command!(:sign_in).should == {id: 7, parent: 'my parent', user_id: 1 }
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ class NiceController
4
+ def flash
5
+ @flash ||= Hash.new
6
+ end
7
+ end
8
+
9
+ class SignInCommand < Imperator::Command
10
+ def perform
11
+ 'signed_in'
12
+ end
13
+ end
14
+
15
+ class NiceCommander < Controll::Commander
16
+ command_method(:sign_in, name: 'kris') { {id: id} }
17
+
18
+ def id
19
+ 'my id'
20
+ end
21
+ end
22
+
23
+ describe Controll::Commander do
24
+ context 'class methods' do
25
+ subject { Controll::Commander }
26
+ end
27
+
28
+ context 'Commander instance' do
29
+ subject { commander_clazz.new controller, options }
30
+ let(:commander_clazz) { NiceCommander }
31
+
32
+ let(:controller) { NiceController.new }
33
+ let(:options) do
34
+ {name: 'nice' }
35
+ end
36
+
37
+ # attr_reader :controller, :options
38
+
39
+ describe '.initialize controller, options = {}' do
40
+ its(:controller) { should == controller }
41
+ its(:options) { should == options }
42
+ end
43
+
44
+ describe '.command name, *args' do
45
+ specify do
46
+ subject.command(:sign_in).should be_a Imperator::Command
47
+ end
48
+ end
49
+
50
+ describe '.command! name, *args' do
51
+ specify do
52
+ subject.command!(:sign_in).should == 'signed_in'
53
+ end
54
+ end
55
+
56
+ describe '.use_command (alias: command!)' do
57
+ specify do
58
+ subject.use_command(:sign_in).should == 'signed_in'
59
+ end
60
+ end
61
+
62
+ describe '.perform_command (alias: command!)' do
63
+ specify do
64
+ subject.perform_command(:sign_in).should == 'signed_in'
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ class MyExec < Controll::Executor::Notificator
5
+ end
6
+
7
+ class MyAwesomeController
8
+ def hello
9
+ "hello"
10
+ end
11
+ end
12
+
13
+ describe Controll::Executor::Notificator do
14
+ subject { MyExec.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
+ end
@@ -0,0 +1,159 @@
1
+ require 'spec_helper'
2
+
3
+ module MyController
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
+ class EmptyEventFlowHandler < Controll::FlowHandler::Control
16
+ def event
17
+ end
18
+ end
19
+
20
+ class UpdateEventWithoutHandlerMapping < Controll::FlowHandler::Control
21
+ def event
22
+ :update
23
+ end
24
+ end
25
+
26
+ class UpdateEventFlowHandler < Controll::FlowHandler::Control
27
+ def event
28
+ :update
29
+ end
30
+
31
+ class Render < Controll::FlowHandler::Render
32
+ set_events :update
33
+ set_default_path 'default'
34
+ end
35
+ end
36
+
37
+ class UpdateEventNoMatchFlowHandler < Controll::FlowHandler::Control
38
+ def event
39
+ :update
40
+ end
41
+
42
+ class Render < Controll::FlowHandler::Render
43
+ set_events :create
44
+ set_default_path '/default'
45
+ end
46
+ end
47
+
48
+
49
+
50
+ describe Controll::FlowHandler::Control do
51
+ context 'use directly without sublclassing' do
52
+ subject { flow_handler.new controller }
53
+
54
+ let(:flow_handler) { Controll::FlowHandler::Control }
55
+ let(:controller) { MyController::Update.new }
56
+
57
+ describe '.initialize' do
58
+ specify do
59
+ subject.controller.should == controller
60
+ end
61
+ end
62
+
63
+ describe '.execute' do
64
+ specify do
65
+ expect { subject.execute }.to_not raise_error
66
+ end
67
+ end
68
+ end
69
+
70
+ context 'A Control FlowHandler with empty #event method' do
71
+ subject { flow_handler.new controller }
72
+
73
+ let(:flow_handler) { EmptyEventFlowHandler }
74
+ let(:controller) { MyController::Update.new }
75
+
76
+ describe '.initialize' do
77
+ specify do
78
+ subject.controller.should == controller
79
+ end
80
+ end
81
+
82
+ describe '.execute' do
83
+ specify do
84
+ expect { subject.execute }.to_not raise_error(NotImplementedError)
85
+ end
86
+
87
+ # since event returns nil
88
+ specify do
89
+ expect { subject.execute }.to_not raise_error
90
+ end
91
+ end
92
+ end
93
+
94
+ context 'A Control FlowHandler where #event returns :update notice event' do
95
+ subject { flow_handler.new controller }
96
+
97
+ let(:flow_handler) { UpdateEventWithoutHandlerMapping }
98
+ let(:controller) { MyController::Update.new }
99
+
100
+ describe '.initialize' do
101
+ specify do
102
+ subject.controller.should == controller
103
+ end
104
+ end
105
+
106
+ describe '.execute' do
107
+ # since event returns nil
108
+ specify do
109
+ expect { subject.execute }.to_not raise_error
110
+ end
111
+ end
112
+ end
113
+
114
+ context 'A Control FlowHandler where #event returns :update notice event and has a Render class with matching mapping' do
115
+ subject { flow_handler.new controller }
116
+
117
+ let(:flow_handler) { UpdateEventFlowHandler }
118
+ let(:controller) { MyController::Update.new }
119
+
120
+ describe '.initialize' do
121
+ specify do
122
+ subject.controller.should == controller
123
+ end
124
+ end
125
+
126
+ describe '.execute' do
127
+ # since event returns nil
128
+ specify do
129
+ expect { subject.execute }.to_not raise_error(Controll::FlowHandler::Control::ActionEventError)
130
+ end
131
+
132
+ specify do
133
+ subject.execute
134
+ subject.executed?.should be_true
135
+ end
136
+ end
137
+ end
138
+
139
+ context 'A Control FlowHandler where #event returns :update notice event and has a Render class with NO matching mapping' do
140
+ subject { flow_handler.new controller }
141
+
142
+ let(:flow_handler) { UpdateEventNoMatchFlowHandler }
143
+ let(:controller) { MyController::Update.new }
144
+
145
+ describe '.initialize' do
146
+ specify do
147
+ subject.controller.should == controller
148
+ end
149
+ end
150
+
151
+ describe '.execute' do
152
+ # since event returns nil
153
+ specify do
154
+ expect { subject.execute }.to_not raise_error
155
+ end
156
+ end
157
+ end
158
+
159
+ end
@@ -0,0 +1,48 @@
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::Action 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
+ let(:clazz) { Controll::FlowHandler::Redirect::Action }
33
+ let(:hello) { notice :hello }
34
+ let(:bad_payment) { error :bad_payment }
35
+
36
+ describe '.action event' do
37
+ subject { clazz.new hello, redirections, types }
38
+
39
+ specify do
40
+ expect { subject.map }.to_not raise_error(Controll::FlowHandler::NoRedirectionFoundError)
41
+ end
42
+
43
+ specify do
44
+ subject.map.should == 'welcome'
45
+ end
46
+ end
47
+ end
48
+ end