redirector 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY +3 -0
- data/README.md +3 -3
- data/app/models/redirect_rule.rb +12 -6
- data/lib/redirector/version.rb +1 -1
- data/redirector.gemspec +2 -2
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/config/environments/development.rb +2 -2
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/log/development.log +235 -0
- data/spec/dummy/log/test.log +12605 -0
- data/spec/features/middleware_spec.rb +6 -6
- data/spec/models/redirect_rule_spec.rb +38 -14
- data/spec/models/request_environment_rule_spec.rb +4 -4
- data/spec/spec_helper.rb +3 -1
- metadata +9 -9
@@ -2,9 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'Redirector middleware', :type => :feature do
|
4
4
|
before do
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
create(:redirect_rule, :destination => '/news/5', :source => '/my_custom_url')
|
6
|
+
create(:redirect_rule_regex, :destination => '/news/$1', :source => '/my_custom_url/([A-Za-z0-9_]+)')
|
7
|
+
create(:redirect_rule_regex, :destination => '/news', :source => 'categoryID=12345')
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'correctly redirects the visitor for an exact match rule' do
|
@@ -61,12 +61,12 @@ describe 'Redirector middleware', :type => :feature do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'handles invalid URIs properly' do
|
64
|
-
bad_rule =
|
64
|
+
bad_rule = create(:redirect_rule_regex, :destination => 'http://www.example.com$1', :source => '^/custom(.*)$')
|
65
65
|
|
66
66
|
begin
|
67
|
-
visit '/custom)
|
67
|
+
visit '/custom)e2'
|
68
68
|
rescue Redirector::RuleError => e
|
69
|
-
e.message.should == "RedirectRule #{bad_rule.id} generated the bad destination: http://www.example.com)
|
69
|
+
e.message.should == "RedirectRule #{bad_rule.id} generated the bad destination: http://www.example.com)e2"
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe RedirectRule do
|
4
|
-
subject {
|
4
|
+
subject { create(:redirect_rule) }
|
5
5
|
let!(:rule) { subject }
|
6
6
|
|
7
7
|
it { should have_many(:request_environment_rules) }
|
@@ -41,8 +41,32 @@ describe RedirectRule do
|
|
41
41
|
RedirectRule.match_for('/catchy_thingy', {}).should == subject
|
42
42
|
end
|
43
43
|
|
44
|
+
context 'for a case sensitive match' do
|
45
|
+
let!(:case_sensitive_rule) { create(:redirect_rule, :source_is_case_sensitive => true, :source => '/Case-Does-Matter') }
|
46
|
+
|
47
|
+
it 'returns the rule if it matches the case' do
|
48
|
+
RedirectRule.match_for('/Case-Does-Matter', {}).should == case_sensitive_rule
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns nil if it does not match the case' do
|
52
|
+
RedirectRule.match_for('/case-does-matter', {}).should be_nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'for a case insensitive match' do
|
57
|
+
let!(:case_insensitive_rule) { create(:redirect_rule, :source_is_case_sensitive => false, :source => '/Case-Does-Not-Matter') }
|
58
|
+
|
59
|
+
it 'returns the rule if it matches the case' do
|
60
|
+
RedirectRule.match_for('/Case-Does-Not-Matter', {}).should == case_insensitive_rule
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'returns the rule if it does not match the case' do
|
64
|
+
RedirectRule.match_for('/case-does-not-matter', {}).should == case_insensitive_rule
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
44
68
|
context 'for a case sensitive regex match' do
|
45
|
-
let!(:regex_rule){
|
69
|
+
let!(:regex_rule){ create(:redirect_rule_regex, :source_is_case_sensitive => true) }
|
46
70
|
|
47
71
|
it 'returns the rule if it matches the case' do
|
48
72
|
RedirectRule.match_for('/new_shiny/from_company', {}).should == regex_rule
|
@@ -54,7 +78,7 @@ describe RedirectRule do
|
|
54
78
|
end
|
55
79
|
|
56
80
|
context 'for a case insensitive regex match' do
|
57
|
-
let!(:regex_rule){
|
81
|
+
let!(:regex_rule){ create(:redirect_rule_regex) }
|
58
82
|
|
59
83
|
it 'returns the rule if it matches the case' do
|
60
84
|
RedirectRule.match_for('/new_shiny/from_company', {}).should == regex_rule
|
@@ -67,7 +91,7 @@ describe RedirectRule do
|
|
67
91
|
|
68
92
|
context 'with a rule with one environment condition' do
|
69
93
|
before do
|
70
|
-
|
94
|
+
create(:request_environment_rule, :redirect_rule => subject)
|
71
95
|
end
|
72
96
|
|
73
97
|
it 'should find the rule if it matches' do
|
@@ -81,8 +105,8 @@ describe RedirectRule do
|
|
81
105
|
|
82
106
|
context 'with a rule with multiple environment conditions' do
|
83
107
|
before do
|
84
|
-
|
85
|
-
|
108
|
+
create(:request_environment_rule, :redirect_rule => subject)
|
109
|
+
create(:request_environment_rule_regex, :redirect_rule => subject)
|
86
110
|
end
|
87
111
|
|
88
112
|
it 'should find the rule if it matches' do
|
@@ -97,12 +121,12 @@ describe RedirectRule do
|
|
97
121
|
end
|
98
122
|
|
99
123
|
context 'with multiple rules with multiple environment conditions' do
|
100
|
-
let!(:rule2){
|
124
|
+
let!(:rule2){ create(:redirect_rule) }
|
101
125
|
before do
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
126
|
+
create(:request_environment_rule, :redirect_rule => subject)
|
127
|
+
create(:request_environment_rule_regex, :redirect_rule => subject)
|
128
|
+
create(:request_environment_rule, :redirect_rule => rule2)
|
129
|
+
create(:request_environment_rule_regex, :redirect_rule => rule2,
|
106
130
|
:environment_value => 'another=value')
|
107
131
|
end
|
108
132
|
|
@@ -123,7 +147,7 @@ describe RedirectRule do
|
|
123
147
|
end
|
124
148
|
|
125
149
|
context 'with a regex rule that also matches an exact string match' do
|
126
|
-
let!(:regex_rule){
|
150
|
+
let!(:regex_rule){ create(:redirect_rule_regex, :source => '[A-Za-z0-9]_thingy') }
|
127
151
|
|
128
152
|
it 'should return the exact match' do
|
129
153
|
RedirectRule.match_for('/catchy_thingy', {}).should == subject
|
@@ -132,7 +156,7 @@ describe RedirectRule do
|
|
132
156
|
end
|
133
157
|
|
134
158
|
describe '.destination_for' do
|
135
|
-
let!(:regex_rule) {
|
159
|
+
let!(:regex_rule) { create(:redirect_rule_regex) }
|
136
160
|
|
137
161
|
it 'should find a regex match' do
|
138
162
|
RedirectRule.destination_for('/new_shiny/from_company', {}).should == 'http://www.example.com/news/from_company'
|
@@ -148,7 +172,7 @@ describe RedirectRule do
|
|
148
172
|
end
|
149
173
|
|
150
174
|
describe '#evaluated_destination_for' do
|
151
|
-
let(:regex_rule) {
|
175
|
+
let(:regex_rule) { create(:redirect_rule_regex) }
|
152
176
|
|
153
177
|
it 'returns the destination for a non regex rule' do
|
154
178
|
subject.evaluated_destination_for('/catchy_thingy').should == 'http://www.example.com/products/1'
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe RequestEnvironmentRule do
|
4
|
-
subject {
|
4
|
+
subject { create(:request_environment_rule) }
|
5
5
|
|
6
6
|
it { should belong_to(:redirect_rule) }
|
7
7
|
|
@@ -20,7 +20,7 @@ describe RequestEnvironmentRule do
|
|
20
20
|
it { should allow_value(false).for(:environment_value_is_case_sensitive) }
|
21
21
|
|
22
22
|
it 'should not allow an invalid regex' do
|
23
|
-
rule =
|
23
|
+
rule = build(:request_environment_rule_regex, :environment_value => '[')
|
24
24
|
rule.errors_on(:environment_value).should == ['is an invalid regular expression']
|
25
25
|
end
|
26
26
|
|
@@ -31,7 +31,7 @@ describe RequestEnvironmentRule do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
context 'with a case sensitive regex value' do
|
34
|
-
subject {
|
34
|
+
subject { create(:request_environment_rule_regex) }
|
35
35
|
|
36
36
|
it "should know if it's matched" do
|
37
37
|
subject.matches?({'QUERY_STRING' => 'something=value'}).should be_true
|
@@ -44,7 +44,7 @@ describe RequestEnvironmentRule do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
context 'with a case insensitve regex value' do
|
47
|
-
subject {
|
47
|
+
subject { create(:request_environment_rule_regex, :environment_value_is_case_sensitive => false) }
|
48
48
|
|
49
49
|
it "should know if it's matched" do
|
50
50
|
subject.matches?({'QUERY_STRING' => 'something=value'}).should be_true
|
data/spec/spec_helper.rb
CHANGED
@@ -18,11 +18,13 @@ Rails.backtrace_cleaner.remove_silencers!
|
|
18
18
|
DatabaseCleaner.strategy = :truncation
|
19
19
|
|
20
20
|
RSpec.configure do |config|
|
21
|
+
config.include FactoryGirl::Syntax::Methods
|
22
|
+
|
21
23
|
config.mock_with :rspec
|
22
24
|
config.use_transactional_fixtures = true
|
23
25
|
config.infer_base_class_for_anonymous_controllers = false
|
24
26
|
|
25
|
-
config.after(:each, :type => :
|
27
|
+
config.after(:each, :type => :feature) do
|
26
28
|
DatabaseCleaner.clean # Truncate the database
|
27
29
|
Capybara.reset_sessions! # Forget the (simulated) browser state
|
28
30
|
Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redirector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Landau
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
QHjym4e4y/FmXBJjpO/TtRoYd8a5YTCaOsML7M/nb/XrArvE3l5JaNEXkhH/nGs7
|
30
30
|
wR9huisTMlESX3ReGKU=
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date: 2014-
|
32
|
+
date: 2014-09-26 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: rails
|
@@ -77,16 +77,16 @@ dependencies:
|
|
77
77
|
name: rspec-rails
|
78
78
|
requirement: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 2.14.2
|
83
83
|
type: :development
|
84
84
|
prerelease: false
|
85
85
|
version_requirements: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 2.14.2
|
90
90
|
- !ruby/object:Gem::Dependency
|
91
91
|
name: shoulda-matchers
|
92
92
|
requirement: !ruby/object:Gem::Requirement
|
@@ -135,14 +135,14 @@ dependencies:
|
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
138
|
+
version: '4.4'
|
139
139
|
type: :development
|
140
140
|
prerelease: false
|
141
141
|
version_requirements: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
145
|
+
version: '4.4'
|
146
146
|
- !ruby/object:Gem::Dependency
|
147
147
|
name: appraisal
|
148
148
|
requirement: !ruby/object:Gem::Requirement
|
@@ -266,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
266
266
|
version: '0'
|
267
267
|
requirements: []
|
268
268
|
rubyforge_project:
|
269
|
-
rubygems_version: 2.2.
|
269
|
+
rubygems_version: 2.2.2
|
270
270
|
signing_key:
|
271
271
|
specification_version: 4
|
272
272
|
summary: A Rails engine that adds a piece of middleware to the top of your middleware
|