rewritten 0.8.2 → 0.9.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/HISTORY.rdoc +5 -0
- data/lib/rack/url.rb +11 -2
- data/lib/rewritten/version.rb +1 -1
- data/test/rack/rewritten_url_test.rb +35 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1abdc39d5f840f0792d1f903d000b5d6d36e95b
|
4
|
+
data.tar.gz: 2746b966bf4d31bb8254fc1a452951a59cdb451c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56b3daa7c907ffc0c845bb341d8348201eb486d08729882c574cf9469e7f8c3c314d4a7cd3e9d26338df6c58c6e425f1505e96f122c4fd06bf583862232bb57d
|
7
|
+
data.tar.gz: f6613822fafe35ccffa7a85b705395a9646421dabdf6cd1a0d5341b7ab234c9eb035916b1e0a085c8b3b475636a1d1ed6d1a18e565930cb5faa2ff57080aa7f0
|
data/HISTORY.rdoc
CHANGED
data/lib/rack/url.rb
CHANGED
@@ -9,6 +9,7 @@ module Rack
|
|
9
9
|
def initialize(app, &block)
|
10
10
|
@app = app
|
11
11
|
@translate_backwards = false
|
12
|
+
@downcase_before_lookup = false
|
12
13
|
|
13
14
|
instance_eval(&block) if block_given?
|
14
15
|
end
|
@@ -19,10 +20,11 @@ module Rack
|
|
19
20
|
subdomain = env["SUBDOMAIN"] ? "#{env["SUBDOMAIN"]}:" : ""
|
20
21
|
|
21
22
|
path = "#{subdomain}#{req.path_info}"
|
23
|
+
path.downcase! if downcase_before_lookup?
|
22
24
|
|
23
|
-
if ::Rewritten.includes?(path) or translate_backwards? && ::Rewritten.exist_translation_for?(path)
|
25
|
+
if ::Rewritten.includes?(path.chomp("/")) or translate_backwards? && ::Rewritten.exist_translation_for?(path)
|
24
26
|
|
25
|
-
to = ::Rewritten.includes?(path) || path
|
27
|
+
to = ::Rewritten.includes?(path.chomp("/")) || path
|
26
28
|
|
27
29
|
current_path = ::Rewritten.get_current_translation(to)
|
28
30
|
current_path = current_path.split(":").last
|
@@ -69,6 +71,13 @@ module Rack
|
|
69
71
|
@translate_backwards = yes_or_no
|
70
72
|
end
|
71
73
|
|
74
|
+
def downcase_before_lookup?
|
75
|
+
@downcase_before_lookup
|
76
|
+
end
|
77
|
+
|
78
|
+
def downcase_before_lookup=(yes_or_no)
|
79
|
+
@downcase_before_lookup = yes_or_no
|
80
|
+
end
|
72
81
|
|
73
82
|
|
74
83
|
end
|
data/lib/rewritten/version.rb
CHANGED
@@ -60,6 +60,41 @@ describe Rack::Rewritten::Url do
|
|
60
60
|
ret[0].must_equal 200
|
61
61
|
end
|
62
62
|
|
63
|
+
describe "/ behavior" do
|
64
|
+
|
65
|
+
it "must 301 redirect paths with / in the end to their chomped version" do
|
66
|
+
ret = @rack.call request_url('/foo/bar/')
|
67
|
+
@app.verify
|
68
|
+
ret[0].must_equal 301
|
69
|
+
ret[1]['Location'].must_equal "http://www.example.org/foo/baz"
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "caps behavior" do
|
75
|
+
|
76
|
+
it "must diferentiate caps" do
|
77
|
+
@app.expect :call, [200, {'Content-Type' => 'text/plain'},[""]], [Hash]
|
78
|
+
ret = @rack.call request_url('/Foo/Bar')
|
79
|
+
@app.verify
|
80
|
+
ret[0].must_equal 200
|
81
|
+
end
|
82
|
+
|
83
|
+
it "must ignore caps if wished" do
|
84
|
+
@rack = Rack::Rewritten::Url.new(@app) do
|
85
|
+
self.downcase_before_lookup = true
|
86
|
+
end
|
87
|
+
|
88
|
+
ret = @rack.call request_url('/Foo/Bar')
|
89
|
+
|
90
|
+
@app.verify
|
91
|
+
ret[0].must_equal 301
|
92
|
+
ret[1]['Location'].must_equal "http://www.example.org/foo/baz"
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
|
63
98
|
describe "enforce nice urls" do
|
64
99
|
|
65
100
|
it "must not redirect from resource url to nice url by default" do
|