redirector 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@ describe 'Redirector middleware' do
6
6
  FactoryGirl.create(:redirect_rule_regex, :destination => '/news/$1', :source => '/my_custom_url/([A-Za-z0-9_]+)')
7
7
  FactoryGirl.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
11
11
  visit '/my_custom_url'
12
12
  current_path.should == '/news/5'
@@ -29,4 +29,26 @@ describe 'Redirector middleware' do
29
29
  current_path.should == '/news'
30
30
  Redirector.include_query_in_source = original_option
31
31
  end
32
+
33
+ it 'handles requests with or without a port specified' do
34
+ Capybara.app_host = 'http://example.com'
35
+
36
+ visit '/my_custom_url'
37
+ current_url.should == 'http://example.com/news/5'
38
+
39
+ Capybara.app_host = 'http://example.com:3000'
40
+
41
+ visit '/my_custom_url'
42
+ current_url.should == 'http://example.com:3000/news/5'
43
+ end
44
+
45
+ it 'handles invalid URIs properly' do
46
+ bad_rule = FactoryGirl.create(:redirect_rule_regex, :destination => 'http://www.example.com$1', :source => '^/custom(.*)$')
47
+
48
+ begin
49
+ visit '/custom)%e2'
50
+ rescue Redirector::RuleError => e
51
+ e.message.should == "RedirectRule #{bad_rule.id} generated the bad destination: http://www.example.com)%e2"
52
+ end
53
+ end
32
54
  end
@@ -6,13 +6,6 @@ describe RedirectRule do
6
6
 
7
7
  it { should have_many(:request_environment_rules) }
8
8
 
9
- it { should allow_mass_assignment_of(:source) }
10
- it { should allow_mass_assignment_of(:source_is_regex) }
11
- it { should allow_mass_assignment_of(:destination) }
12
- it { should allow_mass_assignment_of(:active) }
13
- it { should allow_mass_assignment_of(:source_is_case_sensitive) }
14
- it { should allow_mass_assignment_of(:request_environment_rules_attributes) }
15
-
16
9
  it { should accept_nested_attributes_for(:request_environment_rules) }
17
10
 
18
11
  it { should validate_presence_of(:source) }
@@ -50,7 +43,7 @@ describe RedirectRule do
50
43
 
51
44
  context 'for a case sensitive regex match' do
52
45
  let!(:regex_rule){ FactoryGirl.create(:redirect_rule_regex, :source_is_case_sensitive => true) }
53
-
46
+
54
47
  it 'returns the rule if it matches the case' do
55
48
  RedirectRule.match_for('/new_shiny/from_company', {}).should == regex_rule
56
49
  end
@@ -62,7 +55,7 @@ describe RedirectRule do
62
55
 
63
56
  context 'for a case insensitive regex match' do
64
57
  let!(:regex_rule){ FactoryGirl.create(:redirect_rule_regex) }
65
-
58
+
66
59
  it 'returns the rule if it matches the case' do
67
60
  RedirectRule.match_for('/new_shiny/from_company', {}).should == regex_rule
68
61
  end
@@ -76,16 +69,16 @@ describe RedirectRule do
76
69
  before do
77
70
  FactoryGirl.create(:request_environment_rule, :redirect_rule => subject)
78
71
  end
79
-
72
+
80
73
  it 'should find the rule if it matches' do
81
74
  RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.com'}).should == subject
82
75
  end
83
-
76
+
84
77
  it 'should not find the rule if there is no match' do
85
78
  RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.ca'}).should be_nil
86
79
  end
87
80
  end
88
-
81
+
89
82
  context 'with a rule with multiple environment conditions' do
90
83
  before do
91
84
  FactoryGirl.create(:request_environment_rule, :redirect_rule => subject)
@@ -96,13 +89,13 @@ describe RedirectRule do
96
89
  RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.com',
97
90
  'QUERY_STRING' => 's=bogus&something=value'}).should == subject
98
91
  end
99
-
92
+
100
93
  it 'should not find the rule if there is no match' do
101
- RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.com',
94
+ RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.com',
102
95
  "QUERY_STRING" => 's=bogus&something=wrong'}).should be_nil
103
96
  end
104
97
  end
105
-
98
+
106
99
  context 'with multiple rules with multiple environment conditions' do
107
100
  let!(:rule2){ FactoryGirl.create(:redirect_rule) }
108
101
  before do
@@ -124,14 +117,14 @@ describe RedirectRule do
124
117
  end
125
118
 
126
119
  it 'should not find the rule if there is no match' do
127
- RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.com',
120
+ RedirectRule.match_for('/catchy_thingy', {'SERVER_NAME' => 'example.com',
128
121
  "QUERY_STRING" => 's=bogus&something=wrong'}).should be_nil
129
122
  end
130
123
  end
131
-
124
+
132
125
  context 'with a regex rule that also matches an exact string match' do
133
126
  let!(:regex_rule){ FactoryGirl.create(:redirect_rule_regex, :source => '[A-Za-z0-9]_thingy') }
134
-
127
+
135
128
  it 'should return the exact match' do
136
129
  RedirectRule.match_for('/catchy_thingy', {}).should == subject
137
130
  end
@@ -156,7 +149,7 @@ describe RedirectRule do
156
149
 
157
150
  describe '#evaluated_destination_for' do
158
151
  let(:regex_rule) { FactoryGirl.create(:redirect_rule_regex) }
159
-
152
+
160
153
  it 'returns the destination for a non regex rule' do
161
154
  subject.evaluated_destination_for('/catchy_thingy').should == 'http://www.example.com/products/1'
162
155
  end
@@ -165,4 +158,4 @@ describe RedirectRule do
165
158
  regex_rule.evaluated_destination_for('/new_shiny/from_company').should == 'http://www.example.com/news/from_company'
166
159
  end
167
160
  end
168
- end
161
+ end
@@ -5,13 +5,7 @@ describe RequestEnvironmentRule do
5
5
 
6
6
  it { should belong_to(:redirect_rule) }
7
7
 
8
- it { should allow_mass_assignment_of(:redirect_rule_id) }
9
- it { should allow_mass_assignment_of(:environment_key_name) }
10
- it { should allow_mass_assignment_of(:environment_value) }
11
- it { should allow_mass_assignment_of(:environment_value_is_regex) }
12
- it { should allow_mass_assignment_of(:environment_value_is_case_sensitive) }
13
-
14
- it { should validate_presence_of(:redirect_rule_id) }
8
+ it { should validate_presence_of(:redirect_rule) }
15
9
  it { should validate_presence_of(:environment_key_name) }
16
10
  it { should validate_presence_of(:environment_value) }
17
11
 
@@ -38,7 +32,7 @@ describe RequestEnvironmentRule do
38
32
 
39
33
  context 'with a case sensitive regex value' do
40
34
  subject { FactoryGirl.create(:request_environment_rule_regex) }
41
-
35
+
42
36
  it "should know if it's matched" do
43
37
  subject.matches?({'QUERY_STRING' => 'something=value'}).should be_true
44
38
  subject.matches?({'QUERY_STRING' => 'q=search&something=value'}).should be_true
@@ -51,7 +45,7 @@ describe RequestEnvironmentRule do
51
45
 
52
46
  context 'with a case insensitve regex value' do
53
47
  subject { FactoryGirl.create(:request_environment_rule_regex, :environment_value_is_case_sensitive => false) }
54
-
48
+
55
49
  it "should know if it's matched" do
56
50
  subject.matches?({'QUERY_STRING' => 'something=value'}).should be_true
57
51
  subject.matches?({'QUERY_STRING' => 'q=search&something=value'}).should be_true
@@ -61,4 +55,4 @@ describe RequestEnvironmentRule do
61
55
  subject.matches?({'SERVER_NAME' => 'example.ca'}).should be_false
62
56
  end
63
57
  end
64
- end
58
+ end
data/spec/spec_helper.rb CHANGED
@@ -18,7 +18,7 @@ RSpec.configure do |config|
18
18
  config.mock_with :rspec
19
19
  config.use_transactional_fixtures = true
20
20
  config.infer_base_class_for_anonymous_controllers = false
21
-
21
+
22
22
  config.after(:each, :type => :request) do
23
23
  DatabaseCleaner.clean # Truncate the database
24
24
  Capybara.reset_sessions! # Forget the (simulated) browser state
metadata CHANGED
@@ -1,128 +1,148 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redirector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
5
- prerelease:
4
+ version: 0.1.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Brian Landau
9
8
  autorequire:
10
9
  bindir: bin
11
- cert_chain: []
12
- date: 2012-09-08 00:00:00.000000000 Z
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDOjCCAiKgAwIBAgIBADANBgkqhkiG9w0BAQUFADBDMRUwEwYDVQQDDAxicmlh
14
+ bmpsYW5kYXUxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkW
15
+ A2NvbTAeFw0wNzEyMDUwMzA5NTBaFw0wODEyMDQwMzA5NTBaMEMxFTATBgNVBAMM
16
+ DGJyaWFuamxhbmRhdTEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPy
17
+ LGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvizK5bV4
18
+ NQARcbPgZpLkSaashTY2JgLqQbxw9en6F4JFQsAlalWvmPqaC65NUxpV+Yb7mK1e
19
+ Rx/6HBln8QeywVMwYTRvqYXXVn1MTLxnYLpLjQQrsM0vZIxwNsmQzrNqvvdGJRok
20
+ gSrJx8lnb3LkmO68N6mG1lETaviaPwWhlB8mu3kcDG9dDXLWbPLDO4wHIIMl+0Nb
21
+ wpyl7d4vteRAXOHmA+Ir5KkWloEhpPJ/WzUL4kxmvcqVSo04aEGsGecgkgSWfyID
22
+ 7Z4KcE1dqjA1RjmeRHwxQilW49GkthB3CQhfhsjYJ3IYvUfiQIzDdrWLbJpxzShk
23
+ E1IpSLMiP4svBQIDAQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNV
24
+ HQ4EFgQU00bxUNAS/W5tSWPDvnSlm3Tf9VYwDQYJKoZIhvcNAQEFBQADggEBAKUC
25
+ 669HsZByRjaana3sE5Tyo59/Cb8LxphAS0s9rMtiQyh2sPIno02/pAKrC7S2qnwZ
26
+ 8W71VKqROGnBhaSjWshwU0BjbcCpNDAE4YPLP3lUlP69FuGXbsqv9sYH1GKjgFHi
27
+ OCM/uh9PLtUOQ0gRKixi8/edn11sUxYLMjpThagIU/kzw2J/xQoUpOgzHzrDnN00
28
+ 8VWE27Mw4BMckRzTjgyEbGB6+j1NYaaQ76a1q1yFc3XiR9crZhyTmXT887lPCe3B
29
+ QHjym4e4y/FmXBJjpO/TtRoYd8a5YTCaOsML7M/nb/XrArvE3l5JaNEXkhH/nGs7
30
+ wR9huisTMlESX3ReGKU=
31
+ -----END CERTIFICATE-----
32
+ date: 2014-01-17 00:00:00.000000000 Z
13
33
  dependencies:
14
34
  - !ruby/object:Gem::Dependency
15
35
  name: rails
16
36
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
37
  requirements:
19
- - - ~>
38
+ - - ">="
20
39
  - !ruby/object:Gem::Version
21
40
  version: '3.1'
22
41
  type: :runtime
23
42
  prerelease: false
24
43
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
44
  requirements:
27
- - - ~>
45
+ - - ">="
28
46
  - !ruby/object:Gem::Version
29
47
  version: '3.1'
30
48
  - !ruby/object:Gem::Dependency
31
49
  name: mysql2
32
50
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
51
  requirements:
35
- - - ! '>='
52
+ - - ">="
36
53
  - !ruby/object:Gem::Version
37
54
  version: '0'
38
55
  type: :development
39
56
  prerelease: false
40
57
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
58
  requirements:
43
- - - ! '>='
59
+ - - ">="
44
60
  - !ruby/object:Gem::Version
45
61
  version: '0'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: rspec-rails
48
64
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
65
  requirements:
51
- - - ! '>='
66
+ - - ">="
52
67
  - !ruby/object:Gem::Version
53
68
  version: '0'
54
69
  type: :development
55
70
  prerelease: false
56
71
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
72
  requirements:
59
- - - ! '>='
73
+ - - ">="
60
74
  - !ruby/object:Gem::Version
61
75
  version: '0'
62
76
  - !ruby/object:Gem::Dependency
63
77
  name: shoulda-matchers
64
78
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
79
  requirements:
67
- - - ! '>='
80
+ - - ">="
68
81
  - !ruby/object:Gem::Version
69
82
  version: '0'
70
83
  type: :development
71
84
  prerelease: false
72
85
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
86
  requirements:
75
- - - ! '>='
87
+ - - ">="
76
88
  - !ruby/object:Gem::Version
77
89
  version: '0'
78
90
  - !ruby/object:Gem::Dependency
79
91
  name: capybara
80
92
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
93
  requirements:
83
- - - ! '>='
94
+ - - "~>"
84
95
  - !ruby/object:Gem::Version
85
- version: '0'
96
+ version: '2.2'
86
97
  type: :development
87
98
  prerelease: false
88
99
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
100
  requirements:
91
- - - ! '>='
101
+ - - "~>"
92
102
  - !ruby/object:Gem::Version
93
- version: '0'
103
+ version: '2.2'
94
104
  - !ruby/object:Gem::Dependency
95
105
  name: database_cleaner
96
106
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
107
  requirements:
99
- - - ! '>='
108
+ - - ">="
100
109
  - !ruby/object:Gem::Version
101
110
  version: '0'
102
111
  type: :development
103
112
  prerelease: false
104
113
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
114
  requirements:
107
- - - ! '>='
115
+ - - ">="
108
116
  - !ruby/object:Gem::Version
109
117
  version: '0'
110
118
  - !ruby/object:Gem::Dependency
111
119
  name: factory_girl_rails
112
120
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
121
  requirements:
115
- - - ~>
122
+ - - "~>"
116
123
  - !ruby/object:Gem::Version
117
124
  version: '1.7'
118
125
  type: :development
119
126
  prerelease: false
120
127
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
128
  requirements:
123
- - - ~>
129
+ - - "~>"
124
130
  - !ruby/object:Gem::Version
125
131
  version: '1.7'
132
+ - !ruby/object:Gem::Dependency
133
+ name: appraisal
134
+ requirement: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ type: :development
140
+ prerelease: false
141
+ version_requirements: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
126
146
  description: A Rails engine that adds a piece of middleware to the top of your middleware
127
147
  stack that looks for redirect rules stored in your database and redirects you accordingly.
128
148
  email:
@@ -131,20 +151,20 @@ executables: []
131
151
  extensions: []
132
152
  extra_rdoc_files: []
133
153
  files:
154
+ - HISTORY
155
+ - MIT-LICENSE
156
+ - README.md
157
+ - Rakefile
134
158
  - app/models/redirect_rule.rb
135
159
  - app/models/request_environment_rule.rb
136
160
  - db/migrate/20120815212612_create_redirect_rules.rb
137
161
  - db/migrate/20120823163756_create_request_environment_rules.rb
162
+ - lib/redirector.rb
138
163
  - lib/redirector/engine.rb
139
164
  - lib/redirector/middleware.rb
140
165
  - lib/redirector/regex_attribute.rb
141
166
  - lib/redirector/version.rb
142
- - lib/redirector.rb
143
- - MIT-LICENSE
144
- - Rakefile
145
- - README.md
146
167
  - redirector.gemspec
147
- - HISTORY
148
168
  - spec/dummy/README.rdoc
149
169
  - spec/dummy/Rakefile
150
170
  - spec/dummy/app/assets/javascripts/application.js
@@ -153,9 +173,11 @@ files:
153
173
  - spec/dummy/app/controllers/news_controller.rb
154
174
  - spec/dummy/app/helpers/application_helper.rb
155
175
  - spec/dummy/app/views/layouts/application.html.erb
176
+ - spec/dummy/config.ru
156
177
  - spec/dummy/config/application.rb
157
178
  - spec/dummy/config/boot.rb
158
179
  - spec/dummy/config/database.yml
180
+ - spec/dummy/config/database.yml.example
159
181
  - spec/dummy/config/environment.rb
160
182
  - spec/dummy/config/environments/development.rb
161
183
  - spec/dummy/config/environments/production.rb
@@ -168,7 +190,6 @@ files:
168
190
  - spec/dummy/config/initializers/wrap_parameters.rb
169
191
  - spec/dummy/config/locales/en.yml
170
192
  - spec/dummy/config/routes.rb
171
- - spec/dummy/config.ru
172
193
  - spec/dummy/db/schema.rb
173
194
  - spec/dummy/log/development.log
174
195
  - spec/dummy/log/test.log
@@ -179,44 +200,35 @@ files:
179
200
  - spec/dummy/script/rails
180
201
  - spec/factories/redirect_rules.rb
181
202
  - spec/factories/request_environment_rules.rb
203
+ - spec/features/middleware_spec.rb
182
204
  - spec/models/redirect_rule_spec.rb
183
205
  - spec/models/request_environment_rule_spec.rb
184
- - spec/requests/middleware_spec.rb
185
206
  - spec/spec_helper.rb
186
207
  homepage: https://github.com/vigetlabs/redirector
187
208
  licenses: []
209
+ metadata: {}
188
210
  post_install_message:
189
211
  rdoc_options: []
190
212
  require_paths:
191
213
  - lib
192
214
  required_ruby_version: !ruby/object:Gem::Requirement
193
- none: false
194
215
  requirements:
195
- - - ! '>='
216
+ - - ">="
196
217
  - !ruby/object:Gem::Version
197
218
  version: '0'
198
- segments:
199
- - 0
200
- hash: -1337487945762421703
201
219
  required_rubygems_version: !ruby/object:Gem::Requirement
202
- none: false
203
220
  requirements:
204
- - - ! '>='
221
+ - - ">="
205
222
  - !ruby/object:Gem::Version
206
223
  version: '0'
207
- segments:
208
- - 0
209
- hash: -1337487945762421703
210
224
  requirements: []
211
225
  rubyforge_project:
212
- rubygems_version: 1.8.21
226
+ rubygems_version: 2.2.0
213
227
  signing_key:
214
- specification_version: 3
228
+ specification_version: 4
215
229
  summary: A Rails engine that adds a piece of middleware to the top of your middleware
216
230
  stack that looks for redirect rules stored in your database and redirects you accordingly.
217
231
  test_files:
218
- - spec/dummy/README.rdoc
219
- - spec/dummy/Rakefile
220
232
  - spec/dummy/app/assets/javascripts/application.js
221
233
  - spec/dummy/app/assets/stylesheets/application.css
222
234
  - spec/dummy/app/controllers/application_controller.rb
@@ -226,6 +238,7 @@ test_files:
226
238
  - spec/dummy/config/application.rb
227
239
  - spec/dummy/config/boot.rb
228
240
  - spec/dummy/config/database.yml
241
+ - spec/dummy/config/database.yml.example
229
242
  - spec/dummy/config/environment.rb
230
243
  - spec/dummy/config/environments/development.rb
231
244
  - spec/dummy/config/environments/production.rb
@@ -246,10 +259,12 @@ test_files:
246
259
  - spec/dummy/public/422.html
247
260
  - spec/dummy/public/500.html
248
261
  - spec/dummy/public/favicon.ico
262
+ - spec/dummy/Rakefile
263
+ - spec/dummy/README.rdoc
249
264
  - spec/dummy/script/rails
250
265
  - spec/factories/redirect_rules.rb
251
266
  - spec/factories/request_environment_rules.rb
267
+ - spec/features/middleware_spec.rb
252
268
  - spec/models/redirect_rule_spec.rb
253
269
  - spec/models/request_environment_rule_spec.rb
254
- - spec/requests/middleware_spec.rb
255
270
  - spec/spec_helper.rb