padrino-core 0.9.16 → 0.9.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,7 +21,7 @@ module Padrino
21
21
  def add_before_filter(filter)
22
22
  @before_filters ||= []
23
23
  @before_filters << filter
24
- arbitrary { |env| catch(:pass) { router.runner.instance_eval(&filter); true } == true }
24
+ arbitrary { |req, ps, dest| catch(:pass) { router.runner.params = ps; router.runner.instance_eval(&filter); true } == true }
25
25
  end
26
26
 
27
27
  def add_after_filter(filter)
@@ -38,7 +38,7 @@ module Padrino
38
38
  end
39
39
 
40
40
  def custom_conditions=(custom_conditions)
41
- custom_conditions.each { |blk| arbitrary { |env| router.runner.instance_eval(&blk) != false } } if custom_conditions
41
+ custom_conditions.each { |blk| arbitrary { |req, params, dest| router.runner.instance_eval(&blk) != false } } if custom_conditions
42
42
  @custom_conditions = custom_conditions
43
43
  end
44
44
  end
@@ -240,6 +240,7 @@ module Padrino
240
240
  names, params_array = args.partition{|a| a.is_a?(Symbol)}
241
241
  name = names.join("_").to_sym # route name is concatenated with underscores
242
242
  if params.is_a?(Hash)
243
+ params.delete_if { |k,v| v.nil? }
243
244
  params[:format] = params[:format].to_s if params.has_key?(:format)
244
245
  params.each { |k,v| params[k] = v.to_param if v.respond_to?(:to_param) }
245
246
  end
@@ -367,8 +368,8 @@ module Padrino
367
368
  route.use_layout = @layout
368
369
  route.controller = Array(@_controller).first.to_s
369
370
  else
370
- route.before_filters = []
371
- route.after_filters = []
371
+ route.before_filters = @before_filters || []
372
+ route.after_filters = @after_filters || []
372
373
  end
373
374
 
374
375
  route.to(block)
@@ -394,7 +395,7 @@ module Padrino
394
395
 
395
396
  if path.kind_of?(Symbol) # path i.e :index or :show
396
397
  name = path # The route name
397
- path = map || path.to_s # The route path
398
+ path = map ? map.dup : path.to_s # The route path
398
399
  end
399
400
 
400
401
  if path.kind_of?(String) # path i.e "/index" or "/show"
@@ -413,9 +414,11 @@ module Padrino
413
414
  # Build our controller
414
415
  controller = Array(@_controller).collect { |c| c.to_s }
415
416
 
417
+ absolute_map = map && map[0] == ?/
418
+
416
419
  unless controller.empty?
417
420
  # Now we need to add our controller path only if not mapped directly
418
- if map.blank?
421
+ if map.blank? and !absolute_map
419
422
  controller_path = controller.join("/")
420
423
  path.gsub!(%r{^\(/\)|/\?}, "")
421
424
  path = File.join(controller_path, path)
@@ -428,13 +431,13 @@ module Padrino
428
431
  end
429
432
 
430
433
  # Now we need to parse our 'parent' params and parent scope
431
- if parent_params = options.delete(:parent) || @_parents
434
+ if !absolute_map and parent_params = options.delete(:parent) || @_parents
432
435
  parent_params = Array(@_parents) + Array(parent_params)
433
436
  path = process_path_for_parent_params(path, parent_params)
434
437
  end
435
438
 
436
439
  # Add any controller level map to the front of the path
437
- path = "#{@_map}/#{path}".squeeze('/') unless @_map.blank?
440
+ path = "#{@_map}/#{path}".squeeze('/') unless absolute_map or @_map.blank?
438
441
 
439
442
  # Small reformats
440
443
  path.gsub!(%r{/?index/?}, '') # Remove index path
@@ -5,7 +5,7 @@
5
5
  # without include full padrino core.
6
6
  #
7
7
  module Padrino
8
- VERSION = '0.9.16' unless defined?(Padrino::VERSION)
8
+ VERSION = '0.9.17' unless defined?(Padrino::VERSION)
9
9
  ##
10
10
  # Return the current Padrino version
11
11
  #
data/padrino-core.gemspec CHANGED
@@ -18,8 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.rdoc_options = ["--charset=UTF-8"]
19
19
  s.require_path = "lib"
20
20
  s.add_dependency("sinatra", ">= 1.0.0")
21
- s.add_dependency("http_router", ">= 0.3.16")
22
- s.add_dependency("thor", ">= 0.13.0")
21
+ s.add_dependency("http_router", "~> 0.4.0")
22
+ s.add_dependency("thor", ">=0.14.3")
23
23
  s.add_dependency("activesupport", ">= 3.0.0")
24
24
  s.add_dependency("tzinfo")
25
25
  end
data/test/test_routing.rb CHANGED
@@ -501,6 +501,8 @@ class TestRouting < Test::Unit::TestCase
501
501
  end
502
502
  get "/"
503
503
  assert_equal "index", body
504
+ get @app.url(:admin, :index)
505
+ assert_equal "index", body
504
506
  get "/show/1"
505
507
  assert_equal "show 1", body
506
508
  get "/edit/1/product"
@@ -574,6 +576,9 @@ class TestRouting < Test::Unit::TestCase
574
576
  end
575
577
  end
576
578
 
579
+ assert_equal "/user/1/project", @app.url(:project, :index, :user_id => 1, :shop_id => nil)
580
+ assert_equal "/user/1/shop/23/project", @app.url(:project, :index, :user_id => 1, :shop_id => 23)
581
+
577
582
  user_project_url = "/user/1/project"
578
583
  get user_project_url
579
584
  assert_equal "index 1 ", body
@@ -900,6 +905,30 @@ class TestRouting < Test::Unit::TestCase
900
905
  assert_equal "bar", body
901
906
  end
902
907
 
908
+ should 'ignore nil params' do
909
+ mock_app do
910
+ get(:testing, :provides => [:html, :json]) do
911
+ end
912
+ end
913
+ assert_equal '/testing.html', @app.url(:testing, :format => :html)
914
+ assert_equal '/testing', @app.url(:testing, :format => nil)
915
+ end
916
+
917
+ should 'be able to access params in a before filter' do
918
+ username_from_before_filter = nil
919
+
920
+ mock_app do
921
+ before do
922
+ username_from_before_filter = params[:username]
923
+ end
924
+
925
+ get :users, :with => :username do
926
+ end
927
+ end
928
+ get '/users/josh'
929
+ assert_equal 'josh', username_from_before_filter
930
+ end
931
+
903
932
  should 'work with controller and arbitrary params' do
904
933
  mock_app do
905
934
  get(:testing) { params[:foo] }
@@ -970,6 +999,25 @@ class TestRouting < Test::Unit::TestCase
970
999
  assert_equal "1, 2", body
971
1000
  end
972
1001
 
1002
+ should 'use absolute and relative maps' do
1003
+ mock_app do
1004
+ controller :one do
1005
+ parent :three
1006
+ get :index, :map => 'one' do; end
1007
+ get :index2, :map => '/one' do; end
1008
+ end
1009
+
1010
+ controller :two, :map => 'two' do
1011
+ parent :three
1012
+ get :index, :map => 'two' do; end
1013
+ get :index2, :map => '/two', :with => :id do; end
1014
+ end
1015
+ end
1016
+ assert_equal "/three/three_id/one", @app.url(:one, :index, 'three_id')
1017
+ assert_equal "/one", @app.url(:one, :index2)
1018
+ assert_equal "/two/three/three_id/two", @app.url(:two, :index, 'three_id')
1019
+ assert_equal "/two/four_id", @app.url(:two, :index2, 'four_id')
1020
+ end
973
1021
 
974
1022
  should "work with params and parent options" do
975
1023
  mock_app do
@@ -1,2 +1,2 @@
1
1
  -1
2
- test page again
2
+ test page
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-core
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 16
10
- version: 0.9.16
9
+ - 17
10
+ version: 0.9.17
11
11
  platform: ruby
12
12
  authors:
13
13
  - Padrino Team
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2010-09-24 00:00:00 +02:00
21
+ date: 2010-10-04 00:00:00 +02:00
22
22
  default_executable: padrino
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -43,14 +43,14 @@ dependencies:
43
43
  requirement: &id002 !ruby/object:Gem::Requirement
44
44
  none: false
45
45
  requirements:
46
- - - ">="
46
+ - - ~>
47
47
  - !ruby/object:Gem::Version
48
- hash: 51
48
+ hash: 15
49
49
  segments:
50
50
  - 0
51
- - 3
52
- - 16
53
- version: 0.3.16
51
+ - 4
52
+ - 0
53
+ version: 0.4.0
54
54
  type: :runtime
55
55
  version_requirements: *id002
56
56
  - !ruby/object:Gem::Dependency
@@ -61,12 +61,12 @@ dependencies:
61
61
  requirements:
62
62
  - - ">="
63
63
  - !ruby/object:Gem::Version
64
- hash: 43
64
+ hash: 33
65
65
  segments:
66
66
  - 0
67
- - 13
68
- - 0
69
- version: 0.13.0
67
+ - 14
68
+ - 3
69
+ version: 0.14.3
70
70
  type: :runtime
71
71
  version_requirements: *id003
72
72
  - !ruby/object:Gem::Dependency