short_circuit 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +1 -1
- data/README.md +54 -31
- data/lib/short_circuit.rb +5 -3
- data/lib/short_circuit/presentable.rb +1 -0
- data/lib/short_circuit/presenter.rb +8 -7
- data/lib/short_circuit/version.rb +1 -1
- data/spec/dummy/README.rdoc +15 -248
- data/spec/dummy/Rakefile +0 -1
- data/spec/dummy/app/assets/javascripts/application.js +3 -5
- data/spec/dummy/app/controllers/application_controller.rb +3 -1
- data/spec/dummy/app/views/layouts/application.html.erb +2 -2
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/config/application.rb +6 -37
- data/spec/dummy/config/boot.rb +4 -9
- data/spec/dummy/config/environment.rb +2 -2
- data/spec/dummy/config/environments/development.rb +11 -19
- data/spec/dummy/config/environments/production.rb +40 -27
- data/spec/dummy/config/environments/test.rb +13 -14
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +6 -5
- data/spec/dummy/config/initializers/secret_token.rb +7 -2
- data/spec/dummy/config/initializers/session_store.rb +0 -5
- data/spec/dummy/config/initializers/wrap_parameters.rb +6 -6
- data/spec/dummy/config/locales/en.yml +20 -2
- data/spec/dummy/config/routes.rb +22 -24
- data/spec/dummy/log/test.log +0 -37
- data/spec/dummy/public/404.html +43 -11
- data/spec/dummy/public/422.html +43 -11
- data/spec/dummy/public/500.html +43 -11
- data/spec/short_circuit/presentable_spec.rb +53 -16
- data/spec/short_circuit/presenter_spec.rb +54 -0
- data/spec/spec_helper.rb +9 -17
- metadata +19 -52
- data/Rakefile +0 -21
- data/lib/active_record_extension.rb +0 -13
- data/lib/tasks/short_circuit_tasks.rake +0 -4
- data/spec/dummy/log/development.log +0 -1
- data/spec/dummy/script/rails +0 -6
data/spec/dummy/config/routes.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
Dummy::Application.routes.draw do
|
2
|
-
# The priority is based upon order of creation:
|
3
|
-
#
|
2
|
+
# The priority is based upon order of creation: first created -> highest priority.
|
3
|
+
# See how all your routes lay out with "rake routes".
|
4
4
|
|
5
|
-
#
|
6
|
-
#
|
7
|
-
|
5
|
+
# You can have the root of your site routed with "root"
|
6
|
+
# root 'welcome#index'
|
7
|
+
|
8
|
+
# Example of regular route:
|
9
|
+
# get 'products/:id' => 'catalog#view'
|
8
10
|
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# This route can be invoked with purchase_url(:id => product.id)
|
11
|
+
# Example of named route that can be invoked with purchase_url(id: product.id)
|
12
|
+
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
|
12
13
|
|
13
|
-
#
|
14
|
+
# Example resource route (maps HTTP verbs to controller actions automatically):
|
14
15
|
# resources :products
|
15
16
|
|
16
|
-
#
|
17
|
+
# Example resource route with options:
|
17
18
|
# resources :products do
|
18
19
|
# member do
|
19
20
|
# get 'short'
|
@@ -25,34 +26,31 @@ Dummy::Application.routes.draw do
|
|
25
26
|
# end
|
26
27
|
# end
|
27
28
|
|
28
|
-
#
|
29
|
+
# Example resource route with sub-resources:
|
29
30
|
# resources :products do
|
30
31
|
# resources :comments, :sales
|
31
32
|
# resource :seller
|
32
33
|
# end
|
33
34
|
|
34
|
-
#
|
35
|
+
# Example resource route with more complex sub-resources:
|
35
36
|
# resources :products do
|
36
37
|
# resources :comments
|
37
38
|
# resources :sales do
|
38
|
-
# get 'recent', :
|
39
|
+
# get 'recent', on: :collection
|
39
40
|
# end
|
40
41
|
# end
|
41
42
|
|
42
|
-
#
|
43
|
+
# Example resource route with concerns:
|
44
|
+
# concern :toggleable do
|
45
|
+
# post 'toggle'
|
46
|
+
# end
|
47
|
+
# resources :posts, concerns: :toggleable
|
48
|
+
# resources :photos, concerns: :toggleable
|
49
|
+
|
50
|
+
# Example resource route within a namespace:
|
43
51
|
# namespace :admin do
|
44
52
|
# # Directs /admin/products/* to Admin::ProductsController
|
45
53
|
# # (app/controllers/admin/products_controller.rb)
|
46
54
|
# resources :products
|
47
55
|
# end
|
48
|
-
|
49
|
-
# You can have the root of your site routed with "root"
|
50
|
-
# just remember to delete public/index.html.
|
51
|
-
# root :to => 'welcome#index'
|
52
|
-
|
53
|
-
# See how all your routes lay out with "rake routes"
|
54
|
-
|
55
|
-
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
56
|
-
# Note: This route will make all actions in every controller accessible via GET requests.
|
57
|
-
# match ':controller(/:action(/:id))(.:format)'
|
58
56
|
end
|
data/spec/dummy/log/test.log
CHANGED
@@ -1,37 +0,0 @@
|
|
1
|
-
Connecting to database specified by database.yml
|
2
|
-
Connecting to database specified by database.yml
|
3
|
-
Connecting to database specified by database.yml
|
4
|
-
Connecting to database specified by database.yml
|
5
|
-
Connecting to database specified by database.yml
|
6
|
-
Connecting to database specified by database.yml
|
7
|
-
Connecting to database specified by database.yml
|
8
|
-
Connecting to database specified by database.yml
|
9
|
-
Connecting to database specified by database.yml
|
10
|
-
Connecting to database specified by database.yml
|
11
|
-
Connecting to database specified by database.yml
|
12
|
-
Connecting to database specified by database.yml
|
13
|
-
Connecting to database specified by database.yml
|
14
|
-
Connecting to database specified by database.yml
|
15
|
-
Connecting to database specified by database.yml
|
16
|
-
Connecting to database specified by database.yml
|
17
|
-
Connecting to database specified by database.yml
|
18
|
-
Connecting to database specified by database.yml
|
19
|
-
Connecting to database specified by database.yml
|
20
|
-
Connecting to database specified by database.yml
|
21
|
-
Connecting to database specified by database.yml
|
22
|
-
Connecting to database specified by database.yml
|
23
|
-
Connecting to database specified by database.yml
|
24
|
-
Connecting to database specified by database.yml
|
25
|
-
Connecting to database specified by database.yml
|
26
|
-
Connecting to database specified by database.yml
|
27
|
-
Connecting to database specified by database.yml
|
28
|
-
Connecting to database specified by database.yml
|
29
|
-
Connecting to database specified by database.yml
|
30
|
-
Connecting to database specified by database.yml
|
31
|
-
Connecting to database specified by database.yml
|
32
|
-
Connecting to database specified by database.yml
|
33
|
-
Connecting to database specified by database.yml
|
34
|
-
Connecting to database specified by database.yml
|
35
|
-
Connecting to database specified by database.yml
|
36
|
-
Connecting to database specified by database.yml
|
37
|
-
Connecting to database specified by database.yml
|
data/spec/dummy/public/404.html
CHANGED
@@ -2,17 +2,48 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
-
<style
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
16
47
|
</style>
|
17
48
|
</head>
|
18
49
|
|
@@ -22,5 +53,6 @@
|
|
22
53
|
<h1>The page you were looking for doesn't exist.</h1>
|
23
54
|
<p>You may have mistyped the address or the page may have moved.</p>
|
24
55
|
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
25
57
|
</body>
|
26
58
|
</html>
|
data/spec/dummy/public/422.html
CHANGED
@@ -2,17 +2,48 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<title>The change you wanted was rejected (422)</title>
|
5
|
-
<style
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
16
47
|
</style>
|
17
48
|
</head>
|
18
49
|
|
@@ -22,5 +53,6 @@
|
|
22
53
|
<h1>The change you wanted was rejected.</h1>
|
23
54
|
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
55
|
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
25
57
|
</body>
|
26
58
|
</html>
|
data/spec/dummy/public/500.html
CHANGED
@@ -2,17 +2,48 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<title>We're sorry, but something went wrong (500)</title>
|
5
|
-
<style
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
16
47
|
</style>
|
17
48
|
</head>
|
18
49
|
|
@@ -21,5 +52,6 @@
|
|
21
52
|
<div class="dialog">
|
22
53
|
<h1>We're sorry, but something went wrong.</h1>
|
23
54
|
</div>
|
55
|
+
<p>If you are the application owner check the logs for more information.</p>
|
24
56
|
</body>
|
25
57
|
</html>
|
@@ -1,29 +1,66 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
3
|
module ShortCircuit
|
4
4
|
describe Presentable do
|
5
|
-
before
|
6
|
-
|
5
|
+
before do
|
6
|
+
mock_model('TestModel')
|
7
|
+
TestModel.any_instance.stub(:test_method).and_return('Test Method')
|
8
|
+
TestModel.send(:include, Presentable)
|
9
|
+
stub_const('TestModelPresenter', Presenter)
|
7
10
|
end
|
8
11
|
|
9
|
-
|
10
|
-
@model.presenter.should be_an_instance_of TestModelPresenter
|
11
|
-
end
|
12
|
+
let(:model) { TestModel.new }
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
end
|
14
|
+
describe '#presenter' do
|
15
|
+
subject(:presenter) { model.presenter }
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
it 'returns the correct presenter' do
|
18
|
+
expect(presenter).to be_a(Presenter)
|
19
|
+
expect(presenter).to be_a(TestModelPresenter)
|
20
|
+
end
|
19
21
|
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
+
describe '#present' do
|
24
|
+
context 'when the method exists' do
|
25
|
+
let(:method) { :test_method }
|
26
|
+
|
27
|
+
it 'calls the presenter method' do
|
28
|
+
expect(model.presenter).to receive(:send)
|
29
|
+
model.present(method)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when the method does not exist' do
|
34
|
+
let(:method) { :fake_method }
|
35
|
+
|
36
|
+
it 'does not throw an error' do
|
37
|
+
expect{model.present(method)}.to_not raise_error
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'calls the error_response method' do
|
41
|
+
expect(model.presenter).to receive(:error_response)
|
42
|
+
model.present(method)
|
43
|
+
end
|
44
|
+
end
|
23
45
|
end
|
24
46
|
|
25
|
-
|
26
|
-
|
47
|
+
describe '#present!' do
|
48
|
+
context 'when the method exists' do
|
49
|
+
let(:method) { :test_method }
|
50
|
+
|
51
|
+
it 'calls the presenter method' do
|
52
|
+
expect(model.presenter).to receive(:send)
|
53
|
+
model.present!(method)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when the method does not exist' do
|
58
|
+
let(:method) { :fake_method }
|
59
|
+
|
60
|
+
it 'throws an error' do
|
61
|
+
expect{model.present!(method)}.to raise_error(NoMethodError)
|
62
|
+
end
|
63
|
+
end
|
27
64
|
end
|
28
65
|
end
|
29
66
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ShortCircuit
|
4
|
+
describe Presenter do
|
5
|
+
let(:presentable_object) { mock_model('TestModel', test_method: 'Test Method') }
|
6
|
+
|
7
|
+
let(:presenter) { Presenter.new(presentable_object) }
|
8
|
+
|
9
|
+
it 'delegates missing method calls to controller helpers' do
|
10
|
+
expect(ApplicationController.helpers).to receive(:fake_method)
|
11
|
+
presenter.send(:fake_method)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'delegates missing method calls to url helpers' do
|
15
|
+
expect(presenter.url_helpers).to receive(:fake_method)
|
16
|
+
presenter.send(:fake_method)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'delegates missing method calls to presentable object' do
|
20
|
+
expect(presenter.__getobj__).to receive(:fake_method)
|
21
|
+
presenter.send(:fake_method)
|
22
|
+
|
23
|
+
expect(presenter.test_method).to eq(presentable_object.test_method)
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#initialize' do
|
27
|
+
it 'sets presentable_object' do
|
28
|
+
expect(presenter.__getobj__).to eq(presentable_object)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'set an instance variable for presentable_object' do
|
32
|
+
expect(presenter.instance_variable_get("@#{presentable_object.class.to_s.underscore}")).to eq(presentable_object)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#url_helpers' do
|
37
|
+
subject(:url_helpers) { presenter.url_helpers }
|
38
|
+
|
39
|
+
it 'returns url_helpers' do
|
40
|
+
expect(url_helpers).to_not be_nil
|
41
|
+
expect(url_helpers).to respond_to(:url_for)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#error_response' do
|
46
|
+
subject(:error_response) { presenter.error_response('error', :method) }
|
47
|
+
|
48
|
+
it 'returns a blank response' do
|
49
|
+
expect(error_response).to be_empty
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|