pendragon 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/pendragon/padrino/ext/class_methods.rb +24 -20
- data/lib/pendragon/router.rb +1 -1
- data/lib/pendragon/version.rb +1 -1
- data/test/padrino_test.rb +178 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89f0b037692dd728f51329a2cc4df730582d0480
|
4
|
+
data.tar.gz: 20859c54d93fa69ff145d11d052600b60245ffd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7226f8f044f7310cd4de904661c2cfeda0ac66169d691363f905718498db5cae9f44bf4d857f585a1c4547d9b1de8356763ef6e5414245724f4e4a2031063a7
|
7
|
+
data.tar.gz: 80b0c5acd5492211707c5e7c3fd5f0bb3b3fba6adadd5863e641dca640ca544752e5ff7fdfa97ad87a5de58a292f68c7dc3c048bdc3090a8e61dae5e1d524678
|
data/Gemfile.lock
CHANGED
@@ -36,26 +36,21 @@ module Pendragon
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def url(*args)
|
39
|
-
params = args.extract_options!
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
params[:format] = params[:format].to_s unless params[:format].nil?
|
44
|
-
params = value_to_param(params)
|
45
|
-
end
|
46
|
-
url =
|
47
|
-
if params_array.empty?
|
48
|
-
compiled_router.path(name, params)
|
49
|
-
else
|
50
|
-
compiled_router.path(name, *(params_array << params))
|
51
|
-
end
|
52
|
-
rebase_url(url)
|
53
|
-
rescue Pendragon::InvalidRouteException
|
54
|
-
route_error = "route mapping for url(#{name.inspect}) could not be found!"
|
55
|
-
raise ::Padrino::Routing::UnrecognizedException.new(route_error)
|
39
|
+
params = args.extract_options!
|
40
|
+
fragment = params.delete(:fragment) || params.delete(:anchor)
|
41
|
+
path = make_path_with_params(args, value_to_param(params.symbolize_keys))
|
42
|
+
rebase_url(fragment ? path << '#' << fragment : path)
|
56
43
|
end
|
57
44
|
alias :url_for :url
|
58
45
|
|
46
|
+
def make_path_with_params(args, params)
|
47
|
+
names, params_array = args.partition{ |arg| arg.is_a?(Symbol) }
|
48
|
+
name = names[0, 2].join(" ").to_sym
|
49
|
+
compiled_router.path(name, *(params_array << params))
|
50
|
+
rescue Pendragon::InvalidRouteException
|
51
|
+
raise ::Padrino::Routing::UnrecognizedException, "Route mapping for url(#{name.inspect}) could not be found"
|
52
|
+
end
|
53
|
+
|
59
54
|
def recognize_path(path)
|
60
55
|
responses = @router.recognize_path(path)
|
61
56
|
[responses[0], responses[1]]
|
@@ -64,8 +59,8 @@ module Pendragon
|
|
64
59
|
def rebase_url(url)
|
65
60
|
if url.start_with?('/')
|
66
61
|
new_url = ''
|
67
|
-
new_url << conform_uri(uri_root) if defined?(uri_root)
|
68
62
|
new_url << conform_uri(ENV['RACK_BASE_URI']) if ENV['RACK_BASE_URI']
|
63
|
+
new_url << conform_uri(uri_root) if defined?(uri_root)
|
69
64
|
new_url << url
|
70
65
|
else
|
71
66
|
url.blank? ? '/' : url
|
@@ -92,9 +87,11 @@ module Pendragon
|
|
92
87
|
|
93
88
|
route_options = options.dup
|
94
89
|
route_options[:provides] = @_provides if @_provides
|
90
|
+
route_options[:accepts] = @_accepts if @_accepts
|
91
|
+
route_options[:params] = @_params unless @_params.nil? || route_options.include?(:params)
|
95
92
|
|
96
|
-
if allow_disabled_csrf
|
97
|
-
unless route_options
|
93
|
+
if protect_from_csrf && (report_csrf_failure || allow_disabled_csrf)
|
94
|
+
unless route_options.has_key?(:csrf_protection)
|
98
95
|
route_options[:csrf_protection] = true
|
99
96
|
end
|
100
97
|
end
|
@@ -158,6 +155,13 @@ module Pendragon
|
|
158
155
|
def parse_route(path, options, verb)
|
159
156
|
route_options = {}
|
160
157
|
|
158
|
+
if options[:params] == true
|
159
|
+
options.delete(:params)
|
160
|
+
elsif options.include?(:params)
|
161
|
+
options[:params] ||= []
|
162
|
+
options[:params] += options[:with] if options[:with]
|
163
|
+
end
|
164
|
+
|
161
165
|
# We need check if path is a symbol, if that it's a named route.
|
162
166
|
map = options.delete(:map)
|
163
167
|
|
data/lib/pendragon/router.rb
CHANGED
@@ -127,7 +127,7 @@ module Pendragon
|
|
127
127
|
# @return [Array]
|
128
128
|
def recognize_path(path_info)
|
129
129
|
route, params = recognize(Rack::MockRequest.env_for(path_info)).first
|
130
|
-
[route.name, params.inject({}){|hash, (key, value)| hash[key
|
130
|
+
[route.name, params.inject({}){|hash, (key, value)| hash[key] = value; hash }]
|
131
131
|
end
|
132
132
|
|
133
133
|
# Returns an expanded path matched with the conditions as arguments
|
data/lib/pendragon/version.rb
CHANGED
data/test/padrino_test.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require File.expand_path('../../lib/pendragon/padrino', __FILE__)
|
2
2
|
$:.unshift(File.dirname(__FILE__))
|
3
|
+
require 'active_support/core_ext/hash/conversions'
|
3
4
|
require 'helper'
|
4
5
|
|
5
6
|
class FooError < RuntimeError; end
|
@@ -8,6 +9,7 @@ describe "Pendragon::Padrino" do
|
|
8
9
|
setup do
|
9
10
|
Padrino::Application.send(:register, Pendragon::Padrino)
|
10
11
|
Padrino::Rendering::DEFAULT_RENDERING_OPTIONS[:strict_format] = false
|
12
|
+
ENV['RACK_BASE_URI'] = nil
|
11
13
|
end
|
12
14
|
|
13
15
|
should "serve static files with simple cache control" do
|
@@ -824,6 +826,18 @@ describe "Pendragon::Padrino" do
|
|
824
826
|
ENV['RACK_BASE_URI'] = nil
|
825
827
|
end
|
826
828
|
|
829
|
+
it 'should use uri_root and RACK_BASE_URI' do
|
830
|
+
mock_app do
|
831
|
+
controller :foo do
|
832
|
+
get(:bar){ "bar" }
|
833
|
+
end
|
834
|
+
end
|
835
|
+
ENV['RACK_BASE_URI'] = '/base'
|
836
|
+
@app.uri_root = 'testing'
|
837
|
+
assert_equal '/base/testing/foo/bar', @app.url(:foo, :bar)
|
838
|
+
ENV['RACK_BASE_URI'] = nil
|
839
|
+
end
|
840
|
+
|
827
841
|
should 'reset routes' do
|
828
842
|
mock_app do
|
829
843
|
get("/"){ "foo" }
|
@@ -1882,14 +1896,14 @@ describe "Pendragon::Padrino" do
|
|
1882
1896
|
get(:simple, :map => "/simple/:id") { }
|
1883
1897
|
get(:with_format, :with => :id, :provides => :js) { }
|
1884
1898
|
end
|
1885
|
-
assert_equal [:"foo bar", { :id => "fantastic" }], @app.recognize_path(@app.url(:foo, :bar, :id => :fantastic))
|
1886
|
-
assert_equal [:"foo bar", { :id => "18" }], @app.recognize_path(@app.url(:foo, :bar, :id => 18))
|
1887
|
-
assert_equal [:simple, { :id => "bar" }], @app.recognize_path(@app.url(:simple, :id => "bar"))
|
1888
|
-
assert_equal [:simple, { :id => "true" }], @app.recognize_path(@app.url(:simple, :id => true))
|
1889
|
-
assert_equal [:simple, { :id => "9" }], @app.recognize_path(@app.url(:simple, :id => 9))
|
1890
|
-
assert_equal [:with_format, { :id => "bar", :format => "js" }], @app.recognize_path(@app.url(:with_format, :id => "bar", :format => :js))
|
1891
|
-
assert_equal [:with_format, { :id => "true", :format => "js" }], @app.recognize_path(@app.url(:with_format, :id => true, :format => "js"))
|
1892
|
-
assert_equal [:with_format, { :id => "9", :format => "js" }], @app.recognize_path(@app.url(:with_format, :id => 9, :format => :js))
|
1899
|
+
assert_equal [:"foo bar", { :id => "fantastic" }.with_indifferent_access], @app.recognize_path(@app.url(:foo, :bar, :id => :fantastic))
|
1900
|
+
assert_equal [:"foo bar", { :id => "18" }.with_indifferent_access], @app.recognize_path(@app.url(:foo, :bar, :id => 18))
|
1901
|
+
assert_equal [:simple, { :id => "bar" }.with_indifferent_access], @app.recognize_path(@app.url(:simple, :id => "bar"))
|
1902
|
+
assert_equal [:simple, { :id => "true" }.with_indifferent_access], @app.recognize_path(@app.url(:simple, :id => true))
|
1903
|
+
assert_equal [:simple, { :id => "9" }.with_indifferent_access], @app.recognize_path(@app.url(:simple, :id => 9))
|
1904
|
+
assert_equal [:with_format, { :id => "bar", :format => "js" }.with_indifferent_access], @app.recognize_path(@app.url(:with_format, :id => "bar", :format => :js))
|
1905
|
+
assert_equal [:with_format, { :id => "true", :format => "js" }.with_indifferent_access], @app.recognize_path(@app.url(:with_format, :id => true, :format => "js"))
|
1906
|
+
assert_equal [:with_format, { :id => "9", :format => "js" }.with_indifferent_access], @app.recognize_path(@app.url(:with_format, :id => 9, :format => :js))
|
1893
1907
|
end
|
1894
1908
|
|
1895
1909
|
should 'have current_path' do
|
@@ -1939,4 +1953,160 @@ describe "Pendragon::Padrino" do
|
|
1939
1953
|
get '/users//'
|
1940
1954
|
assert_equal 404, status
|
1941
1955
|
end
|
1956
|
+
describe "Padrino::ParamsProtection" do
|
1957
|
+
before do
|
1958
|
+
@teri = { 'name' => 'Teri Bauer', 'position' => 'baby' }
|
1959
|
+
@kim = { 'name' => 'Kim Bauer', 'position' => 'daughter', 'child' => @teri }
|
1960
|
+
@jack = { 'name' => 'Jack Bauer', 'position' => 'terrorist', 'child' => @kim }
|
1961
|
+
@family = { 'name' => 'Bauer', 'persons' => { 1 => @teri, 2 => @kim, 3 => @jack } }
|
1962
|
+
end
|
1963
|
+
|
1964
|
+
it 'should drop all parameters except allowed ones' do
|
1965
|
+
result = nil
|
1966
|
+
mock_app do
|
1967
|
+
post :basic, :params => [ :name ] do
|
1968
|
+
result = params
|
1969
|
+
''
|
1970
|
+
end
|
1971
|
+
end
|
1972
|
+
post '/basic?' + @jack.to_query
|
1973
|
+
assert_equal({ 'name' => @jack['name'] }, result)
|
1974
|
+
end
|
1975
|
+
|
1976
|
+
it 'should preserve original params' do
|
1977
|
+
result = nil
|
1978
|
+
mock_app do
|
1979
|
+
post :basic, :params => [ :name ] do
|
1980
|
+
result = original_params
|
1981
|
+
''
|
1982
|
+
end
|
1983
|
+
end
|
1984
|
+
post '/basic?' + @jack.to_query
|
1985
|
+
assert_equal(@jack, result)
|
1986
|
+
end
|
1987
|
+
|
1988
|
+
it 'should work with recursive data' do
|
1989
|
+
result = nil
|
1990
|
+
mock_app do
|
1991
|
+
post :basic, :params => [ :name, :child => [ :name, :child => [ :name ] ] ] do
|
1992
|
+
result = [params, original_params]
|
1993
|
+
''
|
1994
|
+
end
|
1995
|
+
end
|
1996
|
+
post '/basic?' + @jack.to_query
|
1997
|
+
assert_equal(
|
1998
|
+
[
|
1999
|
+
{ 'name' => @jack['name'], 'child' => { 'name' => @kim['name'], 'child' => { 'name' => @teri['name'] } } },
|
2000
|
+
@jack
|
2001
|
+
],
|
2002
|
+
result
|
2003
|
+
)
|
2004
|
+
end
|
2005
|
+
|
2006
|
+
it 'should be able to process the data' do
|
2007
|
+
result = nil
|
2008
|
+
mock_app do
|
2009
|
+
post :basic, :params => [ :name, :position => proc{ |v| 'anti-'+v } ] do
|
2010
|
+
result = params
|
2011
|
+
''
|
2012
|
+
end
|
2013
|
+
end
|
2014
|
+
post '/basic?' + @jack.to_query
|
2015
|
+
assert_equal({ 'name' => @jack['name'], 'position' => 'anti-terrorist' }, result)
|
2016
|
+
end
|
2017
|
+
|
2018
|
+
it 'should pass :with parameters' do
|
2019
|
+
result = nil
|
2020
|
+
mock_app do
|
2021
|
+
post :basic, :with => [:id, :tag], :params => [ :name ] do
|
2022
|
+
result = params
|
2023
|
+
''
|
2024
|
+
end
|
2025
|
+
end
|
2026
|
+
post '/basic/24/42?' + @jack.to_query
|
2027
|
+
assert_equal({ 'name' => @jack['name'], 'id' => '24', 'tag' => '42' }, result)
|
2028
|
+
end
|
2029
|
+
|
2030
|
+
it 'should understand true or false values' do
|
2031
|
+
result = nil
|
2032
|
+
mock_app do
|
2033
|
+
get :hide, :with => [ :id ], :params => false do
|
2034
|
+
result = params
|
2035
|
+
''
|
2036
|
+
end
|
2037
|
+
get :show, :with => [ :id ], :params => true do
|
2038
|
+
result = params
|
2039
|
+
''
|
2040
|
+
end
|
2041
|
+
end
|
2042
|
+
get '/hide/1?' + @jack.to_query
|
2043
|
+
assert_equal({"id"=>"1"}, result)
|
2044
|
+
get '/show/1?' + @jack.to_query
|
2045
|
+
assert_equal({"id"=>"1"}.merge(@jack), result)
|
2046
|
+
end
|
2047
|
+
|
2048
|
+
it 'should be configurable with controller options' do
|
2049
|
+
result = nil
|
2050
|
+
mock_app do
|
2051
|
+
controller :persons, :params => [ :name ] do
|
2052
|
+
post :create, :params => [ :name, :position ] do
|
2053
|
+
result = params
|
2054
|
+
''
|
2055
|
+
end
|
2056
|
+
post :update, :with => [ :id ] do
|
2057
|
+
result = params
|
2058
|
+
''
|
2059
|
+
end
|
2060
|
+
post :delete, :params => true do
|
2061
|
+
result = params
|
2062
|
+
''
|
2063
|
+
end
|
2064
|
+
post :destroy, :with => [ :id ], :params => false do
|
2065
|
+
result = params
|
2066
|
+
''
|
2067
|
+
end
|
2068
|
+
end
|
2069
|
+
controller :noparam, :params => false do
|
2070
|
+
get :index do
|
2071
|
+
result = params
|
2072
|
+
''
|
2073
|
+
end
|
2074
|
+
end
|
2075
|
+
end
|
2076
|
+
post '/persons/create?' + @jack.to_query
|
2077
|
+
assert_equal({ 'name' => @jack['name'], 'position' => 'terrorist' }, result)
|
2078
|
+
post '/persons/update/1?name=Chloe+O\'Brian&position=hacker'
|
2079
|
+
assert_equal({ 'id' => '1', 'name' => 'Chloe O\'Brian' }, result)
|
2080
|
+
post '/persons/delete?' + @jack.to_query
|
2081
|
+
assert_equal(@jack, result)
|
2082
|
+
post '/persons/destroy/1?' + @jack.to_query
|
2083
|
+
assert_equal({"id"=>"1"}, result)
|
2084
|
+
get '/noparam?a=1;b=2'
|
2085
|
+
assert_equal({}, result)
|
2086
|
+
end
|
2087
|
+
|
2088
|
+
it 'should successfully filter hashes' do
|
2089
|
+
result = nil
|
2090
|
+
mock_app do
|
2091
|
+
post :family, :params => [ :persons => [ :name ] ] do
|
2092
|
+
result = params
|
2093
|
+
''
|
2094
|
+
end
|
2095
|
+
end
|
2096
|
+
post '/family?' + @family.to_query
|
2097
|
+
assert_equal({"persons" => {"3" => {"name" => @jack["name"]}, "2" => {"name" => @kim["name"]}, "1" => {"name" => @teri["name"]}}}, result)
|
2098
|
+
end
|
2099
|
+
|
2100
|
+
it 'should pass arrays' do
|
2101
|
+
result = nil
|
2102
|
+
mock_app do
|
2103
|
+
post :family, :params => [ :names => [] ] do
|
2104
|
+
result = params
|
2105
|
+
''
|
2106
|
+
end
|
2107
|
+
end
|
2108
|
+
post '/family?names[]=Jack&names[]=Kim&names[]=Teri'
|
2109
|
+
assert_equal({"names" => %w[Jack Kim Teri]}, result)
|
2110
|
+
end
|
2111
|
+
end
|
1942
2112
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pendragon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- namusyaka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|