Skip to content

Commit

Permalink
Merge branch 'fix/13'
Browse files Browse the repository at this point in the history
  • Loading branch information
learnjin committed Jun 10, 2015
2 parents f6c294e + 87f62c9 commit d88241f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
4 changes: 4 additions & 0 deletions HISTORY.rdoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
== 0.15.2

* Fixes nested parameters

== 0.15.0

* Support external targets in redirects
Expand Down
5 changes: 2 additions & 3 deletions lib/rack/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def call(env)
if (current_path == req.path_info) or (::Rewritten.base_from(req.path_info) == current_path) or ::Rewritten.has_flag?(path, 'L')
# if this is the current path, rewrite path and parameters
tpath, tparams = split_to_path_params(to)

env['QUERY_STRING'] = Rack::Utils.build_query(tparams.merge(req.params))
env['QUERY_STRING'] = Rack::Utils.build_nested_query(tparams.merge(req.params))
req.path_info = tpath + ::Rewritten.appendix(req.path_info)
@app.call(req.env)
else
Expand All @@ -77,7 +76,7 @@ def call(env)

def split_to_path_params(path_and_query)
path, query_string = path_and_query.split('?').push('')[0..1]
[path, Rack::Utils.parse_query(query_string)]
[path, Rack::Utils.parse_query(query_string)]
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/rewritten/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Rewritten
VERSION = "0.15.1"
VERSION = "0.15.2"
end

26 changes: 16 additions & 10 deletions test/rack/rewritten_url_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def call_args(overrides={})
'rack.input' => '',
'rack.url_scheme' => 'http'}.merge(overrides)
end

def request_url(url, params={})
call_args.merge({'REQUEST_URI' => url, 'PATH_INFO' => url}.merge(params) )
end
Expand Down Expand Up @@ -83,12 +83,12 @@ def request_url(url, params={})

describe "partial translation" do

before do
before do
@request_str = '/foo/baz/with_tail'
@env = request_url(@request_str)
Rewritten.translate_partial = true
end
Rewritten.translate_partial = true
end

after do
Rewritten.translate_partial = false
end
Expand All @@ -104,7 +104,7 @@ def request_url(url, params={})
end

it "must translate partials if enabled" do
Rewritten.translate_partial = true
Rewritten.translate_partial = true
@app.expect :call, [200, {'Content-Type' => 'text/html'},[]], [Hash]
ret = @rack.call @env
@app.verify
Expand All @@ -123,7 +123,7 @@ def request_url(url, params={})
@env['PATH_INFO'].must_equal url
end


it "won't translate segments not by separated by slashes" do
@app.expect :call, [200, {'Content-Type' => 'text/plain'},[""]], [Hash]
ret = @rack.call @env=request_url('/foo/bazzling')
Expand Down Expand Up @@ -151,7 +151,7 @@ def request_url(url, params={})
end

describe "caps behavior" do

it "must diferentiate caps" do
@app.expect :call, [200, {'Content-Type' => 'text/plain'},[""]], [Hash]
ret = @rack.call request_url('/Foo/Bar')
Expand Down Expand Up @@ -240,7 +240,7 @@ def request_url(url, params={})

it "must set PATH_INFO to /products/2" do
@rack.call(@initial_args)
@initial_args['PATH_INFO'].must_equal "/products/2"
@initial_args['PATH_INFO'].must_equal "/products/2"
end

it "must set QUERY_STRING to w=1" do
Expand All @@ -254,9 +254,15 @@ def request_url(url, params={})
@initial_args['QUERY_STRING'].split('&').sort.must_equal ['s=1', 'w=1']
end

it "must merge nested rails style QUERY parameters" do
@initial_args.merge!('QUERY_STRING' => 'x[id]=1')
@rack.call(@initial_args)
@initial_args['QUERY_STRING'].split('&').sort.map{|s| URI.unescape(s)}.must_equal ['w=1', 'x[id]=1']
end


end



end

0 comments on commit d88241f

Please sign in to comment.