padrino-core 0.11.2 → 0.11.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -169,7 +169,7 @@ module Padrino
169
169
 
170
170
  ##
171
171
  # Registers a gem with padrino. This relieves the caller from setting up
172
- # loadpaths by himself and enables Padrino to look up apps in gem folder.
172
+ # loadpaths by itself and enables Padrino to look up apps in gem folder.
173
173
  #
174
174
  # The name given has to be the proper gem name as given in the gemspec.
175
175
  #
@@ -1,10 +1,12 @@
1
1
  begin
2
2
  require 'haml'
3
3
  require 'haml/helpers/xss_mods'
4
+ require 'haml/helpers/action_view_extensions'
4
5
 
5
6
  module Haml
6
7
  module Helpers
7
8
  include XssMods
9
+ include ActionViewExtensions
8
10
  end
9
11
 
10
12
  module Util
@@ -98,6 +98,30 @@ class HttpRouter
98
98
  []
99
99
  end
100
100
  end
101
+
102
+ def to(dest = nil, &dest_block)
103
+ @dest = dest || dest_block || raise("you didn't specify a destination")
104
+
105
+ @router.current_order ||= 0
106
+ @order = @router.current_order
107
+ @router.current_order += 1
108
+
109
+ if @dest.respond_to?(:url_mount=)
110
+ urlmount = UrlMount.new(@path_for_generation, @default_values || {}) # TODO url mount should accept nil here.
111
+ urlmount.url_mount = @router.url_mount if @router.url_mount
112
+ @dest.url_mount = urlmount
113
+ end
114
+ self
115
+ end
116
+
117
+ attr_accessor :order
118
+
119
+ end
120
+
121
+ attr_accessor :current_order
122
+
123
+ def sort!
124
+ @routes.sort!{ |a, b| a.order <=> b.order }
101
125
  end
102
126
 
103
127
  #Monkey patching the Request class. Using Rack::Utils.unescape rather than
@@ -394,7 +418,7 @@ module Padrino
394
418
  #
395
419
  # @example if filters based on a symbol or regexp
396
420
  # before :index, /main/ do; ... end
397
- # # => match oly path that are +/+ or contains +main+
421
+ # # => match only path that are +/+ or contains +main+
398
422
  #
399
423
  # @example filtering everything except an occurency
400
424
  # before :except => :index do; ...; end
@@ -466,6 +490,7 @@ module Padrino
466
490
  else
467
491
  deferred_routes.each { |_, routes| routes.each { |(route, dest)| route.to(dest) } }
468
492
  @deferred_routes = nil
493
+ router.sort!
469
494
  router
470
495
  end
471
496
  end
@@ -909,6 +934,17 @@ module Padrino
909
934
  end
910
935
  alias :url_for :url
911
936
 
937
+ ##
938
+ # Returns absolute url. Calls Sinatra::Helpers#uri to generate protocol version, hostname and port.
939
+ #
940
+ # @example
941
+ # absolute_url(:show, :id => 1) # => http://example.com/show?id=1
942
+ # absolute_url(:show, 24) # => https://example.com/admin/show/24
943
+ #
944
+ def absolute_url( *args )
945
+ uri url(*args), true, false
946
+ end
947
+
912
948
  ##
913
949
  # Returns the recognized path for a route.
914
950
  #
@@ -58,7 +58,7 @@ module Padrino
58
58
  :info => 3,
59
59
  :debug => 0,
60
60
  :devel => -1,
61
- } unless const_defined?(:Levels)
61
+ } unless defined?(Levels)
62
62
 
63
63
  module Extensions
64
64
  ##
@@ -207,13 +207,8 @@ module Padrino
207
207
 
208
208
  include Extensions
209
209
 
210
- attr_accessor :level
211
- attr_accessor :auto_flush
212
- attr_reader :buffer
213
- attr_reader :log
214
- attr_reader :init_args
215
- attr_accessor :log_static
216
- attr_reader :colorize_logging
210
+ attr_accessor :auto_flush, :level, :log_static
211
+ attr_reader :buffer, :colorize_logging, :init_args, :log
217
212
 
218
213
  ##
219
214
  # Configuration for a given environment, possible options are:
@@ -403,7 +398,7 @@ module Padrino
403
398
  env['rack.logger'] = Padrino.logger
404
399
  began_at = Time.now
405
400
  status, header, body = @app.call(env)
406
- log(env, status, header, began_at)
401
+ log(env, status, header, began_at) if logger.debug?
407
402
  [status, header, body]
408
403
  end
409
404
 
@@ -6,7 +6,7 @@
6
6
  #
7
7
  module Padrino
8
8
  # The version constant for the current version of Padrino.
9
- VERSION = '0.11.2' unless defined?(Padrino::VERSION)
9
+ VERSION = '0.11.3' unless defined?(Padrino::VERSION)
10
10
 
11
11
  #
12
12
  # The current Padrino version.
@@ -38,6 +38,6 @@ Gem::Specification.new do |s|
38
38
  end
39
39
  s.add_dependency("http_router", "~> 0.11.0")
40
40
  s.add_dependency("thor", "~> 0.17.0")
41
- s.add_dependency("activesupport", ">= 3.1.0")
41
+ s.add_dependency("activesupport", ">= 3.1", "< 4.0")
42
42
  s.add_dependency("rack-protection", ">= 1.5.0")
43
43
  end
@@ -98,6 +98,35 @@ describe "PadrinoLogger" do
98
98
  Padrino.logger.instance_eval{ @log_static = false }
99
99
  end
100
100
  end
101
+
102
+ context "health-check requests logging" do
103
+ def access_to_mock_app
104
+ mock_app do
105
+ enable :logging
106
+ get("/"){ "Foo" }
107
+ end
108
+ get "/"
109
+ end
110
+
111
+ should 'output under debug level' do
112
+ Padrino.logger.instance_eval{ @level = Padrino::Logger::Levels[:debug] }
113
+ access_to_mock_app
114
+ assert_match /\e\[36m DEBUG\e\[0m/, Padrino.logger.log.string
115
+
116
+ Padrino.logger.instance_eval{ @level = Padrino::Logger::Levels[:devel] }
117
+ access_to_mock_app
118
+ assert_match /\e\[36m DEBUG\e\[0m/, Padrino.logger.log.string
119
+ end
120
+ should 'not output over debug level' do
121
+ Padrino.logger.instance_eval{ @level = Padrino::Logger::Levels[:info] }
122
+ access_to_mock_app
123
+ assert_equal '', Padrino.logger.log.string
124
+
125
+ Padrino.logger.instance_eval{ @level = Padrino::Logger::Levels[:error] }
126
+ access_to_mock_app
127
+ assert_equal '', Padrino.logger.log.string
128
+ end
129
+ end
101
130
  end
102
131
  end
103
132
 
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+
3
+ describe "Rendering Extensions" do
4
+ context 'for haml' do
5
+ should 'render haml_tag correctly' do
6
+ mock_app do
7
+ get('/') { render :haml, '-haml_tag :div'}
8
+ end
9
+
10
+ get '/'
11
+ assert_match '<div></div>', last_response.body
12
+ end
13
+ end
14
+ end
@@ -226,6 +226,28 @@ describe "Routing" do
226
226
  assert_equal 404, status
227
227
  end
228
228
 
229
+ should 'generate absolute urls' do
230
+ mock_app do
231
+ get(:hash, :with => :id){ absolute_url(:hash, :id => 1) }
232
+ end
233
+ get "/hash/2"
234
+ assert_equal "http://example.org/hash/1", body
235
+ get "https://example.org/hash/2"
236
+ assert_equal "https://example.org/hash/1", body
237
+ end
238
+
239
+ should 'generate proper absolute urls for mounted apps' do
240
+ class Test < Padrino::Application
241
+ get :foo do
242
+ absolute_url(:foo, :id => 1)
243
+ end
244
+ end
245
+ Padrino.mount("Test").to("/test")
246
+ @app = Padrino.application
247
+ get('/test/foo')
248
+ assert_equal 'http://example.org/test/foo?id=1', body
249
+ end
250
+
229
251
  should 'allow regex url with format' do
230
252
  mock_app do
231
253
  get(/.*/, :provides => :any) { "regexp" }
@@ -792,7 +814,6 @@ describe "Routing" do
792
814
 
793
815
 
794
816
  should 'respect priorities' do
795
- skip
796
817
  route_order = []
797
818
  mock_app do
798
819
  get(:index, :priority => :normal) { route_order << :normal; pass }
@@ -804,6 +825,19 @@ describe "Routing" do
804
825
  assert_equal "hello", body
805
826
  end
806
827
 
828
+ should 'catch all after controllers' do
829
+ mock_app do
830
+ get(:index, :with => :slug, :priority => :low) { "catch all" }
831
+ controllers :contact do
832
+ get(:index) { "contact"}
833
+ end
834
+ end
835
+ get "/contact"
836
+ assert_equal "contact", body
837
+ get "/foo"
838
+ assert_equal "catch all", body
839
+ end
840
+
807
841
  should 'allow optionals' do
808
842
  mock_app do
809
843
  get(:show, :map => "/stories/:type(/:category)") do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
4
+ version: 0.11.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-05-21 00:00:00.000000000 Z
15
+ date: 2013-07-29 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: tilt
@@ -85,7 +85,10 @@ dependencies:
85
85
  requirements:
86
86
  - - ! '>='
87
87
  - !ruby/object:Gem::Version
88
- version: 3.1.0
88
+ version: '3.1'
89
+ - - <
90
+ - !ruby/object:Gem::Version
91
+ version: '4.0'
89
92
  type: :runtime
90
93
  prerelease: false
91
94
  version_requirements: !ruby/object:Gem::Requirement
@@ -93,7 +96,10 @@ dependencies:
93
96
  requirements:
94
97
  - - ! '>='
95
98
  - !ruby/object:Gem::Version
96
- version: 3.1.0
99
+ version: '3.1'
100
+ - - <
101
+ - !ruby/object:Gem::Version
102
+ version: '4.0'
97
103
  - !ruby/object:Gem::Dependency
98
104
  name: rack-protection
99
105
  requirement: !ruby/object:Gem::Requirement
@@ -205,6 +211,7 @@ files:
205
211
  - test/test_reloader_complex.rb
206
212
  - test/test_reloader_simple.rb
207
213
  - test/test_rendering.rb
214
+ - test/test_rendering_extensions.rb
208
215
  - test/test_restful_routing.rb
209
216
  - test/test_router.rb
210
217
  - test/test_routing.rb
@@ -222,9 +229,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
222
229
  - - ! '>='
223
230
  - !ruby/object:Gem::Version
224
231
  version: '0'
225
- segments:
226
- - 0
227
- hash: 3143622035712023707
228
232
  required_rubygems_version: !ruby/object:Gem::Requirement
229
233
  none: false
230
234
  requirements:
@@ -268,6 +272,7 @@ test_files:
268
272
  - test/test_reloader_complex.rb
269
273
  - test/test_reloader_simple.rb
270
274
  - test/test_rendering.rb
275
+ - test/test_rendering_extensions.rb
271
276
  - test/test_restful_routing.rb
272
277
  - test/test_router.rb
273
278
  - test/test_routing.rb