joshbuddy-rack-rewrite 0.0.3 → 0.0.4
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.
- data/VERSION.yml +1 -1
- data/lib/rack_rewrite/actions.rb +1 -2
- data/lib/rack_rewrite/condition_set.rb +1 -1
- data/spec/conditions_spec.rb +10 -3
- metadata +2 -2
data/VERSION.yml
CHANGED
data/lib/rack_rewrite/actions.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'rack'
|
2
|
-
require 'cgi'
|
3
2
|
|
4
3
|
module Rack
|
5
4
|
class Rewrite
|
@@ -17,7 +16,7 @@ module Rack
|
|
17
16
|
env = @request.env
|
18
17
|
env['QUERY_STRING'] = case params
|
19
18
|
when Hash
|
20
|
-
|
19
|
+
Rack::Utils.build_query(params)
|
21
20
|
else
|
22
21
|
params
|
23
22
|
end
|
@@ -13,7 +13,7 @@ module Rack
|
|
13
13
|
def satisfied?(env)
|
14
14
|
if conditions
|
15
15
|
|
16
|
-
uri_ok = conditions.key?(:
|
16
|
+
uri_ok = conditions.key?(:path_info) ? conditions[:path_info] === env['PATH_INFO'] : true
|
17
17
|
method_ok = conditions.key?(:method) ? conditions[:method] === env['REQUEST_METHOD'].downcase : true
|
18
18
|
host_ok = conditions.key?(:host) ? conditions[:host] === env['HTTP_HOST'] : true
|
19
19
|
port_ok = conditions.key?(:port) ? conditions[:port] === env['SERVER_PORT'].to_i : true
|
data/spec/conditions_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe "Rack::Rewrite Conditions" do
|
|
8
8
|
env = Rack::MockRequest.env_for('/test', :method => method)
|
9
9
|
app = mock('app')
|
10
10
|
app.should_receive(:call).with(env).and_return([200, {}, ["body"]])
|
11
|
-
Rack::Rewrite.new(app) { on(:method => method) { pass } }.call(env)
|
11
|
+
Rack::Rewrite.new(app) { on(:method => method) { pass }; fail }.call(env)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -16,7 +16,14 @@ describe "Rack::Rewrite Conditions" do
|
|
16
16
|
env = Rack::MockRequest.env_for('/test', :method => 'get')
|
17
17
|
app = mock('app')
|
18
18
|
app.should_receive(:call).with(env).and_return([200, {}, ["body"]])
|
19
|
-
Rack::Rewrite.new(app) { on(:path_info => '/test') { pass } }.call(env)
|
19
|
+
Rack::Rewrite.new(app) { on(:path_info => '/test') { pass }; fail }.call(env)
|
20
|
+
proc { Rack::Rewrite.new(app) { on(:path_info => %r{^/test}) { pass }; fail }.call(Rack::MockRequest.env_for('/badtest', :method => 'get')) }.should raise_error
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should fail on a simple path_info" do
|
24
|
+
env = Rack::MockRequest.env_for('/test', :method => 'get')
|
25
|
+
app = mock('app')
|
26
|
+
proc { Rack::Rewrite.new(app) { on(:path_info => %r{^/test}) { pass }; fail }.call(Rack::MockRequest.env_for('/badtest', :method => 'get')) }.should raise_error
|
20
27
|
end
|
21
28
|
|
22
29
|
it "should detect a param in the query string" do
|
@@ -24,7 +31,7 @@ describe "Rack::Rewrite Conditions" do
|
|
24
31
|
app = mock('app')
|
25
32
|
app.should_receive(:call).with(env).and_return([200, {}, ["body"]])
|
26
33
|
Rack::Rewrite.new(app) { on(:params => {:test => 'helpme'}) { pass } }.call(env)
|
27
|
-
proc { Rack::Rewrite.new(app) { on(:params => {:test => 'helpme2'}) { pass } }.call(env) }.should raise_error
|
34
|
+
proc { Rack::Rewrite.new(app) { on(:params => {:test => 'helpme2'}) { pass }; fail }.call(env) }.should raise_error
|
28
35
|
end
|
29
36
|
|
30
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: joshbuddy-rack-rewrite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Hull
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-18 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|