controll 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +134 -0
- data/LICENSE.txt +20 -0
- data/README.md +320 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/controll.gemspec +184 -0
- data/lib/controll.rb +14 -0
- data/lib/controll/assistant.rb +19 -0
- data/lib/controll/command.rb +24 -0
- data/lib/controll/commander.rb +24 -0
- data/lib/controll/errors.rb +1 -0
- data/lib/controll/executor.rb +6 -0
- data/lib/controll/executor/base.rb +16 -0
- data/lib/controll/executor/notificator.rb +12 -0
- data/lib/controll/flow_handler.rb +11 -0
- data/lib/controll/flow_handler/base.rb +19 -0
- data/lib/controll/flow_handler/control.rb +85 -0
- data/lib/controll/flow_handler/errors.rb +5 -0
- data/lib/controll/flow_handler/event_helper.rb +18 -0
- data/lib/controll/flow_handler/redirect.rb +51 -0
- data/lib/controll/flow_handler/redirect/action.rb +45 -0
- data/lib/controll/flow_handler/redirect/mapper.rb +41 -0
- data/lib/controll/flow_handler/render.rb +51 -0
- data/lib/controll/helper.rb +101 -0
- data/lib/controll/helper/event_matcher.rb +21 -0
- data/lib/controll/helper/hash_access.rb +26 -0
- data/lib/controll/helper/notify.rb +74 -0
- data/lib/controll/helper/params.rb +20 -0
- data/lib/controll/helper/path_resolver.rb +45 -0
- data/lib/controll/helper/session.rb +20 -0
- data/lib/controll/notify.rb +7 -0
- data/lib/controll/notify/base.rb +75 -0
- data/lib/controll/notify/flash.rb +52 -0
- data/lib/controll/notify/typed.rb +39 -0
- data/spec/acceptance/app_test.rb +156 -0
- data/spec/app/.gitignore +15 -0
- data/spec/app/Gemfile +6 -0
- data/spec/app/Gemfile.lock +108 -0
- data/spec/app/README.rdoc +261 -0
- data/spec/app/Rakefile +7 -0
- data/spec/app/app/controllers/application_controller.rb +6 -0
- data/spec/app/app/controllers/posts_controller.rb +52 -0
- data/spec/app/app/models/.gitkeep +0 -0
- data/spec/app/app/models/post.rb +88 -0
- data/spec/app/app/views/layouts/application.html.erb +13 -0
- data/spec/app/app/views/posts/_form.html.erb +31 -0
- data/spec/app/app/views/posts/edit.html.erb +6 -0
- data/spec/app/app/views/posts/index.html.erb +23 -0
- data/spec/app/app/views/posts/new.html.erb +5 -0
- data/spec/app/app/views/posts/show.html.erb +8 -0
- data/spec/app/config.ru +4 -0
- data/spec/app/config/application.rb +16 -0
- data/spec/app/config/boot.rb +6 -0
- data/spec/app/config/environment.rb +5 -0
- data/spec/app/config/environments/development.rb +21 -0
- data/spec/app/config/environments/test.rb +29 -0
- data/spec/app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/app/config/initializers/inflections.rb +15 -0
- data/spec/app/config/initializers/mime_types.rb +5 -0
- data/spec/app/config/initializers/secret_token.rb +7 -0
- data/spec/app/config/initializers/session_store.rb +8 -0
- data/spec/app/config/locales/en.yml +5 -0
- data/spec/app/config/routes.rb +62 -0
- data/spec/app/db/seeds.rb +7 -0
- data/spec/app/lib/assets/.gitkeep +0 -0
- data/spec/app/lib/tasks/.gitkeep +0 -0
- data/spec/app/log/.gitkeep +0 -0
- data/spec/app/public/404.html +26 -0
- data/spec/app/public/422.html +26 -0
- data/spec/app/public/500.html +25 -0
- data/spec/app/public/favicon.ico +0 -0
- data/spec/app/public/index.html +241 -0
- data/spec/app/public/javascripts/application.js +9663 -0
- data/spec/app/public/robots.txt +5 -0
- data/spec/app/public/stylesheets/application.css +83 -0
- data/spec/app/script/rails +6 -0
- data/spec/app/spec/controllers/posts_controller_spec.rb +59 -0
- data/spec/app/spec/isolated_spec_helper.rb +6 -0
- data/spec/app/spec/spec_helper.rb +5 -0
- data/spec/app/spec/unit/controllers/posts_controller_isolated_spec.rb +63 -0
- data/spec/app/spec/unit/controllers/posts_controller_spec.rb +59 -0
- data/spec/app/test/functional/.gitkeep +0 -0
- data/spec/app/test/functional/posts_controller_test.rb +67 -0
- data/spec/app/test/isolated_test_helper.rb +7 -0
- data/spec/app/test/test_helper.rb +6 -0
- data/spec/app/test/unit/.gitkeep +0 -0
- data/spec/app/test/unit/controllers/posts_controller_isolated_test.rb +71 -0
- data/spec/app/test/unit/controllers/posts_controller_test.rb +67 -0
- data/spec/app/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/app/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/app/vendor/plugins/.gitkeep +0 -0
- data/spec/controll/asssistant_spec.rb +5 -0
- data/spec/controll/command_spec.rb +56 -0
- data/spec/controll/commander_spec.rb +68 -0
- data/spec/controll/executor/notificator_spec.rb +27 -0
- data/spec/controll/flow_handler/control_spec.rb +159 -0
- data/spec/controll/flow_handler/redirect/action_spec.rb +48 -0
- data/spec/controll/flow_handler/redirect/mapper_spec.rb +69 -0
- data/spec/controll/flow_handler/redirect_spec.rb +93 -0
- data/spec/controll/flow_handler/render_spec.rb +110 -0
- data/spec/controll/helper/event_matcher_spec.rb +21 -0
- data/spec/controll/helper/hash_access_spec.rb +25 -0
- data/spec/controll/helper/notify_spec.rb +48 -0
- data/spec/controll/helper/params_spec.rb +28 -0
- data/spec/controll/helper/path_resolver_spec.rb +49 -0
- data/spec/controll/helper/session_spec.rb +28 -0
- data/spec/controll/helper_spec.rb +108 -0
- data/spec/controll/notify/base_spec.rb +123 -0
- data/spec/controll/notify/flash_spec.rb +27 -0
- data/spec/controll/notify/message_handler.rb +72 -0
- data/spec/controll/notify/typed_spec.rb +28 -0
- data/spec/functional_test_helper.rb +25 -0
- data/spec/helper.rb +33 -0
- data/spec/rspec_controller_class.rb +15 -0
- data/spec/rspec_functional_helper.rb +25 -0
- data/spec/rspec_helper.rb +42 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/test_helper.rb +183 -0
- data/spec/unit/functional_test_helper_test.rb +65 -0
- data/spec/unit/macros_test.rb +43 -0
- data/spec/unit/mixin_test.rb +147 -0
- data/spec/unit/rspec_functional_helper.rb +42 -0
- data/spec/unit/rspec_helper_test.rb +91 -0
- data/spec/unit/test_helper_test.rb +235 -0
- metadata +289 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Sessione
|
4
|
+
include Controll::Helper::Session
|
5
|
+
|
6
|
+
attr_reader :session
|
7
|
+
|
8
|
+
def initialize session = nil
|
9
|
+
@session = session || {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) { Sessione }
|
17
|
+
|
18
|
+
describe '.session_methods *args' do
|
19
|
+
before :all do
|
20
|
+
clazz.session_methods :name, :shoe_size
|
21
|
+
clazz.session_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,108 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class MyController
|
4
|
+
include Controll::Helper
|
5
|
+
|
6
|
+
# Mocking!
|
7
|
+
def render path
|
8
|
+
path
|
9
|
+
end
|
10
|
+
alias_method :redirect_to, :render
|
11
|
+
end
|
12
|
+
|
13
|
+
class Executor < Controll::Executor::Notificator
|
14
|
+
end
|
15
|
+
|
16
|
+
class ServiceCommander < Executor
|
17
|
+
end
|
18
|
+
|
19
|
+
class ServiceMessageHandler < Executor
|
20
|
+
end
|
21
|
+
|
22
|
+
class ServiceAssistant < Executor
|
23
|
+
end
|
24
|
+
|
25
|
+
class ServiceDelegateAssistant < Executor
|
26
|
+
end
|
27
|
+
|
28
|
+
class ServiceFlowHandler < Executor
|
29
|
+
end
|
30
|
+
|
31
|
+
describe Controll::Helper do
|
32
|
+
subject { controller.new }
|
33
|
+
let(:controller) { MyController }
|
34
|
+
|
35
|
+
describe 'class level macros' do
|
36
|
+
|
37
|
+
describe '.commander name, options = {}' do
|
38
|
+
before :all do
|
39
|
+
controller.commander :service
|
40
|
+
end
|
41
|
+
|
42
|
+
its(:commander) { should be_a ServiceCommander }
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '.commander name, options = {}' do
|
46
|
+
before :all do
|
47
|
+
controller.message_handler :service
|
48
|
+
end
|
49
|
+
|
50
|
+
its(:message_handler) { should be_a ServiceMessageHandler }
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '.assistant name, options = {}' do
|
54
|
+
before :all do
|
55
|
+
controller.assistant :service
|
56
|
+
end
|
57
|
+
|
58
|
+
its(:assistant) { should be_a ServiceAssistant }
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '.delegate_assistant name, options = {}' do
|
62
|
+
before :all do
|
63
|
+
controller.delegate_assistant :service
|
64
|
+
end
|
65
|
+
|
66
|
+
its(:assistant) { should be_a ServiceDelegateAssistant }
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
describe '.flow_handler name, options = {}' do
|
71
|
+
before :all do
|
72
|
+
controller.flow_handler :service
|
73
|
+
end
|
74
|
+
|
75
|
+
its(:flow_handler) { should be_a ServiceFlowHandler }
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '.redirect_map {}' do
|
79
|
+
before :all do
|
80
|
+
controller.redirect_map :index => %w{alpha beta}
|
81
|
+
end
|
82
|
+
|
83
|
+
its(:redirect_map) { should == {:index => ['alpha', 'beta'] } }
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '.redirect_map {}' do
|
87
|
+
before :all do
|
88
|
+
controller.render_map :index => %w{alpha beta}
|
89
|
+
end
|
90
|
+
|
91
|
+
its(:render_paths) { should == {:index => ['alpha', 'beta'] } }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'instance' do
|
96
|
+
describe 'do_redirect *args' do
|
97
|
+
specify do
|
98
|
+
subject.do_redirect.should == nil
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'do_render *args' do
|
103
|
+
specify do
|
104
|
+
subject.do_render.should == nil
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class FlashController
|
4
|
+
attr_reader :flash
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@flash = {}
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Translator < Controll::Notify::Base
|
12
|
+
type :notice
|
13
|
+
|
14
|
+
def messages
|
15
|
+
{
|
16
|
+
must_sign_in: 'You need to sign in before accessing this page!',
|
17
|
+
|
18
|
+
auth_service_error: %q{There was an error at the remote authentication service.
|
19
|
+
You have not been signed in.},
|
20
|
+
|
21
|
+
cant_delete_current_account: 'You are currently signed in with this account!',
|
22
|
+
user_save_error: 'This is embarrassing! There was an error while creating your account from which we were not able to recover.',
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def auth_error!
|
27
|
+
'Error while authenticating via ' + service_name + '. The service did not return valid data.'
|
28
|
+
end
|
29
|
+
|
30
|
+
def auth_invalid!
|
31
|
+
'Error while authenticating via {{full_route}}. The service returned invalid data for the user id.'
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def service_name
|
37
|
+
'facebook'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe Controll::Notify::Base do
|
42
|
+
subject { Translator.new controller }
|
43
|
+
|
44
|
+
let(:controller) { FlashController.new }
|
45
|
+
|
46
|
+
let(:sign_in_msg) { 'You need to sign in before accessing this page!' }
|
47
|
+
|
48
|
+
describe 'notify - method' do
|
49
|
+
specify do
|
50
|
+
subject.notify('must_sign_in').should == sign_in_msg
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'notify_msg - messages map' do
|
55
|
+
specify do
|
56
|
+
subject.send(:notify_msg, :must_sign_in).should == sign_in_msg
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'I18n message' do
|
61
|
+
# services:
|
62
|
+
# notice:
|
63
|
+
# signed_in: 'Your account has been created and you have been signed in!'
|
64
|
+
# signed_out: 'You have been signed out!'
|
65
|
+
let(:signed_in_msg) { 'Your account has been created and you have been signed in!' }
|
66
|
+
let(:signed_out_msg) { 'You have been signed out!' }
|
67
|
+
|
68
|
+
before do
|
69
|
+
::I18n.backend.store_translations :en,
|
70
|
+
:translator => {
|
71
|
+
:signed_in => signed_in_msg,
|
72
|
+
:signed_out => signed_out_msg
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
after do
|
77
|
+
::I18n.backend.reload!
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "t 'signed_in'" do
|
81
|
+
specify do
|
82
|
+
subject.notify('signed_in').should == signed_in_msg
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'Variable substitution' do
|
88
|
+
context 'method calls' do
|
89
|
+
let(:auth_error_msg) { 'Error while authenticating via facebook. The service did not return valid data.' }
|
90
|
+
|
91
|
+
specify do
|
92
|
+
subject.notify('auth_error!').should == auth_error_msg
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'Liquid templates with args' do
|
97
|
+
let(:auth_error_msg) { 'Error while authenticating via www.facebook.com/login. The service returned invalid data for the user id.' }
|
98
|
+
|
99
|
+
specify do
|
100
|
+
subject.notify(:auth_invalid!, full_route: 'www.facebook.com/login').should == auth_error_msg
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'I18n messages with args' do
|
105
|
+
let(:name) { 'kris' }
|
106
|
+
|
107
|
+
before do
|
108
|
+
::I18n.backend.store_translations :en,
|
109
|
+
:translator => {
|
110
|
+
:signed_out => "Hey %{name}, you have been signed out!"
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
after do
|
115
|
+
::I18n.backend.reload!
|
116
|
+
end
|
117
|
+
|
118
|
+
specify do
|
119
|
+
subject.notify(:signed_out, name: name).should == "Hey #{name}, you have been signed out!"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class MockController
|
4
|
+
def flash
|
5
|
+
@flash ||= Hash.new
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Controll::Notify::Flash do
|
10
|
+
subject { Controll::Notify::Flash.new MockController.new }
|
11
|
+
|
12
|
+
describe 'class methods' do
|
13
|
+
subject { Controll::Notify::Flash }
|
14
|
+
|
15
|
+
describe '.types' do
|
16
|
+
its(:types) { should include(:notice, :warning) }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '.add_types' do
|
20
|
+
before do
|
21
|
+
subject.add_types :payment, :help
|
22
|
+
end
|
23
|
+
|
24
|
+
its(:types) { should include(:payment, :help) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module MessageHandler
|
2
|
+
class Services < Controll::Notify::Typed
|
3
|
+
class Base < Controll::Notify::Base
|
4
|
+
def provider_name
|
5
|
+
provider.capitalize
|
6
|
+
end
|
7
|
+
|
8
|
+
def service_name
|
9
|
+
service_route.capitalize
|
10
|
+
end
|
11
|
+
|
12
|
+
def full_route
|
13
|
+
service_route + '/' + provider_name
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class ErrorMsg < Base
|
18
|
+
type :error
|
19
|
+
|
20
|
+
def messages
|
21
|
+
{
|
22
|
+
must_sign_in: 'You need to sign in before accessing this page!',
|
23
|
+
|
24
|
+
auth_service_error: %q{There was an error at the remote authentication service.
|
25
|
+
You have not been signed in.},
|
26
|
+
|
27
|
+
cant_delete_current_account: 'You are currently signed in with this account!',
|
28
|
+
user_save_error: 'This is embarrassing! There was an error while creating your account from which we were not able to recover.',
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def bad
|
33
|
+
'bad stuff!'
|
34
|
+
end
|
35
|
+
|
36
|
+
def auth_error!
|
37
|
+
'Error while authenticating via ' + service_name + '. The service did not return valid data.'
|
38
|
+
end
|
39
|
+
|
40
|
+
def auth_invalid!
|
41
|
+
'Error while authenticating via {{full_route}}. The service returned invalid data for the user id.'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class NoticeMsg < Base
|
46
|
+
type :notice
|
47
|
+
|
48
|
+
# for :signed_in and :signed_out - defined in locale file under:
|
49
|
+
|
50
|
+
# services:
|
51
|
+
# notice:
|
52
|
+
# signed_in: 'Your account has been created and you have been signed in!'
|
53
|
+
# signed_out: 'You have been signed out!'
|
54
|
+
|
55
|
+
def already_connected
|
56
|
+
'Your account at {{provider_name}} is already connected with this site.'
|
57
|
+
end
|
58
|
+
|
59
|
+
def account_added
|
60
|
+
'Your {{provider_name}} account has been added for signing in at this site.'
|
61
|
+
end
|
62
|
+
|
63
|
+
def sign_in_success
|
64
|
+
'Signed in successfully via {{provider_name}}.'
|
65
|
+
end
|
66
|
+
|
67
|
+
def hello
|
68
|
+
'hello you'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'controll/notify/message_handler'
|
3
|
+
|
4
|
+
class MyController
|
5
|
+
attr_reader :flash
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@flash = {}
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Controll::Notify::Typed do
|
13
|
+
subject { MessageHandler::Services.new controller }
|
14
|
+
|
15
|
+
let(:controller) { MyController.new }
|
16
|
+
|
17
|
+
describe 'notice' do
|
18
|
+
specify do
|
19
|
+
subject.notice.hello.should == 'hello you'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'error' do
|
24
|
+
specify do
|
25
|
+
subject.error.bad.should == 'bad stuff!'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module FocusedController
|
4
|
+
module FunctionalTestHelper
|
5
|
+
def get(*args)
|
6
|
+
super(FocusedController.action_name, *args)
|
7
|
+
end
|
8
|
+
|
9
|
+
def post(*args)
|
10
|
+
super(FocusedController.action_name, *args)
|
11
|
+
end
|
12
|
+
|
13
|
+
def put(*args)
|
14
|
+
super(FocusedController.action_name, *args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete(*args)
|
18
|
+
super(FocusedController.action_name, *args)
|
19
|
+
end
|
20
|
+
|
21
|
+
def head(*args)
|
22
|
+
super(FocusedController.action_name, *args)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'test/unit/testcase'
|
3
|
+
require 'active_support/test_case'
|
4
|
+
require 'minitest/spec'
|
5
|
+
require 'minitest/autorun'
|
6
|
+
require 'focused_controller'
|
7
|
+
require 'pathname'
|
8
|
+
require 'ostruct'
|
9
|
+
require 'rspec/core'
|
10
|
+
|
11
|
+
TEST_ROOT = File.expand_path('..', __FILE__)
|
12
|
+
|
13
|
+
# Don't want to actually use RSpec to run our tests
|
14
|
+
# module RSpec::Core::DSL
|
15
|
+
# remove_method :describe
|
16
|
+
# end
|
17
|
+
|
18
|
+
# Annoying monkey-patches. "require 'rspec/rails'" pulls in 'capybara/rails', if it
|
19
|
+
# can, and capybara/rails assumes there is a full rails env present. So this is a
|
20
|
+
# hack to make it not fail.
|
21
|
+
module Rails
|
22
|
+
def self.version
|
23
|
+
'3.0'
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.root
|
27
|
+
Pathname.new('')
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.application
|
31
|
+
OpenStruct.new(:env_config => {}, :env_defaults => {})
|
32
|
+
end
|
33
|
+
end
|