tarquinn 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +85 -0
- data/.gitignore +10 -0
- data/.rubocop.yml +29 -0
- data/.rubocop_todo.yml +13 -0
- data/Dockerfile +21 -0
- data/Gemfile +16 -2
- data/README.md +16 -0
- data/Rakefile +8 -3
- data/config/check_specs.yml +3 -0
- data/config/rubycritc.rb +12 -0
- data/config/yardstick.rb +13 -0
- data/config/yardstick.yml +33 -0
- data/docker-compose.yml +23 -0
- data/lib/tarquinn/class_methods.rb +43 -12
- data/lib/tarquinn/condition/action_checker.rb +24 -7
- data/lib/tarquinn/condition/method_caller.rb +25 -8
- data/lib/tarquinn/condition/proc_runner.rb +18 -7
- data/lib/tarquinn/condition.rb +57 -4
- data/lib/tarquinn/controller.rb +56 -13
- data/lib/tarquinn/redirection_config.rb +92 -0
- data/lib/tarquinn/redirection_handler.rb +97 -0
- data/lib/tarquinn/request_handler.rb +61 -0
- data/lib/tarquinn/request_handler_builder.rb +84 -0
- data/lib/tarquinn/version.rb +3 -1
- data/lib/tarquinn.rb +74 -8
- data/spec/dummy/Rakefile +8 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/stylesheets/application.css +1 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +6 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +6 -0
- data/spec/dummy/app/controllers/application_controller.rb +4 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/tarquinn/dummy_controller.rb +43 -0
- data/spec/dummy/app/controllers/tarquinn/dummy_route_controller.rb +37 -0
- data/spec/dummy/app/helpers/application_helper.rb +4 -0
- data/spec/dummy/app/jobs/application_job.rb +9 -0
- data/spec/dummy/app/mailers/application_mailer.rb +6 -0
- data/spec/dummy/app/models/application_record.rb +5 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/app/views/tarquinn/dummy_route/index.html +0 -0
- data/spec/dummy/app/views/tarquinn/dummy_route/new.html +0 -0
- data/spec/dummy/bin/rails +6 -0
- data/spec/dummy/bin/rake +6 -0
- data/spec/dummy/bin/setup +35 -0
- data/spec/dummy/config/application.rb +24 -0
- data/spec/dummy/config/boot.rb +7 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +7 -0
- data/spec/dummy/config/environments/development.rb +69 -0
- data/spec/dummy/config/environments/production.rb +89 -0
- data/spec/dummy/config/environments/test.rb +62 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +26 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +10 -0
- data/spec/dummy/config/initializers/inflections.rb +17 -0
- data/spec/dummy/config/initializers/permissions_policy.rb +12 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +45 -0
- data/spec/dummy/config/routes.rb +8 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/config.ru +8 -0
- data/spec/dummy/db/schema.rb +16 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/storage/.keep +0 -0
- data/spec/dummy/tmp/.keep +0 -0
- data/spec/dummy/tmp/pids/.keep +0 -0
- data/spec/dummy/tmp/storage/.keep +0 -0
- data/spec/lib/tarquinn/condition/action_checker_spec.rb +4 -2
- data/spec/lib/tarquinn/condition/method_caller_spec.rb +5 -3
- data/spec/lib/tarquinn/condition/proc_runner_spec.rb +56 -4
- data/spec/lib/tarquinn/condition_spec.rb +53 -0
- data/spec/lib/tarquinn/controller_spec.rb +83 -10
- data/spec/lib/tarquinn/{config_spec.rb → redirection_config_spec.rb} +3 -1
- data/spec/lib/tarquinn/{handler_spec.rb → redirection_handler_spec.rb} +21 -3
- data/spec/lib/tarquinn/request_handler_builder_spec.rb +15 -0
- data/spec/lib/tarquinn/{engine_spec.rb → request_handler_spec.rb} +5 -3
- data/spec/lib/tarquinn_spec.rb +176 -13
- data/spec/spec_helper.rb +17 -7
- data/spec/support/shared_examples/config.rb +5 -4
- data/tarquinn.gemspec +10 -14
- data/tarquinn.jpg +0 -0
- metadata +83 -107
- data/Gemfile.lock +0 -58
- data/lib/tarquinn/builder.rb +0 -28
- data/lib/tarquinn/concern.rb +0 -17
- data/lib/tarquinn/config.rb +0 -39
- data/lib/tarquinn/engine.rb +0 -31
- data/lib/tarquinn/handler.rb +0 -49
- data/spec/lib/tarquinn/builder_spec.rb +0 -13
- data/spec/support/models/tarquinn/dummy_controller.rb +0 -43
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
.rails-default-error-page {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
.rails-default-error-page div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
.rails-default-error-page div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
.rails-default-error-page h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
.rails-default-error-page div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body class="rails-default-error-page">
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Tarquinn::Condition::ActionChecker do
|
@@ -34,7 +36,7 @@ describe Tarquinn::Condition::ActionChecker do
|
|
34
36
|
end
|
35
37
|
|
36
38
|
context 'when initialized with more routes' do
|
37
|
-
let(:routes) { [
|
39
|
+
let(:routes) { %i[show view] }
|
38
40
|
let(:subject) { described_class.new(routes) }
|
39
41
|
|
40
42
|
context 'when receiving a request for one of the given action' do
|
@@ -44,7 +46,7 @@ describe Tarquinn::Condition::ActionChecker do
|
|
44
46
|
end
|
45
47
|
|
46
48
|
context 'when receiving a request for another action' do
|
47
|
-
let(:routes) { [
|
49
|
+
let(:routes) { %i[update view] }
|
48
50
|
it do
|
49
51
|
expect(subject.check?(controller)).to be_falsey
|
50
52
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Tarquinn::Condition::MethodCaller do
|
@@ -24,7 +26,7 @@ describe Tarquinn::Condition::MethodCaller do
|
|
24
26
|
end
|
25
27
|
|
26
28
|
context 'when initialized with more methods' do
|
27
|
-
let(:methods) { [
|
29
|
+
let(:methods) { %i[true false] }
|
28
30
|
let(:subject) { described_class.new(methods) }
|
29
31
|
|
30
32
|
context 'when one return true and the other false' do
|
@@ -34,14 +36,14 @@ describe Tarquinn::Condition::MethodCaller do
|
|
34
36
|
end
|
35
37
|
|
36
38
|
context 'when all return true' do
|
37
|
-
let(:methods) { [
|
39
|
+
let(:methods) { %i[true true] }
|
38
40
|
it do
|
39
41
|
expect(subject.check?(controller)).to be_truthy
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
43
45
|
context 'when all return false' do
|
44
|
-
let(:methods) { [
|
46
|
+
let(:methods) { %i[false false] }
|
45
47
|
it do
|
46
48
|
expect(subject.check?(controller)).to be_falsey
|
47
49
|
end
|
@@ -1,22 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Tarquinn::Condition::ProcRunner do
|
4
|
-
let(:
|
5
|
-
let(:
|
6
|
-
let(:subject) { described_class.new
|
6
|
+
let(:rails_controller) { rails_controller_class.new }
|
7
|
+
let(:controller) { Tarquinn::Controller.new(rails_controller) }
|
8
|
+
let(:subject) { described_class.new(&block) }
|
9
|
+
let(:rails_controller_class) do
|
10
|
+
Class.new(ActionController::Base)
|
11
|
+
end
|
7
12
|
|
8
13
|
describe '#check?' do
|
9
14
|
context 'when block evaluates into true' do
|
15
|
+
let(:block) { proc { true } }
|
16
|
+
|
10
17
|
it do
|
11
18
|
expect(subject.check?(controller)).to be_truthy
|
12
19
|
end
|
13
20
|
end
|
14
21
|
|
15
22
|
context 'when block evaluates into false' do
|
16
|
-
let(:
|
23
|
+
let(:block) { proc { false } }
|
24
|
+
|
17
25
|
it do
|
18
26
|
expect(subject.check?(controller)).to be_falsey
|
19
27
|
end
|
20
28
|
end
|
29
|
+
|
30
|
+
context 'when the block gets calls the controller method' do
|
31
|
+
let(:block) { proc { match? } }
|
32
|
+
|
33
|
+
context 'when the method returns true' do
|
34
|
+
let(:rails_controller_class) do
|
35
|
+
Class.new(ActionController::Base) do
|
36
|
+
def match?
|
37
|
+
true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it do
|
43
|
+
expect(subject.check?(controller)).to be_truthy
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when the method returns false' do
|
48
|
+
let(:rails_controller_class) do
|
49
|
+
Class.new(ActionController::Base) do
|
50
|
+
def match?
|
51
|
+
false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it do
|
57
|
+
expect(subject.check?(controller)).to be_falsey
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when the block references a value defined outside' do
|
63
|
+
let(:block) do
|
64
|
+
val = value
|
65
|
+
proc { val }
|
66
|
+
end
|
67
|
+
let(:value) { [false, true].sample }
|
68
|
+
|
69
|
+
it do
|
70
|
+
expect(subject.check?(controller)).to eq(value)
|
71
|
+
end
|
72
|
+
end
|
21
73
|
end
|
22
74
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Tarquinn::Condition do
|
6
|
+
subject(:condition) { described_class.new }
|
7
|
+
|
8
|
+
let(:controller) { instance_double(Tarquinn::Controller) }
|
9
|
+
|
10
|
+
describe '.method_caller' do
|
11
|
+
context 'when methods are given' do
|
12
|
+
let(:methods) { %i[method1 method2] }
|
13
|
+
|
14
|
+
it do
|
15
|
+
expect(described_class.method_caller(methods))
|
16
|
+
.to be_a(Tarquinn::Condition::MethodCaller)
|
17
|
+
end
|
18
|
+
|
19
|
+
it do
|
20
|
+
expect(described_class.method_caller(methods))
|
21
|
+
.to eq(Tarquinn::Condition::MethodCaller.new(methods))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when no methods are given' do
|
26
|
+
let(:methods) { %i[] }
|
27
|
+
|
28
|
+
it do
|
29
|
+
expect(described_class.method_caller(methods)).to be_nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '.action_checker' do
|
35
|
+
let(:actions) { %i[index show] }
|
36
|
+
|
37
|
+
it do
|
38
|
+
expect(described_class.action_checker(actions))
|
39
|
+
.to be_a(Tarquinn::Condition::ActionChecker)
|
40
|
+
end
|
41
|
+
|
42
|
+
it do
|
43
|
+
expect(described_class.action_checker(actions))
|
44
|
+
.to eq(Tarquinn::Condition::ActionChecker.new(actions))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#check?' do
|
49
|
+
it do
|
50
|
+
expect { condition.check?(controller) }.to raise_error(NotImplementedError)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -1,38 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Tarquinn::Controller do
|
4
|
-
|
5
|
-
|
6
|
+
subject(:controller) { described_class.new(rails_controller) }
|
7
|
+
|
8
|
+
let(:rails_controller) { Tarquinn::DummyController.new }
|
6
9
|
|
7
10
|
describe '#call' do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
context 'when no arguments are given' do
|
12
|
+
before do
|
13
|
+
allow(rails_controller).to receive(:redirect_to).with(no_args)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'delegate a method call to the controller' do
|
17
|
+
subject.call(:redirect_to)
|
18
|
+
expect(rails_controller).to have_received(:redirect_to)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'when arguments are given' do
|
23
|
+
before do
|
24
|
+
allow(rails_controller)
|
25
|
+
.to receive(:redirect_to)
|
26
|
+
.with(1, 2, opt: 3)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'delegate a method call to the controller' do
|
30
|
+
subject.call(:redirect_to, 1, 2, opt: 3)
|
31
|
+
|
32
|
+
expect(rails_controller).to have_received(:redirect_to)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when a block is given' do
|
37
|
+
let(:block) { proc { 12 } }
|
38
|
+
|
39
|
+
before do
|
40
|
+
allow(rails_controller)
|
41
|
+
.to receive(:redirect_to)
|
42
|
+
.with(no_args).and_yield
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'delegate a method call to the controller' do
|
46
|
+
subject.call(:redirect_to, &block)
|
47
|
+
|
48
|
+
expect(rails_controller).to have_received(:redirect_to)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'passes the block to be executed' do
|
52
|
+
expect(subject.call(:redirect_to, &block)).to eq(12)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#run' do
|
58
|
+
context 'when block does not call any controller method' do
|
59
|
+
let(:block) { proc { 12 } }
|
60
|
+
|
61
|
+
it 'returns the value from the block' do
|
62
|
+
expect(controller.run(&block)).to eq(12)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when block references a value outside' do
|
67
|
+
let(:block) do
|
68
|
+
value = 15
|
69
|
+
proc { value }
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'returns the value' do
|
73
|
+
expect(controller.run(&block)).to eq(15)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'when block references a method in the controller' do
|
78
|
+
let(:block) { proc { params } }
|
79
|
+
|
80
|
+
it 'returns the value' do
|
81
|
+
expect(controller.run(&block))
|
82
|
+
.to eq(ActionController::Parameters.new(action: 'show'))
|
83
|
+
end
|
11
84
|
end
|
12
85
|
end
|
13
86
|
|
14
87
|
describe '#params' do
|
15
88
|
it 'returns the instance params call' do
|
16
|
-
expect(subject.params).to eq(action: 'show')
|
89
|
+
expect(subject.params).to eq(ActionController::Parameters.new(action: 'show'))
|
17
90
|
end
|
18
91
|
end
|
19
92
|
|
20
|
-
describe '#
|
93
|
+
describe '#method?' do
|
21
94
|
context 'when calling for a public method that exists' do
|
22
95
|
it do
|
23
|
-
expect(subject.
|
96
|
+
expect(subject.method?(:parse_request)).to be_truthy
|
24
97
|
end
|
25
98
|
end
|
26
99
|
|
27
100
|
context 'when calling for a private method that exists' do
|
28
101
|
it do
|
29
|
-
expect(subject.
|
102
|
+
expect(subject.method?(:redirection_path)).to be_truthy
|
30
103
|
end
|
31
104
|
end
|
32
105
|
|
33
106
|
context 'when calling for a non existing method' do
|
34
107
|
it do
|
35
|
-
expect(subject.
|
108
|
+
expect(subject.method?(:non_existing)).to be_falsey
|
36
109
|
end
|
37
110
|
end
|
38
111
|
end
|
@@ -1,14 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe Tarquinn::
|
5
|
+
describe Tarquinn::RedirectionHandler do
|
4
6
|
let(:redirection_path) { '/path' }
|
5
7
|
let(:controller) { Tarquinn::DummyController.new }
|
6
|
-
let(:config) { Tarquinn::
|
8
|
+
let(:config) { Tarquinn::RedirectionConfig.new(:redirection_path) }
|
7
9
|
let(:subject) do
|
8
10
|
described_class.new config, Tarquinn::Controller.new(controller)
|
9
11
|
end
|
10
12
|
|
11
13
|
describe '#perform_redirect?' do
|
14
|
+
context 'when there are no rules' do
|
15
|
+
it do
|
16
|
+
expect(subject.perform_redirect?).to be_truthy
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'but some grant a skip' do
|
20
|
+
before do
|
21
|
+
config.add_skip_rules { true }
|
22
|
+
end
|
23
|
+
|
24
|
+
it do
|
25
|
+
expect(subject.perform_redirect?).to be_falsey
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
12
30
|
context 'when rules allow for redirection' do
|
13
31
|
before do
|
14
32
|
config.add_redirection_rules { true }
|
@@ -98,7 +116,7 @@ describe Tarquinn::Handler do
|
|
98
116
|
end
|
99
117
|
|
100
118
|
context 'when configured with a method that does not exist in the controller' do
|
101
|
-
let(:config) { Tarquinn::
|
119
|
+
let(:config) { Tarquinn::RedirectionConfig.new('/new_path') }
|
102
120
|
|
103
121
|
it 'calls for redirection using static path' do
|
104
122
|
expect(controller).to receive(:redirect_to).with('/new_path')
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Tarquinn::RequestHandlerBuilder do
|
6
|
+
describe '#build' do
|
7
|
+
let(:controller) do
|
8
|
+
double('controller')
|
9
|
+
end
|
10
|
+
|
11
|
+
it do
|
12
|
+
expect(subject.build(controller)).to be_a(Tarquinn::RequestHandler)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe Tarquinn::
|
5
|
+
describe Tarquinn::RequestHandler do
|
4
6
|
let(:redirection_path) { '/path' }
|
5
7
|
let(:redirection_path2) { '/path2' }
|
6
8
|
let(:controller) do
|
7
9
|
double('controller', redirect_path: redirection_path, redirect_path2: redirection_path2)
|
8
10
|
end
|
9
|
-
let(:config) { Tarquinn::
|
10
|
-
let(:config2) { Tarquinn::
|
11
|
+
let(:config) { Tarquinn::RedirectionConfig.new(:redirect_path) }
|
12
|
+
let(:config2) { Tarquinn::RedirectionConfig.new(:redirect_path2) }
|
11
13
|
let(:configs) { { redirect_path: config, redirect_path2: config2 } }
|
12
14
|
let(:subject) do
|
13
15
|
described_class.new configs, Tarquinn::Controller.new(controller)
|
data/spec/lib/tarquinn_spec.rb
CHANGED
@@ -1,24 +1,187 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe Tarquinn do
|
4
|
-
|
5
|
+
describe Tarquinn, type: :controller do
|
6
|
+
describe '.redirection_rule' do
|
7
|
+
context 'when there is only one condition' do
|
8
|
+
controller(Tarquinn::DummyRouteController) do
|
9
|
+
redirection_rule :redirection, :should_redirect?
|
10
|
+
end
|
11
|
+
|
12
|
+
before { get :index, params: parameters }
|
13
|
+
|
14
|
+
context 'when request indicates a redirection' do
|
15
|
+
let(:parameters) { { should_redirect: true } }
|
16
|
+
|
17
|
+
it 'performs a redirect' do
|
18
|
+
expect(response).to redirect_to('/path')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'when request does not indicate a redirection' do
|
23
|
+
let(:parameters) { {} }
|
24
|
+
|
25
|
+
it 'does not performs a redirect' do
|
26
|
+
expect(response).not_to redirect_to('/path')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# TODO: fix this condition
|
32
|
+
context 'when there is only one block condition' do
|
33
|
+
controller(Tarquinn::DummyRouteController) do
|
34
|
+
redirection_rule :redirection do
|
35
|
+
params[:redirect_block]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
before { get :index, params: parameters }
|
40
|
+
|
41
|
+
context 'when request indicates a redirection' do
|
42
|
+
let(:parameters) { { redirect_block: true } }
|
43
|
+
|
44
|
+
it 'performs a redirect' do
|
45
|
+
expect(response).to redirect_to('/path')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when request does not indicate a redirection' do
|
50
|
+
let(:parameters) { {} }
|
5
51
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
expect(controller).to receive(:redirect_to).with('/path')
|
10
|
-
controller.parse_request
|
52
|
+
it 'does not performs a redirect' do
|
53
|
+
expect(response).not_to redirect_to('/path')
|
54
|
+
end
|
11
55
|
end
|
12
56
|
end
|
13
57
|
|
14
|
-
context 'when
|
15
|
-
|
16
|
-
|
58
|
+
context 'when there are more conditions' do
|
59
|
+
controller(Tarquinn::DummyRouteController) do
|
60
|
+
redirection_rule :redirection, :should_redirect?, :condition2
|
17
61
|
end
|
18
62
|
|
19
|
-
|
20
|
-
|
21
|
-
|
63
|
+
before { get :index, params: parameters }
|
64
|
+
|
65
|
+
context 'when request indicates a redirection through first condition' do
|
66
|
+
let(:parameters) { { should_redirect: true } }
|
67
|
+
|
68
|
+
it 'performs a redirect' do
|
69
|
+
expect(response).to redirect_to('/path')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when request indicates a redirection through second condition' do
|
74
|
+
let(:parameters) { { redirect: true } }
|
75
|
+
|
76
|
+
it 'performs a redirect' do
|
77
|
+
expect(response).to redirect_to('/path')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when request does not indicate a redirection' do
|
82
|
+
let(:parameters) { {} }
|
83
|
+
|
84
|
+
it 'does not performs a redirect' do
|
85
|
+
expect(response).not_to redirect_to('/path')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# TODO: fix this condition
|
91
|
+
context 'when there are no conditions' do
|
92
|
+
controller(Tarquinn::DummyRouteController) do
|
93
|
+
redirection_rule :redirection
|
94
|
+
end
|
95
|
+
|
96
|
+
before { get :index }
|
97
|
+
|
98
|
+
it 'performs a redirect' do
|
99
|
+
expect(response).to redirect_to('/path')
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '.skip_redirection' do
|
105
|
+
context 'when there is only one skip condition' do
|
106
|
+
controller(Tarquinn::DummyRouteController) do
|
107
|
+
redirection_rule :redirection, :always_redirect
|
108
|
+
skip_redirection_rule :redirection, :should_skip?
|
109
|
+
end
|
110
|
+
|
111
|
+
before { get :index, params: parameters }
|
112
|
+
|
113
|
+
context 'when requesting with parameters that do not skip' do
|
114
|
+
let(:parameters) { {} }
|
115
|
+
|
116
|
+
it 'performs a redirect' do
|
117
|
+
expect(response).to redirect_to('/path')
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'when request does not indicate a redirection' do
|
122
|
+
let(:parameters) { { should_skip: true } }
|
123
|
+
|
124
|
+
it 'does not performs a redirect' do
|
125
|
+
expect(response).not_to redirect_to('/path')
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'when there are more than oneskip condition' do
|
131
|
+
controller(Tarquinn::DummyRouteController) do
|
132
|
+
redirection_rule :redirection, :always_redirect
|
133
|
+
skip_redirection_rule :redirection, :should_skip?, :do_skip?
|
134
|
+
end
|
135
|
+
|
136
|
+
before { get :index, params: parameters }
|
137
|
+
|
138
|
+
context 'when requesting with parameters that do not skip' do
|
139
|
+
let(:parameters) { {} }
|
140
|
+
|
141
|
+
it 'performs a redirect' do
|
142
|
+
expect(response).to redirect_to('/path')
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'when request skips redirection using first condition' do
|
147
|
+
let(:parameters) { { should_skip: true } }
|
148
|
+
|
149
|
+
it 'does not performs a redirect' do
|
150
|
+
expect(response).not_to redirect_to('/path')
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'when request skips redirection using second condition' do
|
155
|
+
let(:parameters) { { skip: true } }
|
156
|
+
|
157
|
+
it 'does not performs a redirect' do
|
158
|
+
expect(response).not_to redirect_to('/path')
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe '.skip_redirection_rule' do
|
165
|
+
controller(Tarquinn::DummyRouteController) do
|
166
|
+
redirection_rule :redirection, :always_redirect
|
167
|
+
skip_redirection :redirection, :index, :delete
|
168
|
+
end
|
169
|
+
|
170
|
+
before { get action }
|
171
|
+
|
172
|
+
context 'when requestin a path that redirects' do
|
173
|
+
let(:action) { :new }
|
174
|
+
|
175
|
+
it 'performs a redirect' do
|
176
|
+
expect(response).to redirect_to('/path')
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
context 'when request does not indicate a redirection' do
|
181
|
+
let(:action) { :index }
|
182
|
+
|
183
|
+
it 'does not performs a redirect' do
|
184
|
+
expect(response).not_to redirect_to('/path')
|
22
185
|
end
|
23
186
|
end
|
24
187
|
end
|