rewritten 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 209d70c9a3b200f7541f26509e60f3606869fd94
4
- data.tar.gz: a1bb41ce3c1da38d98912211b9e894f50f987d95
3
+ metadata.gz: e1abdc39d5f840f0792d1f903d000b5d6d36e95b
4
+ data.tar.gz: 2746b966bf4d31bb8254fc1a452951a59cdb451c
5
5
  SHA512:
6
- metadata.gz: ca36c2bd7e90bb093adabd289195c197477ef3a89feb6782e46f559054889ee2cd06f08f96dd8849e54bd68c078eff307e23f4e504c2c949d52c341e2954dc14
7
- data.tar.gz: cd854f0f45cf703d7310881c9cf9bf1a91bddd1d628df6ab62a95ff899462984fd88458dc1fa3bfc9815215cab2290c8b74a7c34628910aee15db7a35e12c671
6
+ metadata.gz: 56b3daa7c907ffc0c845bb341d8348201eb486d08729882c574cf9469e7f8c3c314d4a7cd3e9d26338df6c58c6e425f1505e96f122c4fd06bf583862232bb57d
7
+ data.tar.gz: f6613822fafe35ccffa7a85b705395a9646421dabdf6cd1a0d5341b7ab234c9eb035916b1e0a085c8b3b475636a1d1ed6d1a18e565930cb5faa2ff57080aa7f0
data/HISTORY.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.9.0
2
+
3
+ * always chomp '/' from request_path
4
+ * downcase option for Rack::Rewritten::Url
5
+
1
6
  == 0.8.0
2
7
 
3
8
  * introduce the [H] flag to stop translating
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
@@ -1,4 +1,4 @@
1
1
  module Rewritten
2
- VERSION = "0.8.2"
2
+ VERSION = "0.9.0"
3
3
  end
4
4
 
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rewritten
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kai Rubarth