1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

remove NullRequest and just always pass a request class

This commit is contained in:
Aaron Patterson 2014-05-23 10:09:24 -07:00
parent a6e94547e8
commit 890e0a97fb
2 changed files with 8 additions and 29 deletions

View file

@ -20,37 +20,12 @@ module ActionDispatch
# :nodoc: # :nodoc:
VERSION = '2.0.0' VERSION = '2.0.0'
class NullReq # :nodoc:
attr_reader :env
attr_accessor :path_parameters
def initialize(env)
@env = env
@path_parameters = {}
end
def request_method
env['REQUEST_METHOD']
end
def path_info
env['PATH_INFO']
end
def ip
env['REMOTE_ADDR']
end
def [](k)
env[k]
end
end
attr_reader :request_class, :formatter attr_reader :request_class, :formatter
attr_accessor :routes attr_accessor :routes
def initialize(routes, options) def initialize(routes, options)
@options = options @options = options
@request_class = options[:request_class] || NullReq @request_class = options[:request_class]
@routes = routes @routes = routes
end end

View file

@ -41,7 +41,7 @@ module ActionDispatch
end end
def test_dashes def test_dashes
router = Router.new(routes, {}) router = Router.new(routes, { :request_class => ActionDispatch::Request })
exp = Router::Strexp.new '/foo-bar-baz', {}, ['/.?'] exp = Router::Strexp.new '/foo-bar-baz', {}, ['/.?']
path = Path::Pattern.new exp path = Path::Pattern.new exp
@ -57,7 +57,7 @@ module ActionDispatch
end end
def test_unicode def test_unicode
router = Router.new(routes, {}) router = Router.new(routes, { :request_class => ActionDispatch::Request })
#match the escaped version of /ほげ #match the escaped version of /ほげ
exp = Router::Strexp.new '/%E3%81%BB%E3%81%92', {}, ['/.?'] exp = Router::Strexp.new '/%E3%81%BB%E3%81%92', {}, ['/.?']
@ -113,10 +113,14 @@ module ActionDispatch
assert_equal env.env, klass.env assert_equal env.env, klass.env
end end
class CustomPathRequest < Router::NullReq class CustomPathRequest < ActionDispatch::Request
def path_info def path_info
env['custom.path_info'] env['custom.path_info']
end end
def path_info=(x)
env['custom.path_info'] = x
end
end end
def test_request_class_overrides_path_info def test_request_class_overrides_path_info