redirector 1.0.2 → 1.1.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/db/migrate/20120815212612_create_redirect_rules.rb +2 -2
- data/db/migrate/20120823163756_create_request_environment_rules.rb +2 -2
- data/lib/redirector/version.rb +1 -1
- data/redirector.gemspec +2 -2
- data/spec/dummy/config/application.rb +2 -2
- data/spec/factories/redirect_rules.rb +3 -3
- data/spec/factories/request_environment_rules.rb +3 -3
- data/spec/features/middleware_spec.rb +16 -13
- data/spec/models/redirect_rule_spec.rb +54 -49
- data/spec/models/request_environment_rule_spec.rb +29 -28
- data/spec/spec_helper.rb +21 -3
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63dab49a33d2664b3722c5240d71328cd50ec1ba
|
4
|
+
data.tar.gz: 7baceb65e027c70c8db19a9b62d8e598a3c27e32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 209ce7d1b98f706a3e44dd6262c732545b36b8e62fdde2e5261a0292b36105f71ee8d5fbc7f43d66ce7c8c1cac2a582ad82b7c97a26172492d1866531f2fdffe
|
7
|
+
data.tar.gz: 26d3ca13b233ea6e2882c6e2aaf5750cc1402d31cd74343cabe6dffb3d5a10e2a428340a46edf51eae594876038951f42beb2978fdad4353d6da0fca91e1e91f
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class CreateRedirectRules < ActiveRecord::Migration
|
1
|
+
class CreateRedirectRules < ActiveRecord::Migration[4.2]
|
2
2
|
def change
|
3
3
|
create_table :redirect_rules do |t|
|
4
4
|
t.string :source, :null => false
|
@@ -13,4 +13,4 @@ class CreateRedirectRules < ActiveRecord::Migration
|
|
13
13
|
add_index :redirect_rules, :source_is_regex
|
14
14
|
add_index :redirect_rules, :source_is_case_sensitive
|
15
15
|
end
|
16
|
-
end
|
16
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class CreateRequestEnvironmentRules < ActiveRecord::Migration
|
1
|
+
class CreateRequestEnvironmentRules < ActiveRecord::Migration[4.2]
|
2
2
|
def change
|
3
3
|
create_table :request_environment_rules do |t|
|
4
4
|
t.integer :redirect_rule_id, :null => false
|
@@ -10,4 +10,4 @@ class CreateRequestEnvironmentRules < ActiveRecord::Migration
|
|
10
10
|
end
|
11
11
|
add_index :request_environment_rules, :redirect_rule_id
|
12
12
|
end
|
13
|
-
end
|
13
|
+
end
|
data/lib/redirector/version.rb
CHANGED
data/redirector.gemspec
CHANGED
@@ -22,11 +22,11 @@ Gem::Specification.new do |s|
|
|
22
22
|
|
23
23
|
s.add_development_dependency "mysql2"
|
24
24
|
s.add_development_dependency "pg"
|
25
|
-
s.add_development_dependency 'rspec-rails', '~>
|
25
|
+
s.add_development_dependency 'rspec-rails', '~> 3.7'
|
26
26
|
s.add_development_dependency 'shoulda-matchers'
|
27
27
|
s.add_development_dependency 'capybara', '~> 2.2'
|
28
28
|
s.add_development_dependency 'database_cleaner'
|
29
|
-
s.add_development_dependency '
|
29
|
+
s.add_development_dependency 'factory_bot_rails', '~> 4.4'
|
30
30
|
s.add_development_dependency 'appraisal'
|
31
31
|
s.add_development_dependency 'rake'
|
32
32
|
s.add_development_dependency 'coveralls'
|
@@ -50,10 +50,10 @@ module Dummy
|
|
50
50
|
# config.active_record.whitelist_attributes = true
|
51
51
|
|
52
52
|
# Enable the asset pipeline
|
53
|
-
config.assets.enabled = true
|
53
|
+
# config.assets.enabled = true
|
54
54
|
|
55
55
|
# Version of your assets, change this if you want to expire all your assets
|
56
|
-
config.assets.version = '1.0'
|
56
|
+
# config.assets.version = '1.0'
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -1,12 +1,12 @@
|
|
1
|
-
# Read about factories at https://github.com/thoughtbot/
|
1
|
+
# Read about factories at https://github.com/thoughtbot/factory_bot
|
2
2
|
|
3
|
-
|
3
|
+
FactoryBot.define do
|
4
4
|
factory :redirect_rule do
|
5
5
|
active true
|
6
6
|
source_is_regex false
|
7
7
|
source '/catchy_thingy'
|
8
8
|
destination 'http://www.example.com/products/1'
|
9
|
-
|
9
|
+
|
10
10
|
factory :redirect_rule_regex do
|
11
11
|
source_is_regex true
|
12
12
|
source '[A-Za-z0-9_]+shiny\/([A-Za-z0-9_]+)'
|
@@ -1,11 +1,11 @@
|
|
1
|
-
# Read about factories at https://github.com/thoughtbot/
|
1
|
+
# Read about factories at https://github.com/thoughtbot/factory_bot
|
2
2
|
|
3
|
-
|
3
|
+
FactoryBot.define do
|
4
4
|
factory :request_environment_rule do
|
5
5
|
redirect_rule
|
6
6
|
environment_key_name "SERVER_NAME"
|
7
7
|
environment_value "example.com"
|
8
|
-
|
8
|
+
|
9
9
|
factory :request_environment_rule_regex do
|
10
10
|
environment_key_name "QUERY_STRING"
|
11
11
|
environment_value "something=value"
|
@@ -9,24 +9,24 @@ describe 'Redirector middleware', :type => :feature do
|
|
9
9
|
|
10
10
|
it 'correctly redirects the visitor for an exact match rule' do
|
11
11
|
visit '/my_custom_url'
|
12
|
-
current_path.
|
12
|
+
expect(current_path).to eq('/news/5')
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'correctly redirects the visitor for a regex match rule' do
|
16
16
|
visit '/my_custom_url/20'
|
17
|
-
current_path.
|
17
|
+
expect(current_path).to eq('/news/20')
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should not do the query string match if the Redirector.include_query_in_source is false' do
|
21
21
|
visit '/my_old_url?categoryID=12345'
|
22
|
-
current_path.
|
22
|
+
expect(current_path).to eq('/my_old_url')
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should do the query string match if the Redirector.include_query_in_source is true' do
|
26
26
|
original_option = Redirector.include_query_in_source
|
27
27
|
Redirector.include_query_in_source = true
|
28
28
|
visit '/my_old_url?categoryID=12345'
|
29
|
-
current_path.
|
29
|
+
expect(current_path).to eq('/news')
|
30
30
|
Redirector.include_query_in_source = original_option
|
31
31
|
end
|
32
32
|
|
@@ -35,8 +35,8 @@ describe 'Redirector middleware', :type => :feature do
|
|
35
35
|
Redirector.preserve_query = true
|
36
36
|
visit '/my_custom_url/20?categoryID=43257'
|
37
37
|
uri = URI.parse(current_url)
|
38
|
-
uri.query.
|
39
|
-
current_path.
|
38
|
+
expect(uri.query).to eq('categoryID=43257')
|
39
|
+
expect(current_path).to eq('/news/20')
|
40
40
|
Redirector.preserve_query = original_option
|
41
41
|
end
|
42
42
|
|
@@ -44,7 +44,7 @@ describe 'Redirector middleware', :type => :feature do
|
|
44
44
|
original_option = Redirector.silence_sql_logs
|
45
45
|
Redirector.silence_sql_logs = true
|
46
46
|
visit '/my_custom_url/20'
|
47
|
-
current_path.
|
47
|
+
expect(current_path).to eq('/news/20')
|
48
48
|
Redirector.preserve_query = original_option
|
49
49
|
end
|
50
50
|
|
@@ -52,12 +52,12 @@ describe 'Redirector middleware', :type => :feature do
|
|
52
52
|
Capybara.app_host = 'http://example.com'
|
53
53
|
|
54
54
|
visit '/my_custom_url'
|
55
|
-
current_url.
|
55
|
+
expect(current_url).to eq('http://example.com/news/5')
|
56
56
|
|
57
57
|
Capybara.app_host = 'http://example.com:3000'
|
58
58
|
|
59
59
|
visit '/my_custom_url'
|
60
|
-
current_url.
|
60
|
+
expect(current_url).to eq('http://example.com:3000/news/5')
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'foregoes search if ignored path pattern is detected' do
|
@@ -65,19 +65,22 @@ describe 'Redirector middleware', :type => :feature do
|
|
65
65
|
Redirector.ignored_patterns = [/^\/my_custom_url\/.+/]
|
66
66
|
|
67
67
|
visit '/my_custom_url/20'
|
68
|
-
current_path.
|
68
|
+
expect(current_path).to eq('/my_custom_url/20')
|
69
69
|
|
70
70
|
Redirector.ignored_patterns = original_option
|
71
71
|
end
|
72
72
|
|
73
73
|
unless Rails.version =~ /\A4\.2\.\d\z/
|
74
74
|
it 'handles invalid URIs properly' do
|
75
|
-
bad_rule = create(:redirect_rule_regex,
|
75
|
+
bad_rule = create(:redirect_rule_regex,
|
76
|
+
:destination => 'http://www.example.com/invalid)e2',
|
77
|
+
:source => '^/custom(.*)$',
|
78
|
+
)
|
76
79
|
|
77
80
|
begin
|
78
|
-
visit '/
|
81
|
+
visit '/custome2'
|
79
82
|
rescue Redirector::RuleError => e
|
80
|
-
e.message.
|
83
|
+
expect(e.message).to eq("RedirectRule #{bad_rule.id} generated the bad destination: http://www.example.com)e2")
|
81
84
|
end
|
82
85
|
end
|
83
86
|
end
|
@@ -4,61 +4,66 @@ describe RedirectRule do
|
|
4
4
|
subject { create(:redirect_rule) }
|
5
5
|
let!(:rule) { subject }
|
6
6
|
|
7
|
-
it {
|
7
|
+
it { is_expected.to have_many(:request_environment_rules) }
|
8
8
|
|
9
|
-
it {
|
9
|
+
it { is_expected.to accept_nested_attributes_for(:request_environment_rules) }
|
10
10
|
|
11
|
-
it {
|
12
|
-
it {
|
11
|
+
it { is_expected.to validate_presence_of(:source) }
|
12
|
+
it { is_expected.to validate_presence_of(:destination) }
|
13
13
|
|
14
|
-
it {
|
15
|
-
it {
|
16
|
-
it {
|
17
|
-
it {
|
14
|
+
it { is_expected.to allow_value('0').for(:active) }
|
15
|
+
it { is_expected.to allow_value('1').for(:active) }
|
16
|
+
it { is_expected.to allow_value(true).for(:active) }
|
17
|
+
it { is_expected.to allow_value(false).for(:active) }
|
18
18
|
|
19
|
-
it {
|
20
|
-
it {
|
21
|
-
it {
|
22
|
-
it {
|
19
|
+
it { is_expected.to allow_value('0').for(:source_is_regex) }
|
20
|
+
it { is_expected.to allow_value('1').for(:source_is_regex) }
|
21
|
+
it { is_expected.to allow_value(true).for(:source_is_regex) }
|
22
|
+
it { is_expected.to allow_value(false).for(:source_is_regex) }
|
23
23
|
|
24
|
-
it {
|
25
|
-
it {
|
26
|
-
it {
|
27
|
-
it {
|
24
|
+
it { is_expected.to allow_value('0').for(:source_is_case_sensitive) }
|
25
|
+
it { is_expected.to allow_value('1').for(:source_is_case_sensitive) }
|
26
|
+
it { is_expected.to allow_value(true).for(:source_is_case_sensitive) }
|
27
|
+
it { is_expected.to allow_value(false).for(:source_is_case_sensitive) }
|
28
28
|
|
29
29
|
it 'should not allow an invalid regex' do
|
30
|
-
new_rule = RedirectRule.new(
|
31
|
-
:
|
32
|
-
|
30
|
+
new_rule = RedirectRule.new(
|
31
|
+
:source => '[',
|
32
|
+
:source_is_regex => true,
|
33
|
+
:destination => 'http://www.example.com',
|
34
|
+
:active => true
|
35
|
+
)
|
36
|
+
new_rule.validate
|
37
|
+
expect(new_rule.errors[:source]).to eq(['is an invalid regular expression'])
|
33
38
|
end
|
34
39
|
|
35
40
|
describe 'strip_source_whitespace before_save callback' do
|
36
41
|
it 'strips leading and trailing whitespace when saved' do
|
37
|
-
subject =
|
42
|
+
subject = FactoryBot.build(:redirect_rule, :source => ' /needs-stripping ')
|
38
43
|
|
39
44
|
subject.save
|
40
|
-
subject.reload.source.
|
45
|
+
expect(subject.reload.source).to eq('/needs-stripping')
|
41
46
|
end
|
42
47
|
end
|
43
48
|
|
44
49
|
describe '.match_for' do
|
45
50
|
it 'returns nil if there is no matching rule' do
|
46
|
-
RedirectRule.match_for('/someplace', {}).
|
51
|
+
expect(RedirectRule.match_for('/someplace', {})).to be_nil
|
47
52
|
end
|
48
53
|
|
49
54
|
it 'returns the rule if there is a matching rule' do
|
50
|
-
RedirectRule.match_for('/catchy_thingy', {}).
|
55
|
+
expect(RedirectRule.match_for('/catchy_thingy', {})).to eq(subject)
|
51
56
|
end
|
52
57
|
|
53
58
|
context 'for a case sensitive match' do
|
54
59
|
let!(:case_sensitive_rule) { create(:redirect_rule, :source_is_case_sensitive => true, :source => '/Case-Does-Matter') }
|
55
60
|
|
56
61
|
it 'returns the rule if it matches the case' do
|
57
|
-
RedirectRule.match_for('/Case-Does-Matter', {}).
|
62
|
+
expect(RedirectRule.match_for('/Case-Does-Matter', {})).to eq(case_sensitive_rule)
|
58
63
|
end
|
59
64
|
|
60
65
|
it 'returns nil if it does not match the case' do
|
61
|
-
RedirectRule.match_for('/case-does-matter', {}).
|
66
|
+
expect(RedirectRule.match_for('/case-does-matter', {})).to be_nil
|
62
67
|
end
|
63
68
|
end
|
64
69
|
|
@@ -66,11 +71,11 @@ describe RedirectRule do
|
|
66
71
|
let!(:case_insensitive_rule) { create(:redirect_rule, :source_is_case_sensitive => false, :source => '/Case-Does-Not-Matter') }
|
67
72
|
|
68
73
|
it 'returns the rule if it matches the case' do
|
69
|
-
RedirectRule.match_for('/Case-Does-Not-Matter', {}).
|
74
|
+
expect(RedirectRule.match_for('/Case-Does-Not-Matter', {})).to eq(case_insensitive_rule)
|
70
75
|
end
|
71
76
|
|
72
77
|
it 'returns the rule if it does not match the case' do
|
73
|
-
RedirectRule.match_for('/case-does-not-matter', {}).
|
78
|
+
expect(RedirectRule.match_for('/case-does-not-matter', {})).to eq(case_insensitive_rule)
|
74
79
|
end
|
75
80
|
end
|
76
81
|
|
@@ -78,11 +83,11 @@ describe RedirectRule do
|
|
78
83
|
let!(:regex_rule){ create(:redirect_rule_regex, :source_is_case_sensitive => true) }
|
79
84
|
|
80
85
|
it 'returns the rule if it matches the case' do
|
81
|
-
RedirectRule.match_for('/new_shiny/from_company', {}).
|
86
|
+
expect(RedirectRule.match_for('/new_shiny/from_company', {})).to eq(regex_rule)
|
82
87
|
end
|
83
88
|
|
84
89
|
it 'returns nil if it does not match the case' do
|
85
|
-
RedirectRule.match_for('/new_SHINY/from_company', {}).
|
90
|
+
expect(RedirectRule.match_for('/new_SHINY/from_company', {})).to be_nil
|
86
91
|
end
|
87
92
|
end
|
88
93
|
|
@@ -90,11 +95,11 @@ describe RedirectRule do
|
|
90
95
|
let!(:regex_rule){ create(:redirect_rule_regex) }
|
91
96
|
|
92
97
|
it 'returns the rule if it matches the case' do
|
93
|
-
RedirectRule.match_for('/new_shiny/from_company', {}).
|
98
|
+
expect(RedirectRule.match_for('/new_shiny/from_company', {})).to eq(regex_rule)
|
94
99
|
end
|
95
100
|
|
96
101
|
it 'returns the rule if it does not match the case' do
|
97
|
-
RedirectRule.match_for('/new_SHINY/from_company', {}).
|
102
|
+
expect(RedirectRule.match_for('/new_SHINY/from_company', {})).to eq(regex_rule)
|
98
103
|
end
|
99
104
|
end
|
100
105
|
|
@@ -104,11 +109,11 @@ describe RedirectRule do
|
|
104
109
|
end
|
105
110
|
|
106
111
|
it 'should find the rule if it matches' do
|
107
|
-
RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.com'}).
|
112
|
+
expect(RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.com'})).to eq(subject)
|
108
113
|
end
|
109
114
|
|
110
115
|
it 'should not find the rule if there is no match' do
|
111
|
-
RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.ca'}).
|
116
|
+
expect(RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.ca'})).to be_nil
|
112
117
|
end
|
113
118
|
end
|
114
119
|
|
@@ -119,13 +124,13 @@ describe RedirectRule do
|
|
119
124
|
end
|
120
125
|
|
121
126
|
it 'should find the rule if it matches' do
|
122
|
-
RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.com',
|
123
|
-
'QUERY_STRING' => 's=bogus&something=value'}).
|
127
|
+
expect(RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.com',
|
128
|
+
'QUERY_STRING' => 's=bogus&something=value'})).to eq(subject)
|
124
129
|
end
|
125
130
|
|
126
131
|
it 'should not find the rule if there is no match' do
|
127
|
-
RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.com',
|
128
|
-
"QUERY_STRING" => 's=bogus&something=wrong'}).
|
132
|
+
expect(RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.com',
|
133
|
+
"QUERY_STRING" => 's=bogus&something=wrong'})).to be_nil
|
129
134
|
end
|
130
135
|
end
|
131
136
|
|
@@ -140,18 +145,18 @@ describe RedirectRule do
|
|
140
145
|
end
|
141
146
|
|
142
147
|
it 'should find the rule if it matches' do
|
143
|
-
RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.com',
|
144
|
-
'QUERY_STRING' => 's=bogus&something=value'}).
|
148
|
+
expect(RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.com',
|
149
|
+
'QUERY_STRING' => 's=bogus&something=value'})).to eq(subject)
|
145
150
|
end
|
146
151
|
|
147
152
|
it 'should find the other rule if it matches' do
|
148
|
-
RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.com',
|
149
|
-
'QUERY_STRING' => 's=bogus&another=value'}).
|
153
|
+
expect(RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.com',
|
154
|
+
'QUERY_STRING' => 's=bogus&another=value'})).to eq(rule2)
|
150
155
|
end
|
151
156
|
|
152
157
|
it 'should not find the rule if there is no match' do
|
153
|
-
RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.com',
|
154
|
-
"QUERY_STRING" => 's=bogus&something=wrong'}).
|
158
|
+
expect(RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.com',
|
159
|
+
"QUERY_STRING" => 's=bogus&something=wrong'})).to be_nil
|
155
160
|
end
|
156
161
|
end
|
157
162
|
|
@@ -159,7 +164,7 @@ describe RedirectRule do
|
|
159
164
|
let!(:regex_rule){ create(:redirect_rule_regex, :source => '[A-Za-z0-9]_thingy') }
|
160
165
|
|
161
166
|
it 'should return the exact match' do
|
162
|
-
RedirectRule.match_for('/catchy_thingy', {}).
|
167
|
+
expect(RedirectRule.match_for('/catchy_thingy', {})).to eq(subject)
|
163
168
|
end
|
164
169
|
end
|
165
170
|
end
|
@@ -168,15 +173,15 @@ describe RedirectRule do
|
|
168
173
|
let!(:regex_rule) { create(:redirect_rule_regex) }
|
169
174
|
|
170
175
|
it 'should find a regex match' do
|
171
|
-
RedirectRule.destination_for('/new_shiny/from_company', {}).
|
176
|
+
expect(RedirectRule.destination_for('/new_shiny/from_company', {})).to eq('http://www.example.com/news/from_company')
|
172
177
|
end
|
173
178
|
|
174
179
|
it 'should find a string match' do
|
175
|
-
RedirectRule.destination_for('/catchy_thingy', {}).
|
180
|
+
expect(RedirectRule.destination_for('/catchy_thingy', {})).to eq('http://www.example.com/products/1')
|
176
181
|
end
|
177
182
|
|
178
183
|
it 'should return nil if there is no matching rule' do
|
179
|
-
RedirectRule.destination_for('/someplace', {}).
|
184
|
+
expect(RedirectRule.destination_for('/someplace', {})).to be_nil
|
180
185
|
end
|
181
186
|
end
|
182
187
|
|
@@ -184,11 +189,11 @@ describe RedirectRule do
|
|
184
189
|
let(:regex_rule) { create(:redirect_rule_regex) }
|
185
190
|
|
186
191
|
it 'returns the destination for a non regex rule' do
|
187
|
-
subject.evaluated_destination_for('/catchy_thingy').
|
192
|
+
expect(subject.evaluated_destination_for('/catchy_thingy')).to eq('http://www.example.com/products/1')
|
188
193
|
end
|
189
194
|
|
190
195
|
it 'returns the evaluated destination for a regex rule' do
|
191
|
-
regex_rule.evaluated_destination_for('/new_shiny/from_company').
|
196
|
+
expect(regex_rule.evaluated_destination_for('/new_shiny/from_company')).to eq('http://www.example.com/news/from_company')
|
192
197
|
end
|
193
198
|
end
|
194
199
|
end
|
@@ -3,43 +3,44 @@ require 'spec_helper'
|
|
3
3
|
describe RequestEnvironmentRule do
|
4
4
|
subject { create(:request_environment_rule) }
|
5
5
|
|
6
|
-
it {
|
6
|
+
it { is_expected.to belong_to(:redirect_rule) }
|
7
7
|
|
8
|
-
it {
|
9
|
-
it {
|
10
|
-
it {
|
8
|
+
it { is_expected.to validate_presence_of(:redirect_rule) }
|
9
|
+
it { is_expected.to validate_presence_of(:environment_key_name) }
|
10
|
+
it { is_expected.to validate_presence_of(:environment_value) }
|
11
11
|
|
12
|
-
it {
|
13
|
-
it {
|
14
|
-
it {
|
15
|
-
it {
|
12
|
+
it { is_expected.to allow_value('0').for(:environment_value_is_regex) }
|
13
|
+
it { is_expected.to allow_value('1').for(:environment_value_is_regex) }
|
14
|
+
it { is_expected.to allow_value(true).for(:environment_value_is_regex) }
|
15
|
+
it { is_expected.to allow_value(false).for(:environment_value_is_regex) }
|
16
16
|
|
17
|
-
it {
|
18
|
-
it {
|
19
|
-
it {
|
20
|
-
it {
|
17
|
+
it { is_expected.to allow_value('0').for(:environment_value_is_case_sensitive) }
|
18
|
+
it { is_expected.to allow_value('1').for(:environment_value_is_case_sensitive) }
|
19
|
+
it { is_expected.to allow_value(true).for(:environment_value_is_case_sensitive) }
|
20
|
+
it { is_expected.to allow_value(false).for(:environment_value_is_case_sensitive) }
|
21
21
|
|
22
22
|
it 'should not allow an invalid regex' do
|
23
23
|
rule = build(:request_environment_rule_regex, :environment_value => '[')
|
24
|
-
rule.
|
24
|
+
rule.validate
|
25
|
+
expect(rule.errors[:environment_value]).to eq(['is an invalid regular expression'])
|
25
26
|
end
|
26
27
|
|
27
28
|
it "should know if it's matched for a non-regex value" do
|
28
|
-
subject.matches?({'SERVER_NAME' => 'example.com'}).
|
29
|
-
subject.matches?({'HTTP_HOST' => 'www.example.com'}).
|
30
|
-
subject.matches?({'SERVER_NAME' => 'example.ca'}).
|
29
|
+
expect(subject.matches?({'SERVER_NAME' => 'example.com'})).to be_truthy
|
30
|
+
expect(subject.matches?({'HTTP_HOST' => 'www.example.com'})).to be_falsey
|
31
|
+
expect(subject.matches?({'SERVER_NAME' => 'example.ca'})).to be_falsey
|
31
32
|
end
|
32
33
|
|
33
34
|
context 'with a case sensitive regex value' do
|
34
35
|
subject { create(:request_environment_rule_regex) }
|
35
36
|
|
36
37
|
it "should know if it's matched" do
|
37
|
-
subject.matches?({'QUERY_STRING' => 'something=value'}).
|
38
|
-
subject.matches?({'QUERY_STRING' => 'q=search&something=value'}).
|
39
|
-
subject.matches?({'QUERY_STRING' => 'q=search&something=VALUE'}).
|
40
|
-
subject.matches?({'QUERY_STRING' => 'q=search&something=bogus'}).
|
41
|
-
subject.matches?({'QUERY_STRING' => 'q=search'}).
|
42
|
-
subject.matches?({'SERVER_NAME' => 'example.ca'}).
|
38
|
+
expect(subject.matches?({'QUERY_STRING' => 'something=value'})).to be_truthy
|
39
|
+
expect(subject.matches?({'QUERY_STRING' => 'q=search&something=value'})).to be_truthy
|
40
|
+
expect(subject.matches?({'QUERY_STRING' => 'q=search&something=VALUE'})).to be_falsey
|
41
|
+
expect(subject.matches?({'QUERY_STRING' => 'q=search&something=bogus'})).to be_falsey
|
42
|
+
expect(subject.matches?({'QUERY_STRING' => 'q=search'})).to be_falsey
|
43
|
+
expect(subject.matches?({'SERVER_NAME' => 'example.ca'})).to be_falsey
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
@@ -47,12 +48,12 @@ describe RequestEnvironmentRule do
|
|
47
48
|
subject { create(:request_environment_rule_regex, :environment_value_is_case_sensitive => false) }
|
48
49
|
|
49
50
|
it "should know if it's matched" do
|
50
|
-
subject.matches?({'QUERY_STRING' => 'something=value'}).
|
51
|
-
subject.matches?({'QUERY_STRING' => 'q=search&something=value'}).
|
52
|
-
subject.matches?({'QUERY_STRING' => 'q=search&something=VALUE'}).
|
53
|
-
subject.matches?({'QUERY_STRING' => 'q=search&something=bogus'}).
|
54
|
-
subject.matches?({'QUERY_STRING' => 'q=search'}).
|
55
|
-
subject.matches?({'SERVER_NAME' => 'example.ca'}).
|
51
|
+
expect(subject.matches?({'QUERY_STRING' => 'something=value'})).to be_truthy
|
52
|
+
expect(subject.matches?({'QUERY_STRING' => 'q=search&something=value'})).to be_truthy
|
53
|
+
expect(subject.matches?({'QUERY_STRING' => 'q=search&something=VALUE'})).to be_truthy
|
54
|
+
expect(subject.matches?({'QUERY_STRING' => 'q=search&something=bogus'})).to be_falsey
|
55
|
+
expect(subject.matches?({'QUERY_STRING' => 'q=search'})).to be_falsey
|
56
|
+
expect(subject.matches?({'SERVER_NAME' => 'example.ca'})).to be_falsey
|
56
57
|
end
|
57
58
|
end
|
58
59
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,19 +6,19 @@ Coveralls.wear! 'rails'
|
|
6
6
|
|
7
7
|
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
8
8
|
require 'rspec/rails'
|
9
|
-
require 'rspec/autorun'
|
10
9
|
require 'shoulda-matchers'
|
11
10
|
require 'capybara/rails'
|
12
11
|
require 'capybara/rspec'
|
13
12
|
require 'database_cleaner'
|
14
|
-
require '
|
13
|
+
require 'factory_bot_rails'
|
14
|
+
require 'pry'
|
15
15
|
|
16
16
|
Rails.backtrace_cleaner.remove_silencers!
|
17
17
|
|
18
18
|
DatabaseCleaner.strategy = :truncation
|
19
19
|
|
20
20
|
RSpec.configure do |config|
|
21
|
-
config.include
|
21
|
+
config.include FactoryBot::Syntax::Methods
|
22
22
|
|
23
23
|
config.mock_with :rspec
|
24
24
|
config.use_transactional_fixtures = true
|
@@ -29,4 +29,22 @@ RSpec.configure do |config|
|
|
29
29
|
Capybara.reset_sessions! # Forget the (simulated) browser state
|
30
30
|
Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver
|
31
31
|
end
|
32
|
+
|
33
|
+
# rspec-rails 3 will no longer automatically infer an example group's spec type
|
34
|
+
# from the file location. You can explicitly opt-in to the feature using this
|
35
|
+
# config option.
|
36
|
+
# To explicitly tag specs without using automatic inference, set the `:type`
|
37
|
+
# metadata manually:
|
38
|
+
#
|
39
|
+
# describe ThingsController, :type => :controller do
|
40
|
+
# # Equivalent to being in spec/controllers
|
41
|
+
# end
|
42
|
+
config.infer_spec_type_from_file_location!
|
43
|
+
end
|
44
|
+
|
45
|
+
Shoulda::Matchers.configure do |config|
|
46
|
+
config.integrate do |with|
|
47
|
+
with.test_framework :rspec
|
48
|
+
with.library :rails
|
49
|
+
end
|
32
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redirector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Landau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '3.7'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '3.7'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: shoulda-matchers
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: factory_bot_rails
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|