route_downcaser 1.0.1 → 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.
@@ -1,70 +1,117 @@
1
1
  require 'test_helper'
2
2
 
3
- class MockApp
4
- attr_accessor :env
5
-
3
+ class MyMockApp
6
4
  def call(env)
7
- @env = env
5
+ raise "Env nil" if env.blank?
6
+ @env = env.clone
7
+ return @env
8
+ end
9
+
10
+ def env
11
+ @env
8
12
  end
9
13
  end
10
14
 
11
15
  class RouteDowncaserTest < ActiveSupport::TestCase
12
- test "REQUEST_URI path-part is downcased" do
13
- app = MockApp.new
14
- env = { 'REQUEST_URI' => "HELLO/WORLD" }
15
- RouteDowncaser::DowncaseRouteMiddleware.new(app).call(env)
16
+ class BasicTests < ActiveSupport::TestCase
17
+ setup do
18
+ @app = MyMockApp.new
19
+ RouteDowncaser.configuration do |config|
20
+ config.redirect = false
21
+ config.exclude_patterns = nil
22
+ end
23
+ end
16
24
 
17
- assert_equal("hello/world", app.env['REQUEST_URI'])
18
- end
25
+ test "REQUEST_URI path-part is downcased" do
26
+ callenv = { 'REQUEST_URI' => "HELLO/WORLD" }
27
+ RouteDowncaser::DowncaseRouteMiddleware.new(@app).call(callenv)
28
+ assert_equal("hello/world", @app.env['REQUEST_URI'])
29
+ end
19
30
 
20
- test "REQUEST_URI querystring parameters are not touched" do
21
- app = MockApp.new
22
- env = { 'REQUEST_URI' => "HELLO/WORLD?FOO=BAR" }
23
- RouteDowncaser::DowncaseRouteMiddleware.new(app).call(env)
31
+ test "REQUEST_URI querystring parameters are not touched" do
32
+ callenv = { 'REQUEST_URI' => "HELLO/WORLD?FOO=BAR" }
33
+ RouteDowncaser::DowncaseRouteMiddleware.new(@app).call(callenv)
34
+ assert_equal("hello/world?FOO=BAR", @app.env['REQUEST_URI'])
35
+ end
24
36
 
25
- assert_equal("hello/world?FOO=BAR", app.env['REQUEST_URI'])
37
+ test "entire PATH_INFO is downcased" do
38
+ callenv = { 'PATH_INFO' => "HELLO/WORLD" }
39
+ RouteDowncaser::DowncaseRouteMiddleware.new(@app).call(callenv)
40
+ assert_equal("hello/world", @app.env['PATH_INFO'])
41
+ end
26
42
  end
27
43
 
28
- test "entire PATH_INFO is downcased" do
29
- app = MockApp.new
30
- env = { 'PATH_INFO' => "HELLO/WORLD" }
31
- RouteDowncaser::DowncaseRouteMiddleware.new(app).call(env)
32
44
 
33
- assert_equal("hello/world", app.env['PATH_INFO'])
34
- end
45
+ class ExcludePatternsTests < ActiveSupport::TestCase
46
+ setup do
47
+ @app = MyMockApp.new
48
+ RouteDowncaser.configuration do |config|
49
+ config.redirect = false
50
+ config.exclude_patterns = [/assets\//i, /fonts\//i]
51
+ end
52
+ end
35
53
 
36
- test "asset filenames are not touched" do
37
- app = MockApp.new
38
- env = { 'PATH_INFO' => "ASSETS/IMAges/SpaceCat.jpeg" }
39
- RouteDowncaser::DowncaseRouteMiddleware.new(app).call(env)
54
+ test "when PATH_INFO is found in exclude_patterns, do nothing" do
55
+ callenv = { 'PATH_INFO' => "ASSETS/IMAges/SpaceCat.jpeg" }
56
+ RouteDowncaser::DowncaseRouteMiddleware.new(@app).call(callenv)
57
+ assert_equal("ASSETS/IMAges/SpaceCat.jpeg", @app.env['PATH_INFO'])
58
+ end
40
59
 
41
- assert_equal("assets/images/SpaceCat.jpeg", app.env['PATH_INFO'])
60
+ test "when REQUEST_URI is found in exclude_patterns, do nothing" do
61
+ callenv = { 'REQUEST_URI' => "ASSETS/IMAges/SpaceCat.jpeg" }
62
+ RouteDowncaser::DowncaseRouteMiddleware.new(@app).call(callenv)
63
+ assert_equal("ASSETS/IMAges/SpaceCat.jpeg", @app.env['REQUEST_URI'])
64
+ end
42
65
  end
43
66
 
67
+
44
68
  class RedirectTrueTests < ActiveSupport::TestCase
45
69
  setup do
46
- @app = MockApp.new
70
+ @app = MyMockApp.new
47
71
  RouteDowncaser.configuration do |config|
48
72
  config.redirect = true
49
- config.exclude_patterns = [/assets\//i, /fonts\//i]
73
+ config.exclude_patterns = nil
50
74
  end
51
75
  end
52
76
 
53
- test "when redirect is true it redirects paths that do not contain matching exclude patterns" do
54
- env = { 'REQUEST_URI' => "HELLO/WORLD" }
77
+ test "when redirect is true it redirects REQUEST_URI" do
78
+ callenv = { 'REQUEST_URI' => "HELLO/WORLD" }
79
+ assert_equal(
80
+ [301, {'Location' => "hello/world", 'Content-Type' => 'text/html'}, []],
81
+ RouteDowncaser::DowncaseRouteMiddleware.new(@app).call(callenv)
82
+ )
83
+ end
55
84
 
85
+ test "when redirect is true it redirects PATH_INFO" do
86
+ callenv = { 'PATH_INFO' => "HELLO/WORLD" }
56
87
  assert_equal(
57
- RouteDowncaser::DowncaseRouteMiddleware.new(@app).call(env),
58
- [301, {'Location' => "hello/world", 'Content-Type' => 'text/html'}, []]
88
+ [301, {'Location' => "hello/world", 'Content-Type' => 'text/html'}, []],
89
+ RouteDowncaser::DowncaseRouteMiddleware.new(@app).call(callenv)
59
90
  )
60
91
  end
92
+ end
61
93
 
62
- test "when redirect is true it does not redirect matching exclude patterns" do
63
- env = { 'REQUEST_URI' => "fonts/Icons.woff", 'PATH_INFO' => "fonts/Icons.woff" }
64
94
 
65
- RouteDowncaser::DowncaseRouteMiddleware.new(@app).call(env)
95
+ class RedirectTrueExcludePatternsTests < ActiveSupport::TestCase
96
+ setup do
97
+ @app = MyMockApp.new
98
+ RouteDowncaser.configuration do |config|
99
+ config.redirect = true
100
+ config.exclude_patterns = [/assets\//i, /fonts\//i]
101
+ end
102
+ end
103
+
104
+ test "when redirect is true it does not redirect, if REQUEST_URI match exclude patterns" do
105
+ callenv = { 'REQUEST_URI' => "fonts/Icons.woff" }
106
+ RouteDowncaser::DowncaseRouteMiddleware.new(@app).call(callenv)
107
+ assert_equal("fonts/Icons.woff", @app.env['REQUEST_URI'])
108
+ end
66
109
 
110
+ test "when redirect is true it does not redirect, if PATH_INFO match exclude patterns" do
111
+ callenv = { 'PATH_INFO' => "fonts/Icons.woff" }
112
+ RouteDowncaser::DowncaseRouteMiddleware.new(@app).call(callenv)
67
113
  assert_equal("fonts/Icons.woff", @app.env['PATH_INFO'])
68
114
  end
69
115
  end
116
+
70
117
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: route_downcaser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Gehling
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-10 00:00:00.000000000 Z
11
+ date: 2015-03-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This gem hooks into the Rack middleware of Rails. This way all paths
14
14
  are downcased before dispatching to Rails' routing mechanism. Querystring parameters
@@ -62,7 +62,8 @@ files:
62
62
  - test/route_downcaser_test.rb
63
63
  - test/test_helper.rb
64
64
  homepage: https://github.com/carstengehling/route_downcaser
65
- licenses: []
65
+ licenses:
66
+ - MIT
66
67
  metadata: {}
67
68
  post_install_message:
68
69
  rdoc_options: []
@@ -70,12 +71,12 @@ require_paths:
70
71
  - lib
71
72
  required_ruby_version: !ruby/object:Gem::Requirement
72
73
  requirements:
73
- - - ! '>='
74
+ - - '>='
74
75
  - !ruby/object:Gem::Version
75
76
  version: '0'
76
77
  required_rubygems_version: !ruby/object:Gem::Requirement
77
78
  requirements:
78
- - - ! '>='
79
+ - - '>='
79
80
  - !ruby/object:Gem::Version
80
81
  version: '0'
81
82
  requirements: []