tarquinn 0.4.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +22 -8
- data/.claude/agents/architect.md +45 -0
- data/.claude/agents/ruby.md +39 -0
- data/.claude/scripts/check_ruby.sh +8 -0
- data/.github/commit_message_template-2.0.md +32 -0
- data/.github/commit_message_template.md +10 -0
- data/.github/copilot-instructions.md +1 -188
- data/.github/pull_request_template.md +17 -0
- data/.github/tarquinn-usage.md +152 -0
- data/.gitignore +1 -0
- data/AGENTS.md +221 -0
- data/CLAUDE.md +1 -0
- data/Dockerfile +2 -2
- data/Gemfile +13 -12
- data/README.md +34 -6
- data/docs/agents/arcanum-split-issue.md +9 -0
- data/docs/agents/architecture.md +20 -0
- data/docs/agents/contributing.md +150 -0
- data/docs/agents/flow.md +5 -0
- data/docs/agents/folder-structure.md +14 -0
- data/docs/agents/issue-enhancement.md +10 -0
- data/docs/agents/issues/.gitkeep +1 -0
- data/docs/agents/plans/.gitkeep +1 -0
- data/lib/tarquinn/class_methods.rb +3 -3
- data/lib/tarquinn/controller.rb +17 -0
- data/lib/tarquinn/redirection_config/options.rb +6 -27
- data/lib/tarquinn/redirection_config.rb +4 -20
- data/lib/tarquinn/redirection_handler.rb +49 -31
- data/lib/tarquinn/version.rb +1 -1
- data/scripts/bump_version.sh +62 -0
- data/spec/dummy/app/controllers/tarquinn/dummy_controller.rb +6 -2
- data/spec/dummy/app/controllers/tarquinn/dummy_route_controller.rb +1 -1
- data/spec/dummy/config/initializers/content_security_policy.rb +1 -0
- data/spec/dummy/config/initializers/inflections.rb +1 -0
- data/spec/dummy/config/initializers/permissions_policy.rb +1 -0
- data/spec/lib/tarquinn/condition/method_caller_spec.rb +5 -5
- data/spec/lib/tarquinn/controller_spec.rb +20 -0
- data/spec/lib/tarquinn/redirection_config/options_spec.rb +10 -24
- data/spec/lib/tarquinn/redirection_handler_spec.rb +40 -5
- data/spec/lib/tarquinn_spec.rb +33 -3
- data/spec/spec_helper.rb +6 -0
- data/tarquinn.gemspec +2 -2
- metadata +27 -12
|
@@ -76,16 +76,7 @@ module Tarquinn
|
|
|
76
76
|
@skip_blocks ||= []
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
-
delegate :
|
|
80
|
-
|
|
81
|
-
# @method redirection_options
|
|
82
|
-
# @api private
|
|
83
|
-
# @private
|
|
84
|
-
#
|
|
85
|
-
# Options to be passed for the controller on redirect_to
|
|
86
|
-
#
|
|
87
|
-
# @return [Hash] the options for the redirection
|
|
88
|
-
# @see Tarquinn::RedirectionConfig::Options#redirection_options
|
|
79
|
+
delegate :domain, to: :options
|
|
89
80
|
|
|
90
81
|
# @method domain
|
|
91
82
|
# @api private
|
|
@@ -96,18 +87,11 @@ module Tarquinn
|
|
|
96
87
|
# if not set, the redirection be for the same host
|
|
97
88
|
# and not allowed for external hosts.
|
|
98
89
|
# if set, the redirection will be allowed for external
|
|
99
|
-
# hosts and the domain will be used for validation
|
|
100
|
-
#
|
|
90
|
+
# hosts and the domain will be used for validation.
|
|
91
|
+
# A Symbol value is resolved at runtime via the controller method.
|
|
92
|
+
# @return [String, Symbol, nil] the domain for cross-domain redirection
|
|
101
93
|
# @see Tarquinn::RedirectionConfig::Options#domain
|
|
102
94
|
|
|
103
|
-
# @method domain?
|
|
104
|
-
# @api private
|
|
105
|
-
# @private
|
|
106
|
-
# Checks if the domain option is set
|
|
107
|
-
# @return [TrueClass] when the domain option is set
|
|
108
|
-
# @return [FalseClass] when the domain option is not set
|
|
109
|
-
# @see Tarquinn::RedirectionConfig::Options#domain?
|
|
110
|
-
|
|
111
95
|
private
|
|
112
96
|
|
|
113
97
|
# @api private
|
|
@@ -33,14 +33,12 @@ module Tarquinn
|
|
|
33
33
|
controller.call(:redirect_to, redirect_full_path, **redirection_options)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
# @
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
# @return (see Tarquinn::RedirectionConfig::Options#redirection_options)
|
|
43
|
-
# @see Tarquinn::RedirectionConfig::Options#redirection_options
|
|
36
|
+
# Options to be passed for the controller on redirect_to
|
|
37
|
+
#
|
|
38
|
+
# @return [Hash] the options for the redirection
|
|
39
|
+
def redirection_options
|
|
40
|
+
{ allow_other_host: }.compact
|
|
41
|
+
end
|
|
44
42
|
|
|
45
43
|
private
|
|
46
44
|
|
|
@@ -68,42 +66,64 @@ module Tarquinn
|
|
|
68
66
|
# @return [Boolean]
|
|
69
67
|
attr_reader :perform_redirect
|
|
70
68
|
|
|
71
|
-
delegate :redirection_blocks, :
|
|
69
|
+
delegate :redirection_blocks, :skip_blocks, to: :config
|
|
70
|
+
delegate :domain, to: :config, prefix: true
|
|
71
|
+
|
|
72
|
+
# @method config_domain
|
|
73
|
+
# @api private
|
|
74
|
+
# @private
|
|
75
|
+
# The configured domain for cross-domain redirection
|
|
76
|
+
# @return [String, Symbol, nil] the configured domain for cross-domain redirection
|
|
72
77
|
|
|
73
78
|
# @method redirection_blocks
|
|
74
79
|
# @api private
|
|
75
80
|
# @private
|
|
76
|
-
#
|
|
81
|
+
# All blocks that indicate a redirection
|
|
77
82
|
# @return [Array<Tarquinn::Condition>] all blocks that indicate a redirection
|
|
78
|
-
# @see Tarquinn::RedirectionConfig::Options#redirection_options
|
|
79
83
|
|
|
80
|
-
# @method
|
|
84
|
+
# @method skip_blocks
|
|
85
|
+
# @api private
|
|
86
|
+
# @private
|
|
87
|
+
# All blocks that indicate a redirection should be skipped
|
|
88
|
+
# @return (see Tarquinn::RedirectionConfig#skip_blocks)
|
|
89
|
+
# @see Tarquinn::RedirectionConfig#skip_blocks
|
|
90
|
+
|
|
81
91
|
# @api private
|
|
82
92
|
# @private
|
|
83
93
|
#
|
|
84
|
-
#
|
|
94
|
+
# Resolves the domain for cross-domain redirection
|
|
85
95
|
#
|
|
86
|
-
#
|
|
87
|
-
# and
|
|
88
|
-
#
|
|
89
|
-
#
|
|
90
|
-
#
|
|
91
|
-
#
|
|
96
|
+
# When the configured domain is a Symbol and the controller responds to
|
|
97
|
+
# that method, the method is called and its return value is used.
|
|
98
|
+
# Otherwise, the configured value is returned as-is (a String is used
|
|
99
|
+
# directly; a Symbol that the controller does not respond to is converted
|
|
100
|
+
# to a String via `#to_s`).
|
|
101
|
+
#
|
|
102
|
+
# @return [String, nil] the resolved domain
|
|
103
|
+
def domain
|
|
104
|
+
controller.resolve_callable(config_domain).to_s.presence
|
|
105
|
+
end
|
|
92
106
|
|
|
93
|
-
# @method domain?
|
|
94
107
|
# @api private
|
|
95
108
|
# @private
|
|
96
|
-
#
|
|
97
|
-
#
|
|
98
|
-
#
|
|
99
|
-
# @
|
|
109
|
+
#
|
|
110
|
+
# Checks if the resolved domain is set
|
|
111
|
+
#
|
|
112
|
+
# @return [TrueClass] when the domain is set
|
|
113
|
+
# @return [FalseClass] when the domain is not set
|
|
114
|
+
def domain?
|
|
115
|
+
domain.present?
|
|
116
|
+
end
|
|
100
117
|
|
|
101
|
-
# @method skip_blocks
|
|
102
118
|
# @api private
|
|
103
119
|
# @private
|
|
104
|
-
#
|
|
105
|
-
#
|
|
106
|
-
#
|
|
120
|
+
#
|
|
121
|
+
# Returns the value of the allow_other_host option
|
|
122
|
+
#
|
|
123
|
+
# @return [TrueClass, nil] the value of the allow_other_host option
|
|
124
|
+
def allow_other_host
|
|
125
|
+
domain? || nil
|
|
126
|
+
end
|
|
107
127
|
|
|
108
128
|
# @api private
|
|
109
129
|
# @private
|
|
@@ -134,9 +154,7 @@ module Tarquinn
|
|
|
134
154
|
#
|
|
135
155
|
# @return [String]
|
|
136
156
|
def redirect_path
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
controller.call redirect_method
|
|
157
|
+
controller.resolve_callable(redirect_method)
|
|
140
158
|
end
|
|
141
159
|
|
|
142
160
|
# @api private
|
data/lib/tarquinn/version.rb
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Usage: scripts/bump_version.sh [major|minor|patch|X.Y.Z]
|
|
3
|
+
# Without arguments, bumps the patch version of the current version.
|
|
4
|
+
|
|
5
|
+
set -euo pipefail
|
|
6
|
+
|
|
7
|
+
ROOT="$(git rev-parse --show-toplevel)"
|
|
8
|
+
README="$ROOT/README.md"
|
|
9
|
+
VERSION_FILE="$ROOT/lib/tarquinn/version.rb"
|
|
10
|
+
LOCKFILE="$ROOT/Gemfile.lock"
|
|
11
|
+
GEM="tarquinn"
|
|
12
|
+
|
|
13
|
+
current=$(grep -oE "VERSION = '[0-9]+\.[0-9]+\.[0-9]+'" "$VERSION_FILE" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
|
|
14
|
+
IFS='.' read -r cmajor cminor cpatch <<< "$current"
|
|
15
|
+
|
|
16
|
+
arg="${1:-patch}"
|
|
17
|
+
|
|
18
|
+
case "$arg" in
|
|
19
|
+
major) new_version="$((cmajor + 1)).0.0" ;;
|
|
20
|
+
minor) new_version="${cmajor}.$((cminor + 1)).0" ;;
|
|
21
|
+
patch) new_version="${cmajor}.${cminor}.$((cpatch + 1))" ;;
|
|
22
|
+
*) new_version="$arg" ;;
|
|
23
|
+
esac
|
|
24
|
+
|
|
25
|
+
# Validate semver format
|
|
26
|
+
if ! echo "$new_version" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
|
|
27
|
+
echo "Error: version must be major, minor, patch or X.Y.Z" >&2
|
|
28
|
+
exit 1
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
# Next release: following minor
|
|
32
|
+
IFS='.' read -r major minor _patch <<< "$new_version"
|
|
33
|
+
next_release="${major}.$((minor + 1)).0"
|
|
34
|
+
|
|
35
|
+
echo "Current version: $current"
|
|
36
|
+
echo "New version: $new_version"
|
|
37
|
+
echo "Next release: $next_release"
|
|
38
|
+
|
|
39
|
+
# version.rb
|
|
40
|
+
sed -i '' "s|VERSION = '[0-9.]*'|VERSION = '${new_version}'|" "$VERSION_FILE"
|
|
41
|
+
|
|
42
|
+
# README: YARD docs link
|
|
43
|
+
sed -i '' \
|
|
44
|
+
"s|rubydoc.info/gems/${GEM}/[0-9.]*|rubydoc.info/gems/${GEM}/${new_version}|g" \
|
|
45
|
+
"$README"
|
|
46
|
+
|
|
47
|
+
# README: Current Release line
|
|
48
|
+
sed -i '' \
|
|
49
|
+
"s|\*\*Current Release\*\*: \[[0-9.]*\](https://github.com/darthjee/tarquinn/tree/[0-9.]*)|**Current Release**: [${new_version}](https://github.com/darthjee/tarquinn/tree/${new_version})|" \
|
|
50
|
+
"$README"
|
|
51
|
+
|
|
52
|
+
# README: Next release line
|
|
53
|
+
sed -i '' \
|
|
54
|
+
"s|\*\*Next release\*\*: \[[0-9.]*\](https://github.com/darthjee/tarquinn/compare/[0-9.]*\.\.\.main)|**Next release**: [${next_release}](https://github.com/darthjee/tarquinn/compare/${new_version}...main)|" \
|
|
55
|
+
"$README"
|
|
56
|
+
|
|
57
|
+
# Gemfile.lock
|
|
58
|
+
if [ -f "$LOCKFILE" ]; then
|
|
59
|
+
sed -i '' "s|^\( *${GEM} (\)[0-9.]*)|\1${new_version})|" "$LOCKFILE"
|
|
60
|
+
fi
|
|
61
|
+
|
|
62
|
+
echo "Done."
|
|
@@ -18,11 +18,11 @@ module Tarquinn
|
|
|
18
18
|
ActionController::Parameters.new({ action: 'show' })
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def true
|
|
21
|
+
def true?
|
|
22
22
|
true
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
def false
|
|
25
|
+
def false?
|
|
26
26
|
false
|
|
27
27
|
end
|
|
28
28
|
|
|
@@ -39,5 +39,9 @@ module Tarquinn
|
|
|
39
39
|
def should_skip_redirect?
|
|
40
40
|
false
|
|
41
41
|
end
|
|
42
|
+
|
|
43
|
+
def dynamic_domain
|
|
44
|
+
'dynamic.example.com'
|
|
45
|
+
end
|
|
42
46
|
end
|
|
43
47
|
end
|
|
@@ -7,7 +7,7 @@ describe Tarquinn::Condition::MethodCaller do
|
|
|
7
7
|
let(:controller) { Tarquinn::Controller.new(dummy_controller) }
|
|
8
8
|
|
|
9
9
|
context 'when initialized with a single method' do
|
|
10
|
-
let(:method) { :true }
|
|
10
|
+
let(:method) { :true? }
|
|
11
11
|
let(:subject) { described_class.new(method) }
|
|
12
12
|
|
|
13
13
|
context 'when method returns true' do
|
|
@@ -17,7 +17,7 @@ describe Tarquinn::Condition::MethodCaller do
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
context 'when method returns true' do
|
|
20
|
-
let(:method) { :false }
|
|
20
|
+
let(:method) { :false? }
|
|
21
21
|
|
|
22
22
|
it do
|
|
23
23
|
expect(subject.check?(controller)).to be_falsey
|
|
@@ -26,7 +26,7 @@ describe Tarquinn::Condition::MethodCaller do
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
context 'when initialized with more methods' do
|
|
29
|
-
let(:methods) { %i[true false] }
|
|
29
|
+
let(:methods) { %i[true? false?] }
|
|
30
30
|
let(:subject) { described_class.new(methods) }
|
|
31
31
|
|
|
32
32
|
context 'when one return true and the other false' do
|
|
@@ -36,14 +36,14 @@ describe Tarquinn::Condition::MethodCaller do
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
context 'when all return true' do
|
|
39
|
-
let(:methods) { %i[true true] }
|
|
39
|
+
let(:methods) { %i[true? true?] }
|
|
40
40
|
it do
|
|
41
41
|
expect(subject.check?(controller)).to be_truthy
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
context 'when all return false' do
|
|
46
|
-
let(:methods) { %i[false false] }
|
|
46
|
+
let(:methods) { %i[false? false?] }
|
|
47
47
|
it do
|
|
48
48
|
expect(subject.check?(controller)).to be_falsey
|
|
49
49
|
end
|
|
@@ -109,4 +109,24 @@ describe Tarquinn::Controller do
|
|
|
109
109
|
end
|
|
110
110
|
end
|
|
111
111
|
end
|
|
112
|
+
|
|
113
|
+
describe '#resolve_callable' do
|
|
114
|
+
context 'when value is a symbol and method exists' do
|
|
115
|
+
it 'returns method call result' do
|
|
116
|
+
expect(subject.resolve_callable(:redirection_path)).to eq('/path')
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
context 'when value is a symbol and method does not exist' do
|
|
121
|
+
it 'returns the original symbol' do
|
|
122
|
+
expect(subject.resolve_callable(:non_existing)).to eq(:non_existing)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
context 'when value is not a symbol' do
|
|
127
|
+
it 'returns the original value' do
|
|
128
|
+
expect(subject.resolve_callable('redirection_path')).to eq('redirection_path')
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
112
132
|
end
|
|
@@ -3,42 +3,28 @@
|
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
|
|
5
5
|
RSpec.describe Tarquinn::RedirectionConfig::Options do
|
|
6
|
-
describe '#
|
|
7
|
-
subject(:redirection_options) { options.redirection_options }
|
|
8
|
-
|
|
6
|
+
describe '#domain' do
|
|
9
7
|
context 'when domain is not set' do
|
|
10
8
|
subject(:options) { described_class.new }
|
|
11
9
|
|
|
12
|
-
it 'returns
|
|
13
|
-
expect(
|
|
10
|
+
it 'returns nil' do
|
|
11
|
+
expect(options.domain).to be_nil
|
|
14
12
|
end
|
|
15
13
|
end
|
|
16
14
|
|
|
17
|
-
context 'when domain is set' do
|
|
15
|
+
context 'when domain is set to a string' do
|
|
18
16
|
subject(:options) { described_class.new(domain: 'example.com') }
|
|
19
17
|
|
|
20
|
-
it 'returns
|
|
21
|
-
expect(
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
describe '#domain?' do
|
|
27
|
-
subject(:options) { described_class.new(domain: domain_value) }
|
|
28
|
-
|
|
29
|
-
context 'when domain is not set' do
|
|
30
|
-
let(:domain_value) { nil }
|
|
31
|
-
|
|
32
|
-
it 'returns false' do
|
|
33
|
-
expect(options.domain?).to be false
|
|
18
|
+
it 'returns the configured string' do
|
|
19
|
+
expect(options.domain).to eq('example.com')
|
|
34
20
|
end
|
|
35
21
|
end
|
|
36
22
|
|
|
37
|
-
context 'when domain is set' do
|
|
38
|
-
|
|
23
|
+
context 'when domain is set to a symbol' do
|
|
24
|
+
subject(:options) { described_class.new(domain: :some_domain_method) }
|
|
39
25
|
|
|
40
|
-
it 'returns
|
|
41
|
-
expect(options.domain
|
|
26
|
+
it 'returns the configured symbol' do
|
|
27
|
+
expect(options.domain).to eq(:some_domain_method)
|
|
42
28
|
end
|
|
43
29
|
end
|
|
44
30
|
end
|
|
@@ -70,7 +70,7 @@ describe Tarquinn::RedirectionHandler do
|
|
|
70
70
|
context 'when passing a method name for evaluation' do
|
|
71
71
|
context 'when method returns true' do
|
|
72
72
|
before do
|
|
73
|
-
config.add_redirection_rules :true
|
|
73
|
+
config.add_redirection_rules :true?
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
it do
|
|
@@ -79,7 +79,7 @@ describe Tarquinn::RedirectionHandler do
|
|
|
79
79
|
|
|
80
80
|
context 'but some grant a skip' do
|
|
81
81
|
before do
|
|
82
|
-
config.add_skip_rules :true
|
|
82
|
+
config.add_skip_rules :true?
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
it do
|
|
@@ -90,7 +90,7 @@ describe Tarquinn::RedirectionHandler do
|
|
|
90
90
|
|
|
91
91
|
context 'when method returns false' do
|
|
92
92
|
before do
|
|
93
|
-
config.add_redirection_rules :false
|
|
93
|
+
config.add_redirection_rules :false?
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
it do
|
|
@@ -99,7 +99,7 @@ describe Tarquinn::RedirectionHandler do
|
|
|
99
99
|
|
|
100
100
|
context 'but some do not grant a skip' do
|
|
101
101
|
before do
|
|
102
|
-
config.add_skip_rules :false
|
|
102
|
+
config.add_skip_rules :false?
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
it do
|
|
@@ -138,8 +138,43 @@ describe Tarquinn::RedirectionHandler do
|
|
|
138
138
|
)
|
|
139
139
|
end
|
|
140
140
|
|
|
141
|
-
it 'calls for redirection using full path' do
|
|
141
|
+
it 'calls for redirection using full path with allow_other_host' do
|
|
142
142
|
subject.redirect
|
|
143
|
+
|
|
144
|
+
expect(controller).to have_received(:redirect_to)
|
|
145
|
+
.with('example.com/path', allow_other_host: true)
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
context 'when configured with a symbol domain that the controller responds to' do
|
|
150
|
+
let(:config) do
|
|
151
|
+
Tarquinn::RedirectionConfig.new(
|
|
152
|
+
redirection: :redirection_path,
|
|
153
|
+
domain: :dynamic_domain
|
|
154
|
+
)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
it 'resolves the domain by calling the controller method' do
|
|
158
|
+
subject.redirect
|
|
159
|
+
|
|
160
|
+
expect(controller).to have_received(:redirect_to)
|
|
161
|
+
.with('dynamic.example.com/path', allow_other_host: true)
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
context 'when configured with a symbol domain that the controller does not respond to' do
|
|
166
|
+
let(:config) do
|
|
167
|
+
Tarquinn::RedirectionConfig.new(
|
|
168
|
+
redirection: :redirection_path,
|
|
169
|
+
domain: :unknown_domain_method
|
|
170
|
+
)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it 'treats the symbol as a static domain string' do
|
|
174
|
+
subject.redirect
|
|
175
|
+
|
|
176
|
+
expect(controller).to have_received(:redirect_to)
|
|
177
|
+
.with('unknown_domain_method/path', allow_other_host: true)
|
|
143
178
|
end
|
|
144
179
|
end
|
|
145
180
|
end
|
data/spec/lib/tarquinn_spec.rb
CHANGED
|
@@ -125,12 +125,42 @@ describe Tarquinn, type: :controller do
|
|
|
125
125
|
end
|
|
126
126
|
end
|
|
127
127
|
end
|
|
128
|
+
|
|
129
|
+
context 'when passing domain option as a symbol' do
|
|
130
|
+
controller(Tarquinn::DummyRouteController) do
|
|
131
|
+
redirection_rule :redirection, domain: :dynamic_domain do
|
|
132
|
+
params[:should_redirect]
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def dynamic_domain
|
|
136
|
+
'dynamic.example.com'
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
before { get :index, params: parameters }
|
|
141
|
+
|
|
142
|
+
context 'when request indicates a redirection' do
|
|
143
|
+
let(:parameters) { { should_redirect: true } }
|
|
144
|
+
|
|
145
|
+
it 'performs a redirect using the value returned by the domain method' do
|
|
146
|
+
expect(response).to redirect_to('dynamic.example.com/path')
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
context 'when request does not indicate a redirection' do
|
|
151
|
+
let(:parameters) { {} }
|
|
152
|
+
|
|
153
|
+
it 'does not perform a redirect' do
|
|
154
|
+
expect(response).not_to redirect_to('/path')
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
128
158
|
end
|
|
129
159
|
|
|
130
160
|
describe '.skip_redirection' do
|
|
131
161
|
context 'when there is only one skip condition' do
|
|
132
162
|
controller(Tarquinn::DummyRouteController) do
|
|
133
|
-
redirection_rule :redirection, :always_redirect
|
|
163
|
+
redirection_rule :redirection, :always_redirect?
|
|
134
164
|
skip_redirection_rule :redirection, :should_skip?
|
|
135
165
|
end
|
|
136
166
|
|
|
@@ -155,7 +185,7 @@ describe Tarquinn, type: :controller do
|
|
|
155
185
|
|
|
156
186
|
context 'when there are more than oneskip condition' do
|
|
157
187
|
controller(Tarquinn::DummyRouteController) do
|
|
158
|
-
redirection_rule :redirection, :always_redirect
|
|
188
|
+
redirection_rule :redirection, :always_redirect?
|
|
159
189
|
skip_redirection_rule :redirection, :should_skip?, :do_skip?
|
|
160
190
|
end
|
|
161
191
|
|
|
@@ -189,7 +219,7 @@ describe Tarquinn, type: :controller do
|
|
|
189
219
|
|
|
190
220
|
describe '.skip_redirection_rule' do
|
|
191
221
|
controller(Tarquinn::DummyRouteController) do
|
|
192
|
-
redirection_rule :redirection, :always_redirect
|
|
222
|
+
redirection_rule :redirection, :always_redirect?
|
|
193
223
|
skip_redirection :redirection, :index, :delete
|
|
194
224
|
end
|
|
195
225
|
|
data/spec/spec_helper.rb
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
require 'simplecov'
|
|
4
4
|
|
|
5
|
+
if ENV['CI']
|
|
6
|
+
require 'simplecov-lcov'
|
|
7
|
+
SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
|
|
8
|
+
SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
|
|
9
|
+
end
|
|
10
|
+
|
|
5
11
|
SimpleCov.start do
|
|
6
12
|
add_filter '/spec/'
|
|
7
13
|
end
|
data/tarquinn.gemspec
CHANGED
|
@@ -18,8 +18,8 @@ Gem::Specification.new do |gem|
|
|
|
18
18
|
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
19
19
|
gem.require_paths = ['lib']
|
|
20
20
|
|
|
21
|
-
gem.add_dependency 'activesupport'
|
|
22
|
-
gem.add_dependency 'sinclair',
|
|
21
|
+
gem.add_dependency 'activesupport', '~> 7.2.x'
|
|
22
|
+
gem.add_dependency 'sinclair', '>= 3.2.0'
|
|
23
23
|
|
|
24
24
|
gem.metadata['rubygems_mfa_required'] = 'true'
|
|
25
25
|
end
|