padrino-core 0.13.0.beta2 → 0.13.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9157558167a224779bc75315038e491ff4817df7
4
- data.tar.gz: 7b3b6f87d38b17584c7b4f513279062e262c69ad
3
+ metadata.gz: ada2a90b4ae422b001c76fd0c1975cdc8eb83fb0
4
+ data.tar.gz: f02e786a62c645f53a0c099954a80e21c3123793
5
5
  SHA512:
6
- metadata.gz: 808a48bbb9e9ce5963a80e9ecfca40ec6122f3152efe6aecc150d1a8a6a8c87958b3efc1f3c391c4792fb5169c8d96e223f1783ac908a4a644c3b1ef0d56d060
7
- data.tar.gz: 94db6c26a4c2162e15a550c58fabe704da50f9d3d7adbb0ee479364441ea697828ff7ad25c34ff917143f2ef7de04b2a380f4453d33c8eed4ed953421fba3abb
6
+ metadata.gz: e6e7e61f93b09177a0347b1eff272a91cdacb9d3a55f1b5e65bb9902bcc4c4f6a0fd335f6be3c3b683e8fa2a0c2164bad2dcdfe7e3705b955dd5bd428d12e7d6
7
+ data.tar.gz: ea1d049f1f85e47f84c8b197af9c5e75d0bb21fbca7b867af1ed0c874c84a864cff2ab9952b2aa93203c8f3b8fcb4e5033a16093b8dab875c56febeb1e59c718
@@ -62,6 +62,7 @@ module Padrino
62
62
  set :uri_root, '/'
63
63
  set :public_folder, proc { Padrino.root('public', uri_root) }
64
64
  set :images_path, proc { File.join(public_folder, 'images') }
65
+ set :base_url, 'http://localhost'
65
66
  end
66
67
 
67
68
  def default_security
@@ -344,6 +344,14 @@ module Padrino
344
344
  end
345
345
  alias :url_for :url
346
346
 
347
+ ##
348
+ # Returns absolute url. By default adds 'http://localhost' before generated url.
349
+ # To change that `set :base_url, 'http://example.com'` in your app.
350
+ #
351
+ def absolute_url(*args)
352
+ base_url + url(*args)
353
+ end
354
+
347
355
  def get(path, *args, &block)
348
356
  conditions = @conditions.dup
349
357
  route('GET', path, *args, &block)
@@ -725,8 +733,7 @@ module Padrino
725
733
  if types.include?(accept_format)
726
734
  content_type(accept_format || :html, :charset => 'utf-8')
727
735
  else
728
- halt 406 unless catch_all
729
- false
736
+ catch_all ? true : halt(406)
730
737
  end
731
738
  end
732
739
  end
@@ -972,8 +979,9 @@ module Padrino
972
979
  @route = request.route_obj = route
973
980
  captured_params = captures_from_params(params)
974
981
 
975
- @params.merge!(params) if params.kind_of?(Hash)
976
- @params.merge!(:captures => captured_params) if !captured_params.empty? && route.path.is_a?(Regexp)
982
+ @params.merge!(params) { |key, original, newval| original } unless params.empty?
983
+ @params[:format] = params[:format] if params[:format]
984
+ @params[:captures] = captured_params if !captured_params.empty? && route.path.is_a?(Regexp)
977
985
 
978
986
  filter! :before if first_time
979
987
 
@@ -390,6 +390,7 @@ module Padrino
390
390
  # Flush the entire buffer to the log object.
391
391
  #
392
392
  def flush
393
+ puts @buffer.size if $l
393
394
  return unless @buffer.size > 0
394
395
  @@mutex.synchronize do
395
396
  @log.write(@buffer.join(''))
@@ -73,7 +73,7 @@ module Padrino
73
73
  #
74
74
  def match?(offset, path)
75
75
  current_regexp = @regexps[offset]
76
- return unless current_regexp === path || current_regexp === path[0..-2]
76
+ return unless current_regexp === path || (path.end_with?("/") && current_regexp === path[0..-2])
77
77
  @routes[offset..-1].detect{ |route| Regexp.last_match["_#{route.index}"] }
78
78
  end
79
79
 
@@ -251,18 +251,13 @@ module Padrino
251
251
  #
252
252
  def external_constant?(const)
253
253
  sources = object_sources(const)
254
- begin
255
- if sample = ObjectSpace.each_object(const).first
256
- sources += object_sources(sample)
257
- end
258
- rescue RuntimeError => error # JRuby 1.7.12 fails to ObjectSpace.each_object
259
- raise unless RUBY_PLATFORM =='java' && error.message.start_with?("ObjectSpace is disabled")
260
- end
254
+ # consider methodless constants not external
255
+ return false if sources.empty?
261
256
  !sources.any?{ |source| source.start_with?(Padrino.root) }
262
257
  end
263
258
 
264
259
  ##
265
- # Gets all the sources in which target's class or instance methods are defined.
260
+ # Gets all the sources in which target class is defined.
266
261
  #
267
262
  # Note: Method#source_location is for Ruby 1.9.3+ only.
268
263
  #
@@ -271,7 +266,14 @@ module Padrino
271
266
  target.methods.each do |method_name|
272
267
  next unless method_name.kind_of?(Symbol)
273
268
  method_object = target.method(method_name)
274
- if method_object.owner == (target.class == Class ? target.singleton_class : target.class)
269
+ if method_object.owner == target.singleton_class
270
+ sources << method_object.source_location.first
271
+ end
272
+ end
273
+ target.instance_methods.each do |method_name|
274
+ next unless method_name.kind_of?(Symbol)
275
+ method_object = target.instance_method(method_name)
276
+ if method_object.owner == target
275
277
  sources << method_object.source_location.first
276
278
  end
277
279
  end
@@ -6,7 +6,7 @@
6
6
  #
7
7
  module Padrino
8
8
  # The version constant for the current version of Padrino.
9
- VERSION = '0.13.0.beta2' unless defined?(Padrino::VERSION)
9
+ VERSION = '0.13.0.beta3' unless defined?(Padrino::VERSION)
10
10
 
11
11
  #
12
12
  # The current Padrino version.
@@ -0,0 +1,7 @@
1
+ PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
2
+
3
+ class SystemStealthyClassDemo < Padrino::Application
4
+ set :reload, true
5
+ end
6
+
7
+ Padrino.load!
@@ -0,0 +1,13 @@
1
+ class Boo
2
+ def self.class_method
3
+ "BooClass"
4
+ end
5
+ end
6
+
7
+ class Woo < Boo
8
+ def poo
9
+ end
10
+ end
11
+
12
+ class Soo < Boo
13
+ end
data/test/test_logger.rb CHANGED
@@ -1,3 +1,4 @@
1
+ #coding:utf-8
1
2
  require File.expand_path(File.dirname(__FILE__) + '/helper')
2
3
  require 'logger'
3
4
 
@@ -58,6 +59,14 @@ describe "PadrinoLogger" do
58
59
  assert_match /log via alias/, @log.string
59
60
  end
60
61
 
62
+ it 'should not blow up on mixed or broken encoodings' do
63
+ skip
64
+ setup_logger(:log_level => :error, :auto_flush => false)
65
+ @logger.error "\xD0".force_encoding('BINARY')
66
+ @logger << 'фыв'
67
+ @logger.flush
68
+ end
69
+
61
70
  it 'should log an application' do
62
71
  mock_app do
63
72
  enable :logging
@@ -262,7 +271,7 @@ describe "options :source_location" do
262
271
 
263
272
  it 'should output source_location if :source_location is set to true' do
264
273
  stub_root { Padrino.logger.debug("hello world") }
265
- assert_match /\[test\/test_logger\.rb:264\] hello world/, Padrino.logger.log.string
274
+ assert_match /\[test\/test_logger\.rb:#{__LINE__-1}\] hello world/, Padrino.logger.log.string
266
275
  end
267
276
 
268
277
  it 'should output source_location if file path is relative' do
@@ -109,5 +109,15 @@ describe "SystemReloader" do
109
109
  FileUtils.rm tmp_file
110
110
  end
111
111
  end
112
+
113
+ it 'should not fail with superclass mismatch when reloading descendant classes with no instances' do
114
+ Padrino.clear!
115
+ require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/stealthy/app.rb')
116
+ @app = SystemStealthyClassDemo
117
+ Padrino.mount(SystemStealthyClassDemo).to("/")
118
+ get '/'
119
+ FileUtils.touch File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/stealthy/helpers/stealthy_class_helpers.rb')
120
+ Padrino.reload!
121
+ end
112
122
  end
113
123
  end
data/test/test_routing.rb CHANGED
@@ -436,6 +436,16 @@ describe "Routing" do
436
436
  assert_equal 406, status
437
437
  end
438
438
 
439
+ it 'should provide proper content when :provides is specified and Accept: `*/*` requested' do
440
+ mock_app do
441
+ get(:text, :provides => :text) { "text" }
442
+ end
443
+ header 'Accept', '*/*'
444
+ get "/text"
445
+ assert_equal 200, status
446
+ assert_equal "text", body
447
+ end
448
+
439
449
  it 'should return 404 on file extensions it does not provide and flag is not set' do
440
450
  mock_app do
441
451
  get(:a, :provides => [:html, :js]){ content_type }
@@ -2325,4 +2335,43 @@ describe "Routing" do
2325
2335
  assert ok?
2326
2336
  assert_equal 'bar', body
2327
2337
  end
2338
+
2339
+ it 'should generate urls and absolute urls' do
2340
+ mock_app do
2341
+ get(:index) { settings.url(:index) }
2342
+ get(:absolute) { settings.absolute_url(:absolute) }
2343
+ end
2344
+ get '/'
2345
+ assert_equal '/', body
2346
+ get '/absolute'
2347
+ assert_equal 'http://localhost/absolute', body
2348
+ @app.set :base_url, 'http://example.com'
2349
+ get '/absolute'
2350
+ assert_equal 'http://example.com/absolute', body
2351
+ end
2352
+
2353
+ it 'should not match if route regexps matches with incorrect_path[0..2]' do
2354
+ mock_app do
2355
+ get(:index) { "bork" }
2356
+ get("/foo") { "foo" }
2357
+ end
2358
+ get "/"
2359
+ assert_equal 200, status
2360
+ get "/a"
2361
+ assert_equal 404, status
2362
+ get "/foo"
2363
+ assert_equal 200, status
2364
+ get "/fo"
2365
+ assert_equal 404, status
2366
+ end
2367
+
2368
+ it "should maintain Sinatra's params indifference" do
2369
+ mock_app do
2370
+ get '/update', :with => :id do
2371
+ "#{params[:product]['title']}==#{params[:product][:title]}"
2372
+ end
2373
+ end
2374
+ get '/update/1?product[title]=test'
2375
+ assert_equal 'test==test', body
2376
+ end
2328
2377
  end
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.13.0.beta2
4
+ version: 0.13.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-04-11 00:00:00.000000000 Z
14
+ date: 2015-08-02 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: padrino-support
@@ -19,14 +19,14 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 0.13.0.beta2
22
+ version: 0.13.0.beta3
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.13.0.beta2
29
+ version: 0.13.0.beta3
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: sinatra
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -177,6 +177,8 @@ files:
177
177
  - test/fixtures/apps/precompiled_app.rb
178
178
  - test/fixtures/apps/simple.rb
179
179
  - test/fixtures/apps/static.rb
180
+ - test/fixtures/apps/stealthy/app.rb
181
+ - test/fixtures/apps/stealthy/helpers/stealthy_class_helpers.rb
180
182
  - test/fixtures/apps/system.rb
181
183
  - test/fixtures/apps/system_class_methods_demo.rb
182
184
  - test/fixtures/apps/system_instance_methods_demo.rb
@@ -261,6 +263,8 @@ test_files:
261
263
  - test/fixtures/apps/precompiled_app.rb
262
264
  - test/fixtures/apps/simple.rb
263
265
  - test/fixtures/apps/static.rb
266
+ - test/fixtures/apps/stealthy/app.rb
267
+ - test/fixtures/apps/stealthy/helpers/stealthy_class_helpers.rb
264
268
  - test/fixtures/apps/system.rb
265
269
  - test/fixtures/apps/system_class_methods_demo.rb
266
270
  - test/fixtures/apps/system_instance_methods_demo.rb