tarquinn 0.4.0 → 0.5.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 +3 -0
- data/Gemfile +13 -12
- data/README.md +34 -6
- 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/spec/dummy/app/controllers/tarquinn/dummy_controller.rb +4 -0
- 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 +36 -1
- data/spec/lib/tarquinn_spec.rb +30 -0
- data/spec/spec_helper.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bedf2c09afd835b6b2b70a2f83a6f3e81c15822105b27a50f482bb81fbdd9d89
|
|
4
|
+
data.tar.gz: 7592837ef041e0b83e9ffa5cec438859cf7be9cc6c9d16819a50d6242d1ae27b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 998e736f046dee05cd716719d7bd6dd212840c3c6d4caaddf4178e3027ce9962a3ce9fc5ac4c9a480f0df8ebc7ac4c4dd689c58151ddf268f01ad1468b33fb19
|
|
7
|
+
data.tar.gz: 5175105a808ef43c98a54fc9b0a4e8831bef7bbe561b99db04f1a746bda0480cd871720173b61cf59505a47bc390b9567e655e2a2dccf7cac1d0e56dca1a2544
|
data/.circleci/config.yml
CHANGED
|
@@ -33,6 +33,9 @@ jobs:
|
|
|
33
33
|
- run:
|
|
34
34
|
name: RSpec
|
|
35
35
|
command: bundle exec rspec
|
|
36
|
+
- run:
|
|
37
|
+
name: Upload coverage to Codacy
|
|
38
|
+
command: bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r coverage/lcov/project.lcov
|
|
36
39
|
checks:
|
|
37
40
|
docker:
|
|
38
41
|
- image: darthjee/circleci_ruby_331:1.0.1
|
data/Gemfile
CHANGED
|
@@ -2,17 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
source 'https://rubygems.org'
|
|
4
4
|
|
|
5
|
-
gem 'bundler',
|
|
6
|
-
gem 'pry',
|
|
7
|
-
gem 'pry-nav',
|
|
8
|
-
gem 'rails',
|
|
9
|
-
gem 'rake',
|
|
10
|
-
gem 'rspec',
|
|
11
|
-
gem 'rspec-rails',
|
|
12
|
-
gem 'rubycritic',
|
|
13
|
-
gem 'simplecov',
|
|
14
|
-
gem '
|
|
15
|
-
gem '
|
|
16
|
-
gem '
|
|
5
|
+
gem 'bundler', '~> 2.5.13'
|
|
6
|
+
gem 'pry', '~> 0.14.2'
|
|
7
|
+
gem 'pry-nav', '~> 1.0.0'
|
|
8
|
+
gem 'rails', '7.2.3'
|
|
9
|
+
gem 'rake', '~> 13.1.0'
|
|
10
|
+
gem 'rspec', '~> 3.12.0'
|
|
11
|
+
gem 'rspec-rails', '6.1.1'
|
|
12
|
+
gem 'rubycritic', '4.9.1'
|
|
13
|
+
gem 'simplecov', '~> 0.22.0'
|
|
14
|
+
gem 'simplecov-lcov', '0.9.0'
|
|
15
|
+
gem 'sqlite3', '1.4.2'
|
|
16
|
+
gem 'yard', '0.9.38'
|
|
17
|
+
gem 'yardstick', '0.9.9'
|
|
17
18
|
|
|
18
19
|
gemspec
|
data/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
Tarquinn
|
|
2
2
|
========
|
|
3
3
|
[](https://circleci.com/gh/darthjee/tarquinn)
|
|
4
|
-
[](https://app.codacy.com/gh/darthjee/tarquinn/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
|
5
|
+
[](https://app.codacy.com/gh/darthjee/tarquinn/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
|
|
5
6
|
[](https://badge.fury.io/rb/tarquinn)
|
|
6
7
|
[](http://inch-ci.org/github/darthjee/tarquinn)
|
|
7
8
|
|
|
@@ -9,13 +10,13 @@ Tarquinn
|
|
|
9
10
|
|
|
10
11
|
Yard Documentation
|
|
11
12
|
-------------------
|
|
12
|
-
[https://www.rubydoc.info/gems/tarquinn/0.
|
|
13
|
+
[https://www.rubydoc.info/gems/tarquinn/0.5.0](https://www.rubydoc.info/gems/tarquinn/0.5.0)
|
|
13
14
|
|
|
14
15
|
This gem makes easier to controll generic redirection
|
|
15
16
|
|
|
16
|
-
Current Release: [0.
|
|
17
|
+
Current Release: [0.5.0](https://github.com/darthjee/tarquinn/tree/0.5.0)
|
|
17
18
|
|
|
18
|
-
Next Version [0.
|
|
19
|
+
Next Version [0.5.1](https://github.com/darthjee/tarquinn/compare/0.45.0...main)
|
|
19
20
|
|
|
20
21
|
Getting started
|
|
21
22
|
---------------
|
|
@@ -143,7 +144,9 @@ bundle exec rake verify_measurements
|
|
|
143
144
|
|
|
144
145
|
You can specify a `domain` option in your `redirection_rule` to allow cross-domain redirection. When set, the redirection will be allowed to external hosts and the specified domain will be used for validation.
|
|
145
146
|
|
|
146
|
-
**
|
|
147
|
+
The `domain:` option accepts either a **String** (static domain) or a **Symbol** (dynamic domain resolved at runtime by calling the named method on the controller).
|
|
148
|
+
|
|
149
|
+
**Static domain (String):**
|
|
147
150
|
|
|
148
151
|
```ruby
|
|
149
152
|
class ExternalRedirectController < ApplicationController
|
|
@@ -161,5 +164,30 @@ class ExternalRedirectController < ApplicationController
|
|
|
161
164
|
end
|
|
162
165
|
```
|
|
163
166
|
|
|
167
|
+
**Dynamic domain (Symbol):**
|
|
168
|
+
|
|
169
|
+
```ruby
|
|
170
|
+
class ExternalRedirectController < ApplicationController
|
|
171
|
+
include Tarquinn
|
|
172
|
+
|
|
173
|
+
redirection_rule :redirect_external, domain: :current_domain do
|
|
174
|
+
params[:should_redirect]
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
private
|
|
178
|
+
|
|
179
|
+
def redirect_external
|
|
180
|
+
'/external_path'
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def current_domain
|
|
184
|
+
# resolved at request time
|
|
185
|
+
request.subdomain == 'admin' ? 'admin.example.com' : 'example.com'
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
```
|
|
189
|
+
|
|
164
190
|
- If `domain` is not set, redirection is only allowed for the same host.
|
|
165
|
-
- If `domain` is
|
|
191
|
+
- If `domain` is a String, it is used directly as the domain prefix.
|
|
192
|
+
- If `domain` is a Symbol and the controller responds to that method, the method is called and its return value is used as the domain.
|
|
193
|
+
- If `domain` is a Symbol but the controller does not respond to it, the Symbol's string representation is used as the domain.
|
data/lib/tarquinn/controller.rb
CHANGED
|
@@ -52,6 +52,23 @@ module Tarquinn
|
|
|
52
52
|
controller.respond_to?(method, true)
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
+
# Resolves a value that may reference a controller method
|
|
56
|
+
#
|
|
57
|
+
# If the value is a Symbol and the controller responds to it, calls the
|
|
58
|
+
# method and returns its result. Otherwise, returns the original value.
|
|
59
|
+
#
|
|
60
|
+
# @overload resolve_callable(method_name)
|
|
61
|
+
# @param method_name [Symbol] method name
|
|
62
|
+
# @overload resolve_callable(value)
|
|
63
|
+
# @param value [String] value to be returned
|
|
64
|
+
#
|
|
65
|
+
# @return [Object] resolved method return or original value
|
|
66
|
+
def resolve_callable(value)
|
|
67
|
+
return value unless value.is_a?(Symbol) && method?(value)
|
|
68
|
+
|
|
69
|
+
call(value)
|
|
70
|
+
end
|
|
71
|
+
|
|
55
72
|
private
|
|
56
73
|
|
|
57
74
|
# @api private
|
|
@@ -19,40 +19,19 @@ module Tarquinn
|
|
|
19
19
|
# and not allowed for external hosts.
|
|
20
20
|
#
|
|
21
21
|
# if set, the redirection will be allowed for external
|
|
22
|
-
# hosts and the domain will be used for validation
|
|
22
|
+
# hosts and the domain will be used for validation.
|
|
23
|
+
# A Symbol value is resolved at runtime via the controller method.
|
|
23
24
|
#
|
|
24
|
-
# @return [String, nil] the domain for cross-domain redirection
|
|
25
|
+
# @return [String, Symbol, nil] the domain for cross-domain redirection
|
|
25
26
|
# @see RedirectionHandler#redirect
|
|
26
|
-
# @see #redirection_options
|
|
27
27
|
|
|
28
28
|
# @method initialize(domain: nil)
|
|
29
29
|
# @api private
|
|
30
30
|
# Initializes a new Options object
|
|
31
|
-
# @param domain [String, nil] the domain for cross-domain redirection
|
|
31
|
+
# @param domain [String, Symbol, nil] the domain for cross-domain redirection.
|
|
32
|
+
# A String is used as-is; a Symbol is resolved by calling the matching
|
|
33
|
+
# method on the controller at runtime (via {Tarquinn::RedirectionHandler}).
|
|
32
34
|
# @return [Tarquinn::RedirectionConfig::Options]
|
|
33
|
-
|
|
34
|
-
# Options to be passed for the controller on redirect_to
|
|
35
|
-
# @return [Hash] the options for the redirection
|
|
36
|
-
def redirection_options
|
|
37
|
-
{
|
|
38
|
-
allow_other_host:
|
|
39
|
-
}.compact
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# Checks if the domain option is set
|
|
43
|
-
# @return [TrueClass] when the domain option is set
|
|
44
|
-
# @return [FalseClass] when the domain option is not set
|
|
45
|
-
def domain?
|
|
46
|
-
domain.present?
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
private
|
|
50
|
-
|
|
51
|
-
# Returns the value of the allow_other_host option
|
|
52
|
-
# @return [TrueClass, nil] the value of the allow_other_host option
|
|
53
|
-
def allow_other_host
|
|
54
|
-
domain? || nil
|
|
55
|
-
end
|
|
56
35
|
end
|
|
57
36
|
end
|
|
58
37
|
end
|
|
@@ -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
|
@@ -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
|
|
@@ -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,6 +125,36 @@ 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
|
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
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tarquinn
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- DarthJee
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-03-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|