From 29f13beda35e30b472c6617fcf3fc5cc22d3468a Mon Sep 17 00:00:00 2001 From: Santiago Pastorino <santiago@wyeworks.com> Date: Sun, 26 Sep 2010 12:06:19 -0300 Subject: port is appended twice to HTTP_HOST when host already has the port --- actionpack/lib/action_dispatch/testing/integration.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 84039c06ab..404b6185c2 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -257,19 +257,19 @@ module ActionDispatch end end - port = host.split(':')[1] + hostname, port = host.split(':') env = { :method => method, :params => parameters, - "SERVER_NAME" => host.split(':')[0], + "SERVER_NAME" => hostname, "SERVER_PORT" => (port ? port : (https? ? "443" : "80")), "HTTPS" => https? ? "on" : "off", "rack.url_scheme" => https? ? "https" : "http", "REQUEST_URI" => path, - "HTTP_HOST" => [host, port].compact.join(':'), + "HTTP_HOST" => host, "REMOTE_ADDR" => remote_addr, "CONTENT_TYPE" => "application/x-www-form-urlencoded", "HTTP_ACCEPT" => accept -- cgit v1.2.3 From db23e321413aedcfb30207da80bfe06a0eb90e8b Mon Sep 17 00:00:00 2001 From: Santiago Pastorino <santiago@wyeworks.com> Date: Sun, 26 Sep 2010 17:43:26 -0300 Subject: Not need to do this double ternary --- actionpack/lib/action_dispatch/testing/integration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 404b6185c2..41729beefb 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -264,7 +264,7 @@ module ActionDispatch :params => parameters, "SERVER_NAME" => hostname, - "SERVER_PORT" => (port ? port : (https? ? "443" : "80")), + "SERVER_PORT" => port || https? ? "443" : "80", "HTTPS" => https? ? "on" : "off", "rack.url_scheme" => https? ? "https" : "http", -- cgit v1.2.3 From 56de4e9a8090e2e617a0d478d38c0fccfce7d725 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino <santiago@wyeworks.com> Date: Sun, 26 Sep 2010 17:54:00 -0300 Subject: Fix the precedence issue here --- actionpack/lib/action_dispatch/testing/integration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 41729beefb..50bdad1b1c 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -264,7 +264,7 @@ module ActionDispatch :params => parameters, "SERVER_NAME" => hostname, - "SERVER_PORT" => port || https? ? "443" : "80", + "SERVER_PORT" => port || (https? ? "443" : "80"), "HTTPS" => https? ? "on" : "off", "rack.url_scheme" => https? ? "https" : "http", -- cgit v1.2.3 From 5d773f8dedef85f3ef5d3bdebcedd72716002268 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Wed, 22 Sep 2010 16:11:15 -0300 Subject: Remove warning "URI.unescape is obsolete" from actionpack. --- actionpack/lib/action_controller/caching/actions.rb | 6 +++++- actionpack/lib/action_controller/caching/pages.rb | 6 +++++- actionpack/lib/action_controller/test_case.rb | 6 +++++- actionpack/lib/action_dispatch/routing/mapper.rb | 18 +++++++++--------- actionpack/lib/action_dispatch/routing/route_set.rb | 12 ++++++++++-- 5 files changed, 34 insertions(+), 14 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index a3591eafbe..e00f4a7b1d 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -161,7 +161,11 @@ module ActionController #:nodoc: def normalize!(path) path << 'index' if path[-1] == ?/ path << ".#{extension}" if extension and !path.ends_with?(extension) - URI.unescape(path) + uri_parser.unescape(path) + end + + def uri_parser + @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI end end end diff --git a/actionpack/lib/action_controller/caching/pages.rb b/actionpack/lib/action_controller/caching/pages.rb index 4f7a5d3f55..b845c6f6f9 100644 --- a/actionpack/lib/action_controller/caching/pages.rb +++ b/actionpack/lib/action_controller/caching/pages.rb @@ -99,7 +99,7 @@ module ActionController #:nodoc: private def page_cache_file(path) - name = (path.empty? || path == "/") ? "/index" : URI.unescape(path.chomp('/')) + name = (path.empty? || path == "/") ? "/index" : uri_parser.unescape(path.chomp('/')) name << page_cache_extension unless (name.split('/').last || name).include? '.' return name end @@ -111,6 +111,10 @@ module ActionController #:nodoc: def instrument_page_cache(name, path) ActiveSupport::Notifications.instrument("#{name}.action_controller", :path => path){ yield } end + + def uri_parser + @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI + end end # Expires the page that was cached with the +options+ as a key. Example: diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index f5ae1c3fff..eeffce1612 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -127,7 +127,11 @@ module ActionController class Result < ::Array #:nodoc: def to_s() join '/' end def self.new_escaped(strings) - new strings.collect {|str| URI.unescape str} + new strings.collect {|str| uri_parser.unescape str} + end + + def uri_parser + @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI end end diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index fe85acb94e..8ddf67c0cf 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -395,10 +395,10 @@ module ActionDispatch # namespace "admin" do # resources :posts, :comments # end - # + # # This will create a number of routes for each of the posts and comments # controller. For Admin::PostsController, Rails will create: - # + # # GET /admin/photos # GET /admin/photos/new # POST /admin/photos @@ -406,33 +406,33 @@ module ActionDispatch # GET /admin/photos/1/edit # PUT /admin/photos/1 # DELETE /admin/photos/1 - # + # # If you want to route /photos (without the prefix /admin) to # Admin::PostsController, you could use - # + # # scope :module => "admin" do # resources :posts, :comments # end # # or, for a single case - # + # # resources :posts, :module => "admin" - # + # # If you want to route /admin/photos to PostsController # (without the Admin:: module prefix), you could use - # + # # scope "/admin" do # resources :posts, :comments # end # # or, for a single case - # + # # resources :posts, :path => "/admin" # # In each of these cases, the named routes remain the same as if you did # not use scope. In the last case, the following paths map to # PostsController: - # + # # GET /admin/photos # GET /admin/photos/new # POST /admin/photos diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 1a5f21bd09..b885a573d5 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -66,7 +66,11 @@ module ActionDispatch end def split_glob_param!(params) - params[@glob_param] = params[@glob_param].split('/').map { |v| URI.unescape(v) } + params[@glob_param] = params[@glob_param].split('/').map { |v| uri_parser.unescape(v) } + end + + def uri_parser + @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI end end @@ -543,7 +547,7 @@ module ActionDispatch params.each do |key, value| if value.is_a?(String) value = value.dup.force_encoding(Encoding::BINARY) if value.encoding_aware? - params[key] = URI.unescape(value) + params[key] = uri_parser.unescape(value) end end @@ -560,6 +564,10 @@ module ActionDispatch end private + def uri_parser + @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI + end + def handle_positional_args(options) return unless args = options.delete(:_positional_args) -- cgit v1.2.3 From 5ced275ac1fc8d52654521bf61742cb7f2f0d796 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Fri, 24 Sep 2010 13:01:31 -0300 Subject: Remove old method before redefining it. --- actionpack/lib/action_dispatch/routing/route_set.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index b885a573d5..ebb9e194c7 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -161,6 +161,7 @@ module ActionDispatch # We use module_eval to avoid leaks @module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1 + remove_method :#{selector} if method_defined?(:#{selector}) def #{selector}(*args) options = args.extract_options! @@ -194,6 +195,7 @@ module ActionDispatch hash_access_method = hash_access_name(name, kind) @module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1 + remove_method :#{selector} if method_defined?(:#{selector}) def #{selector}(*args) url_for(#{hash_access_method}(*args)) end -- cgit v1.2.3 From bb2f53b4090768e4750af66c6fed15d6596bb11c Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Fri, 24 Sep 2010 13:04:51 -0300 Subject: Initialize @as before plural method is called. --- actionpack/lib/action_dispatch/routing/mapper.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 8ddf67c0cf..f6d625e7c3 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -676,6 +676,7 @@ module ActionDispatch DEFAULT_ACTIONS = [:show, :create, :update, :destroy, :new, :edit] def initialize(entities, options) + @as = nil @name = entities.to_s @path = (options.delete(:path) || @name).to_s @controller = (options.delete(:controller) || plural).to_s -- cgit v1.2.3 From b9fa46ca97b448d8cf5b285750341da50d417f8a Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Fri, 24 Sep 2010 15:39:59 -0300 Subject: Initialize @_etag. --- actionpack/lib/action_dispatch/http/response.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index ff5e96fdf7..a5d082c6a2 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -43,6 +43,7 @@ module ActionDispatch # :nodoc: @writer = lambda { |x| @body << x } @block = nil @length = 0 + @_etag = nil @status, @header = status, header self.body = body -- cgit v1.2.3 From 986bad6a3b89fed39c02f87068210f0c74e083cd Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Fri, 24 Sep 2010 15:40:14 -0300 Subject: Remove warning "too many arguments for format string" when interpolating with empty hash. --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index f6d625e7c3..5e95d8ed39 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -350,7 +350,7 @@ module ActionDispatch options = args.last.is_a?(Hash) ? args.pop : {} path = args.shift || block - path_proc = path.is_a?(Proc) ? path : proc { |params| path % params } + path_proc = path.is_a?(Proc) ? path : proc { |params| params.empty? ? path : (path % params) } status = options[:status] || 301 lambda do |env| -- cgit v1.2.3 From cd681681e655b155b8f739d8042389a58be28111 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Fri, 24 Sep 2010 15:41:01 -0300 Subject: Initialize @_routes if it doesn't exists. --- actionpack/lib/action_dispatch/routing/url_for.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index e836cf7c8e..045c9ec77d 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -128,6 +128,7 @@ module ActionDispatch when String options when nil, Hash + @_routes ||= nil _routes.url_for((options || {}).reverse_merge!(url_options).symbolize_keys) else polymorphic_url(options) -- cgit v1.2.3 From 24ef32fe93a701c0b65a0aedf7c361ff3364c42b Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Fri, 24 Sep 2010 15:41:19 -0300 Subject: Ask is @controller is defined to avoid warning. --- actionpack/lib/action_dispatch/testing/assertions/routing.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index c5fed1fc8f..4293ed19e1 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -171,7 +171,7 @@ module ActionDispatch # ROUTES TODO: These assertions should really work in an integration context def method_missing(selector, *args, &block) - if @controller && @routes && @routes.named_routes.helpers.include?(selector) + if defined?(@controller) && @controller && @routes && @routes.named_routes.helpers.include?(selector) @controller.send(selector, *args, &block) else super -- cgit v1.2.3 From 53b91b11ccb18551d6193dc5e96571c24c688e6a Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Fri, 24 Sep 2010 15:41:42 -0300 Subject: Avoid uninitialized variable warning, reuse @integration_session. --- .../lib/action_dispatch/testing/integration.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 50bdad1b1c..3204115e9f 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -182,6 +182,7 @@ module ActionDispatch reset! end + remove_method :default_url_options def default_url_options { :host => host, :protocol => https? ? "https" : "http" } end @@ -319,10 +320,10 @@ module ActionDispatch %w(get post put head delete cookies assigns xml_http_request xhr get_via_redirect post_via_redirect).each do |method| define_method(method) do |*args| - reset! unless @integration_session + reset! unless integration_session # reset the html_document variable, but only for new get/post calls @html_document = nil unless %w(cookies assigns).include?(method) - @integration_session.__send__(method, *args).tap do + integration_session.__send__(method, *args).tap do copy_session_variables! end end @@ -347,7 +348,7 @@ module ActionDispatch # Copy the instance variables from the current session instance into the # test instance. def copy_session_variables! #:nodoc: - return unless @integration_session + return unless integration_session %w(controller response request).each do |var| instance_variable_set("@#{var}", @integration_session.__send__(var)) end @@ -357,21 +358,26 @@ module ActionDispatch include ActionDispatch::Routing::UrlFor def url_options - reset! unless @integration_session - @integration_session.url_options + reset! unless integration_session + integration_session.url_options end # Delegate unhandled messages to the current session instance. def method_missing(sym, *args, &block) - reset! unless @integration_session - if @integration_session.respond_to?(sym) - @integration_session.__send__(sym, *args, &block).tap do + reset! unless integration_session + if integration_session.respond_to?(sym) + integration_session.__send__(sym, *args, &block).tap do copy_session_variables! end else super end end + + private + def integration_session + @integration_session ||= nil + end end end -- cgit v1.2.3 From dafb4bd33ba26bf8ca3455db270fee843c8bd2fd Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Wed, 22 Sep 2010 16:53:02 -0300 Subject: Don't shadow outer local variables. --- actionpack/lib/action_dispatch/testing/test_request.rb | 2 +- actionpack/lib/action_view/testing/resolvers.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/test_request.rb b/actionpack/lib/action_dispatch/testing/test_request.rb index c587a36930..abc2e9afcc 100644 --- a/actionpack/lib/action_dispatch/testing/test_request.rb +++ b/actionpack/lib/action_dispatch/testing/test_request.rb @@ -66,7 +66,7 @@ module ActionDispatch def accept=(mime_types) @env.delete('action_dispatch.request.accepts') - @env['HTTP_ACCEPT'] = Array(mime_types).collect { |mime_types| mime_types.to_s }.join(",") + @env['HTTP_ACCEPT'] = Array(mime_types).collect { |mime_type| mime_type.to_s }.join(",") end def cookies diff --git a/actionpack/lib/action_view/testing/resolvers.rb b/actionpack/lib/action_view/testing/resolvers.rb index 97de2471cf..b2b62528a9 100644 --- a/actionpack/lib/action_view/testing/resolvers.rb +++ b/actionpack/lib/action_view/testing/resolvers.rb @@ -22,10 +22,10 @@ module ActionView #:nodoc: end templates = [] - @hash.select { |k,v| k =~ /^#{query}$/ }.each do |path, source| - handler, format = extract_handler_and_format(path, formats) - templates << Template.new(source, path, handler, - :virtual_path => path, :format => format) + @hash.select { |k,v| k =~ /^#{query}$/ }.each do |_path, source| + handler, format = extract_handler_and_format(_path, formats) + templates << Template.new(source, _path, handler, + :virtual_path => _path, :format => format) end templates.sort_by {|t| -t.identifier.match(/^#{query}$/).captures.reject(&:blank?).size } -- cgit v1.2.3 From 583ddf22a2a9d9f903ff0f2dba72cc04e80a378f Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Wed, 22 Sep 2010 16:47:22 -0300 Subject: Remove more warnings shadowing outer local variable. --- actionpack/lib/action_controller/metal/helpers.rb | 6 +++--- actionpack/lib/action_controller/vendor/html-scanner/html/node.rb | 6 +++--- actionpack/lib/action_dispatch/testing/assertions/selector.rb | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/helpers.rb b/actionpack/lib/action_controller/metal/helpers.rb index 4d5d534c75..f10fc66b52 100644 --- a/actionpack/lib/action_controller/metal/helpers.rb +++ b/actionpack/lib/action_controller/metal/helpers.rb @@ -96,9 +96,9 @@ module ActionController def all_helpers_from_path(path) helpers = [] - Array.wrap(path).each do |path| - extract = /^#{Regexp.quote(path.to_s)}\/?(.*)_helper.rb$/ - helpers += Dir["#{path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1') } + Array.wrap(path).each do |p| + extract = /^#{Regexp.quote(p.to_s)}\/?(.*)_helper.rb$/ + helpers += Dir["#{p}/**/*_helper.rb"].map { |file| file.sub(extract, '\1') } end helpers.sort! helpers.uniq! diff --git a/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb b/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb index 85250721e7..c82324dee6 100644 --- a/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb +++ b/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb @@ -18,12 +18,12 @@ module HTML #:nodoc: hash[k] = Conditions.new(v) when :children hash[k] = v = keys_to_symbols(v) - v.each do |k,v2| - case k + v.each do |key,v2| + case key when :count, :greater_than, :less_than # keys are valid, and require no further processing when :only - v[k] = Conditions.new(v2) + v[key] = Conditions.new(v2) else raise "illegal key #{k.inspect} => #{v2.inspect}" end diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index e1015c62cd..86fba87586 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -513,8 +513,8 @@ module ActionDispatch node.content.gsub(/<!\[CDATA\[(.*)(\]\]>)?/m) { Rack::Utils.escapeHTML($1) } end - selected = elements.map do |element| - text = element.children.select{ |c| not c.tag? }.map{ |c| fix_content[c] }.join + selected = elements.map do |ele| + text = ele.children.select{ |c| not c.tag? }.map{ |c| fix_content[c] }.join root = HTML::Document.new(CGI.unescapeHTML("<encoded>#{text}</encoded>")).root css_select(root, "encoded:root", &block)[0] end -- cgit v1.2.3 From 1ed18fcc91e8e908f26291f6ec9ffbd61e48195f Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Fri, 24 Sep 2010 16:07:01 -0300 Subject: Initialize @cookies. --- actionpack/lib/action_dispatch/testing/test_request.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/test_request.rb b/actionpack/lib/action_dispatch/testing/test_request.rb index abc2e9afcc..cf440a1fad 100644 --- a/actionpack/lib/action_dispatch/testing/test_request.rb +++ b/actionpack/lib/action_dispatch/testing/test_request.rb @@ -13,6 +13,7 @@ module ActionDispatch env = Rails.application.env_config.merge(env) if defined?(Rails.application) super(DEFAULT_ENV.merge(env)) + @cookies = nil self.host = 'test.host' self.remote_addr = '0.0.0.0' self.user_agent = 'Rails Testing' -- cgit v1.2.3 From 74d7664b607a7ca2770c937a832b3339d7bf8203 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Fri, 24 Sep 2010 16:07:17 -0300 Subject: Avoid uninitialized variable warning. --- actionpack/lib/action_view/helpers/date_helper.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 9891478606..3aee4fb773 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -923,6 +923,7 @@ module ActionView private def datetime_selector(options, html_options) datetime = value(object) || default_datetime(options) + @auto_index ||= nil options = options.dup options[:field_name] = @method_name -- cgit v1.2.3 From e7c833fca9c18807245bf1a75cbb212a626e278c Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Fri, 24 Sep 2010 16:07:37 -0300 Subject: Define @emitted_hidden_id if it doesn't exists and reuse it if it does. --- actionpack/lib/action_view/helpers/form_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 3ebc6601e5..8bae6d2796 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1237,7 +1237,7 @@ module ActionView end def emitted_hidden_id? - @emitted_hidden_id + @emitted_hidden_id ||= nil end private -- cgit v1.2.3 From 2f59cd6fd6c54bd55d4cd55f59cae413e961626a Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Fri, 24 Sep 2010 16:08:04 -0300 Subject: Remove method previous method if already defined. --- actionpack/lib/action_view/test_case.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index ff35fb7df4..32fd8c5e21 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -127,6 +127,7 @@ module ActionView def say_no_to_protect_against_forgery! _helpers.module_eval do + remove_method :protect_against_forgery? if method_defined?(:protect_against_forgery?) def protect_against_forgery? false end -- cgit v1.2.3 From d95a16c5263d1fa53914540ee023e9031d884a22 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Fri, 24 Sep 2010 16:52:47 -0300 Subject: Initialize @_request and @_response. --- actionpack/lib/action_controller/metal.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index 96cb5977d5..7fcc4e7211 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -85,6 +85,8 @@ module ActionController def initialize(*) @_headers = {"Content-Type" => "text/html"} @_status = 200 + @_request = nil + @_response = nil super end @@ -99,7 +101,7 @@ module ActionController # Basic implementations for content_type=, location=, and headers are # provided to reduce the dependency on the RackDelegation module # in Renderer and Redirector. - + def content_type=(type) headers["Content-Type"] = type.to_s end -- cgit v1.2.3 From d0621fde885ca0b61c75d0fd0b03bd431d736b42 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Fri, 24 Sep 2010 16:53:06 -0300 Subject: Avoid uninitialized variable warning. --- actionpack/lib/action_controller/test_case.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index eeffce1612..676828957a 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -421,7 +421,7 @@ module ActionController @request.env.delete('PATH_INFO') - if @controller + if defined?(@controller) && @controller @controller.request = @request @controller.params = {} end -- cgit v1.2.3 From c2940a6bf4b101eafc0c9d968f4e702473156613 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Fri, 24 Sep 2010 16:57:28 -0300 Subject: Refactor method to avoid warnings and not run unnecessary code. --- .../action_dispatch/testing/assertions/routing.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index 4293ed19e1..0cdc69760b 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -146,25 +146,25 @@ module ActionDispatch # def with_routing old_routes, @routes = @routes, ActionDispatch::Routing::RouteSet.new - old_controller, @controller = @controller, @controller.clone if @controller - _routes = @routes - - # Unfortunately, there is currently an abstraction leak between AC::Base - # and AV::Base which requires having the URL helpers in both AC and AV. - # To do this safely at runtime for tests, we need to bump up the helper serial - # to that the old AV subclass isn't cached. - # - # TODO: Make this unnecessary - if @controller + if defined?(@controller) && @controller + old_controller, @controller = @controller, @controller.clone + + # Unfortunately, there is currently an abstraction leak between AC::Base + # and AV::Base which requires having the URL helpers in both AC and AV. + # To do this safely at runtime for tests, we need to bump up the helper serial + # to that the old AV subclass isn't cached. + # + # TODO: Make this unnecessary @controller.singleton_class.send(:include, _routes.url_helpers) @controller.view_context_class = Class.new(@controller.view_context_class) do include _routes.url_helpers end end + _routes = @routes yield @routes ensure @routes = old_routes - if @controller + if defined?(@controller) && @controller @controller = old_controller end end -- cgit v1.2.3 From 023c2020b3f94dadb86ead782c07006732d9ab56 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Fri, 24 Sep 2010 17:02:26 -0300 Subject: Initialize @_routes if not defined yet, avoiding more warnings. --- actionpack/lib/action_controller/metal/url_for.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb index 85c6b0a9b5..f43fc3f609 100644 --- a/actionpack/lib/action_controller/metal/url_for.rb +++ b/actionpack/lib/action_controller/metal/url_for.rb @@ -6,6 +6,7 @@ module ActionController def url_options options = {} + @_routes ||= nil if _routes.equal?(env["action_dispatch.routes"]) options[:script_name] = request.script_name.dup end -- cgit v1.2.3 From 50decfbc0e2e58961cc3665710922860d38ee2fb Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Fri, 24 Sep 2010 17:07:54 -0300 Subject: _routes must be inside @controller conditional. --- actionpack/lib/action_dispatch/testing/assertions/routing.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index 0cdc69760b..1390b74a95 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -148,6 +148,7 @@ module ActionDispatch old_routes, @routes = @routes, ActionDispatch::Routing::RouteSet.new if defined?(@controller) && @controller old_controller, @controller = @controller, @controller.clone + _routes = @routes # Unfortunately, there is currently an abstraction leak between AC::Base # and AV::Base which requires having the URL helpers in both AC and AV. @@ -160,7 +161,6 @@ module ActionDispatch include _routes.url_helpers end end - _routes = @routes yield @routes ensure @routes = old_routes -- cgit v1.2.3 From 918dc27345319fbabf25a43bd65b613878b3a66e Mon Sep 17 00:00:00 2001 From: thedarkone <thedarkone2@gmail.com> Date: Mon, 27 Sep 2010 14:50:39 +0200 Subject: Compile ActionController::Base.config's methods to avoid method_missing overhead. --- actionpack/lib/action_controller/railtie.rb | 10 ++++++++++ actionpack/lib/action_view/base.rb | 3 +-- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index aea28d9265..4c57d82f1c 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -26,6 +26,10 @@ module ActionController options.stylesheets_dir ||= paths.public.stylesheets.to_a.first options.page_cache_directory ||= paths.public.to_a.first + # make sure readers methods get compiled + options.asset_path ||= nil + options.asset_host ||= nil + ActiveSupport.on_load(:action_controller) do include app.routes.mounted_helpers extend ::AbstractController::Railties::RoutesHelpers.with(app.routes) @@ -33,5 +37,11 @@ module ActionController options.each { |k,v| send("#{k}=", v) } end end + + config.after_initialize do + ActiveSupport.on_load(:action_controller) do + config.crystalize! if config.respond_to?(:crystalize!) + end + end end end diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 3fa46d0f43..0bef3e3a08 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -209,8 +209,7 @@ module ActionView #:nodoc: @_request = controller.request if controller.respond_to?(:request) end - config = controller && controller.respond_to?(:config) ? controller.config : {} - @_config = ActiveSupport::InheritableOptions.new(config) + @_config = controller && controller.respond_to?(:config) ? controller.config.inheritable_copy : {} @_content_for = Hash.new { |h,k| h[k] = ActiveSupport::SafeBuffer.new } @_virtual_path = nil -- cgit v1.2.3 From 05e53b4c1a3422131f73598848b0332cdc793f69 Mon Sep 17 00:00:00 2001 From: thedarkone <thedarkone2@gmail.com> Date: Wed, 22 Sep 2010 20:18:05 +0200 Subject: Optimize relative_url_root rewriting code. --- actionpack/lib/action_view/helpers/asset_tag_helper.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 687cb83d75..bf57321e86 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -718,6 +718,10 @@ module ActionView "#{host}#{source}" end + def rewrite_relative_url_root(source, relative_url_root) + relative_url_root && !source.starts_with?("#{relative_url_root}/") ? "#{relative_url_root}#{source}" : source + end + # Add the the extension +ext+ if not present. Return full URLs otherwise untouched. # Prefix with <tt>/dir/</tt> if lacking a leading +/+. Account for relative URL # roots. Rewrite the asset path for cache-busting asset ids. Include @@ -733,9 +737,7 @@ module ActionView source = rewrite_asset_path(source, config.asset_path) has_request = controller.respond_to?(:request) - if has_request && include_host && source !~ %r{^#{controller.config.relative_url_root}/} - source = "#{controller.config.relative_url_root}#{source}" - end + source = rewrite_relative_url_root(source, controller.config.relative_url_root) if has_request && include_host source = rewrite_host_and_protocol(source, has_request) if include_host source -- cgit v1.2.3 From 7b2d51817d58336324bce5de422ff82fcab8e18a Mon Sep 17 00:00:00 2001 From: thedarkone <thedarkone2@gmail.com> Date: Wed, 22 Sep 2010 22:38:13 +0200 Subject: Make asset extension rewriting faster. --- actionpack/lib/action_view/helpers/asset_tag_helper.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index bf57321e86..7576177392 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -705,9 +705,15 @@ module ActionView private - def rewrite_extension?(source, dir, ext) - source_ext = File.extname(source)[1..-1] - ext && (source_ext.blank? || (ext != source_ext && File.exist?(File.join(config.assets_dir, dir, "#{source}.#{ext}")))) + def rewrite_extension(source, dir, ext) + source_ext = File.extname(source) + + if source_ext.empty? + "#{source}.#{ext}" + elsif ext != source_ext[1..-1] + with_ext = "#{source}.#{ext}" + with_ext if File.exist?(File.join(config.assets_dir, dir, with_ext)) + end || source end def rewrite_host_and_protocol(source, has_request) @@ -729,8 +735,8 @@ module ActionView def compute_public_path(source, dir, ext = nil, include_host = true) return source if is_uri?(source) - source += ".#{ext}" if rewrite_extension?(source, dir, ext) - source = "/#{dir}/#{source}" unless source[0] == ?/ + source = rewrite_extension(source, dir, ext) if ext + source = "/#{dir}/#{source}" unless source[0] == ?/ if controller.respond_to?(:env) && controller.env["action_dispatch.asset_path"] source = rewrite_asset_path(source, controller.env["action_dispatch.asset_path"]) end -- cgit v1.2.3 From 86bcccf8dfced5e9428407a71f02c1dcc186f2ba Mon Sep 17 00:00:00 2001 From: thedarkone <thedarkone2@gmail.com> Date: Thu, 23 Sep 2010 18:08:43 +0200 Subject: No need to create a separate lambda for each call. --- .../lib/action_dispatch/routing/route_set.rb | 29 +++++++++++----------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 1a5f21bd09..60b1342d55 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -334,6 +334,19 @@ module ActionDispatch end class Generator #:nodoc: + PARAMETERIZE = { + :parameterize => lambda do |name, value| + if name == :controller + value + elsif value.is_a?(Array) + value.map { |v| Rack::Mount::Utils.escape_uri(v.to_param) }.join('/') + else + return nil unless param = value.to_param + param.split('/').map { |v| Rack::Mount::Utils.escape_uri(v) }.join("/") + end + end + } + attr_reader :options, :recall, :set, :named_route def initialize(options, recall, set, extras = false) @@ -422,7 +435,7 @@ module ActionDispatch end def generate - path, params = @set.set.generate(:path_info, named_route, options, recall, opts) + path, params = @set.set.generate(:path_info, named_route, options, recall, PARAMETERIZE) raise_routing_error unless path @@ -436,20 +449,6 @@ module ActionDispatch raise_routing_error end - def opts - parameterize = lambda do |name, value| - if name == :controller - value - elsif value.is_a?(Array) - value.map { |v| Rack::Mount::Utils.escape_uri(v.to_param) }.join('/') - else - return nil unless param = value.to_param - param.split('/').map { |v| Rack::Mount::Utils.escape_uri(v) }.join("/") - end - end - {:parameterize => parameterize} - end - def raise_routing_error raise ActionController::RoutingError.new("No route matches #{options.inspect}") end -- cgit v1.2.3 From 8fdb34b2373b13eee24a403a3af398cddb2a5ad0 Mon Sep 17 00:00:00 2001 From: thedarkone <thedarkone2@gmail.com> Date: Mon, 27 Sep 2010 15:11:19 +0200 Subject: Cache url_options on a per-request basis. --- actionpack/lib/action_controller/metal/url_for.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb index 85c6b0a9b5..ef1071bb3d 100644 --- a/actionpack/lib/action_controller/metal/url_for.rb +++ b/actionpack/lib/action_controller/metal/url_for.rb @@ -5,16 +5,18 @@ module ActionController include AbstractController::UrlFor def url_options - options = {} - if _routes.equal?(env["action_dispatch.routes"]) - options[:script_name] = request.script_name.dup - end + @_url_options ||= begin + options = {} + if _routes.equal?(env["action_dispatch.routes"]) + options[:script_name] = request.script_name.dup + end - super.merge(options).reverse_merge( - :host => request.host_with_port, - :protocol => request.protocol, - :_path_segments => request.symbolized_path_parameters - ) + super.merge(options).reverse_merge( + :host => request.host_with_port, + :protocol => request.protocol, + :_path_segments => request.symbolized_path_parameters + ).freeze + end end end end -- cgit v1.2.3 From e12e2fb4f660da479110b35b375694bf267aedfb Mon Sep 17 00:00:00 2001 From: thedarkone <thedarkone2@gmail.com> Date: Mon, 27 Sep 2010 17:37:40 +0200 Subject: Cache 2 of Request's commonly called methods. --- actionpack/lib/action_dispatch/http/url.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/http/url.rb b/actionpack/lib/action_dispatch/http/url.rb index 2e39d0dbc2..3e5cd6a2f9 100644 --- a/actionpack/lib/action_dispatch/http/url.rb +++ b/actionpack/lib/action_dispatch/http/url.rb @@ -15,12 +15,12 @@ module ActionDispatch # Returns 'https://' if this is an SSL request and 'http://' otherwise. def protocol - ssl? ? 'https://' : 'http://' + @protocol ||= ssl? ? 'https://' : 'http://' end # Is this an SSL request? def ssl? - @env['HTTPS'] == 'on' || @env['HTTP_X_FORWARDED_PROTO'] == 'https' + @ssl ||= @env['HTTPS'] == 'on' || @env['HTTP_X_FORWARDED_PROTO'] == 'https' end # Returns the \host for this request, such as "example.com". -- cgit v1.2.3 From 7cee1587f14638e61a33d12114a0d5ae2620d62b Mon Sep 17 00:00:00 2001 From: thedarkone <thedarkone2@gmail.com> Date: Sat, 25 Sep 2010 16:15:21 +0200 Subject: options[:action] is very likely to be nil. --- actionpack/lib/action_dispatch/routing/polymorphic_routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb index 02ba5236ee..eaef09d445 100644 --- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb @@ -105,7 +105,7 @@ module ActionDispatch else [ record_or_hash_or_array ] end - inflection = if options[:action].to_s == "new" + inflection = if options[:action] && options[:action].to_s == "new" args.pop :singular elsif (record.respond_to?(:persisted?) && !record.persisted?) -- cgit v1.2.3 From e1bccc5169ba18238aa0bde720384efc74c533b0 Mon Sep 17 00:00:00 2001 From: thedarkone <thedarkone2@gmail.com> Date: Sat, 25 Sep 2010 16:40:53 +0200 Subject: Simple .empty? test will do fine here (rails_asset_id returns nice strings). --- actionpack/lib/action_view/helpers/asset_tag_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 7576177392..59d1c8b7eb 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -810,7 +810,7 @@ module ActionView end asset_id = rails_asset_id(source) - if asset_id.blank? + if asset_id.empty? source else source + "?#{asset_id}" -- cgit v1.2.3 From 70357666bc86629c8d10501209105b144855ddbc Mon Sep 17 00:00:00 2001 From: thedarkone <thedarkone2@gmail.com> Date: Sat, 25 Sep 2010 16:42:35 +0200 Subject: Do a single string interpolation. --- actionpack/lib/action_view/helpers/asset_tag_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 59d1c8b7eb..efd238c692 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -813,7 +813,7 @@ module ActionView if asset_id.empty? source else - source + "?#{asset_id}" + "#{source}?#{asset_id}" end end -- cgit v1.2.3 From 5b81d1f3ef1f1b06495eadcc1c2d110d76ac1de3 Mon Sep 17 00:00:00 2001 From: thedarkone <thedarkone2@gmail.com> Date: Mon, 27 Sep 2010 17:42:32 +0200 Subject: Hash#empty? is faster than Enumerable#any? when used on a Hash. --- actionpack/lib/action_dispatch/routing/route_set.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 60b1342d55..eeec10a403 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -443,7 +443,7 @@ module ActionDispatch return [path, params.keys] if @extras - path << "?#{params.to_query}" if params.any? + path << "?#{params.to_query}" unless params.empty? path rescue Rack::Mount::RoutingError raise_routing_error -- cgit v1.2.3 From 7d9f605f8072ef473e2c30800b91493b56af5b2b Mon Sep 17 00:00:00 2001 From: thedarkone <thedarkone2@gmail.com> Date: Sun, 26 Sep 2010 14:04:51 +0200 Subject: Clean up url_for. --- actionpack/lib/action_view/helpers/url_helper.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index f8147840ed..8d1def05de 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -95,7 +95,7 @@ module ActionView # # => javascript:history.back() def url_for(options = {}) options ||= {} - url = case options + case options when String options when Hash @@ -106,8 +106,6 @@ module ActionView else polymorphic_path(options) end - - url end # Creates a link tag of the given +name+ using a URL created by the set -- cgit v1.2.3 From dcabc6c04301a44d875447e4f88534ca04a538d6 Mon Sep 17 00:00:00 2001 From: thedarkone <thedarkone2@gmail.com> Date: Sun, 26 Sep 2010 14:24:48 +0200 Subject: Remove dead code. --- actionpack/lib/action_view/helpers/url_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 8d1def05de..98ea75502f 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -591,9 +591,9 @@ module ActionView html_options['data-remote'] = 'true' end - confirm = html_options.delete("confirm") - method, href = html_options.delete("method"), html_options['href'] + confirm = html_options.delete('confirm') + method = html_options.delete('method') add_confirm_to_attributes!(html_options, confirm) if confirm add_method_to_attributes!(html_options, method) if method -- cgit v1.2.3 From b127e0cac97886d9fcaaea7b91f88becd2fcff2c Mon Sep 17 00:00:00 2001 From: thedarkone <thedarkone2@gmail.com> Date: Mon, 27 Sep 2010 17:43:27 +0200 Subject: Performance: refactor convert_options_to_data_attributes. --- actionpack/lib/action_view/helpers/url_helper.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 98ea75502f..1c3ca78d28 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -584,20 +584,24 @@ module ActionView private def convert_options_to_data_attributes(options, html_options) - html_options = {} if html_options.nil? - html_options = html_options.stringify_keys + if html_options.nil? + link_to_remote_options?(options) ? {'data-remote' => 'true'} : {} + else + html_options = html_options.stringify_keys + html_options['data-remote'] = 'true' if link_to_remote_options?(options) || link_to_remote_options?(html_options) - if (options.is_a?(Hash) && options.key?('remote') && options.delete('remote')) || (html_options.is_a?(Hash) && html_options.key?('remote') && html_options.delete('remote')) - html_options['data-remote'] = 'true' - end + confirm = html_options.delete('confirm') + method = html_options.delete('method') + add_confirm_to_attributes!(html_options, confirm) if confirm + add_method_to_attributes!(html_options, method) if method - confirm = html_options.delete('confirm') - method = html_options.delete('method') - add_confirm_to_attributes!(html_options, confirm) if confirm - add_method_to_attributes!(html_options, method) if method + html_options + end + end - html_options + def link_to_remote_options?(options) + options.is_a?(Hash) && options.key?('remote') && options.delete('remote') end def add_confirm_to_attributes!(html_options, confirm) -- cgit v1.2.3 From bb47927d914480218b003d322c8e8ebcd388093e Mon Sep 17 00:00:00 2001 From: thedarkone <thedarkone2@gmail.com> Date: Mon, 27 Sep 2010 17:44:11 +0200 Subject: Convert unless/else into if/else. --- actionpack/lib/action_dispatch/routing/polymorphic_routes.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb index eaef09d445..49e237f8db 100644 --- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb @@ -168,10 +168,7 @@ module ActionDispatch end def build_named_route_call(records, inflection, options = {}) - unless records.is_a?(Array) - record = extract_record(records) - route = [] - else + if records.is_a?(Array) record = records.pop route = records.map do |parent| if parent.is_a?(Symbol) || parent.is_a?(String) @@ -180,6 +177,9 @@ module ActionDispatch ActiveModel::Naming.route_key(parent).singularize end end + else + record = extract_record(records) + route = [] end if record.is_a?(Symbol) || record.is_a?(String) -- cgit v1.2.3 From dc09cc055ab79ec8181ec4089449c94759700e51 Mon Sep 17 00:00:00 2001 From: thedarkone <thedarkone2@gmail.com> Date: Sun, 26 Sep 2010 14:45:27 +0200 Subject: Assume compute_asset_host returns reasonable values. --- actionpack/lib/action_view/helpers/asset_tag_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index efd238c692..c1dfbe5dc3 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -718,7 +718,7 @@ module ActionView def rewrite_host_and_protocol(source, has_request) host = compute_asset_host(source) - if has_request && host.present? && !is_uri?(host) + if has_request && host && !is_uri?(host) host = "#{controller.request.protocol}#{host}" end "#{host}#{source}" -- cgit v1.2.3 From 6067d1620075c1c311bbae01993453cd80967804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Mon, 27 Sep 2010 20:42:02 +0200 Subject: Call it compile_methods! and do the same on AM. --- actionpack/lib/action_controller/railtie.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index 4c57d82f1c..0ade42ba2d 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -38,9 +38,9 @@ module ActionController end end - config.after_initialize do + initializer "action_controller.compile_config_methods" do ActiveSupport.on_load(:action_controller) do - config.crystalize! if config.respond_to?(:crystalize!) + config.compile_methods! if config.respond_to?(:compile_methods!) end end end -- cgit v1.2.3 From 8aa3684e07db81244c61c9ac98347831a976666b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Mon, 27 Sep 2010 21:14:18 +0200 Subject: Do not cache the script name outcome. --- actionpack/lib/action_controller/metal/url_for.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb index ef1071bb3d..333eeaeffb 100644 --- a/actionpack/lib/action_controller/metal/url_for.rb +++ b/actionpack/lib/action_controller/metal/url_for.rb @@ -5,17 +5,19 @@ module ActionController include AbstractController::UrlFor def url_options - @_url_options ||= begin - options = {} - if _routes.equal?(env["action_dispatch.routes"]) + @_url_options ||= super.reverse_merge( + :host => request.host_with_port, + :protocol => request.protocol, + :_path_segments => request.symbolized_path_parameters + ).freeze + + if _routes.equal?(env["action_dispatch.routes"]) + @_url_options.dup.tap do |options| options[:script_name] = request.script_name.dup + options.freeze end - - super.merge(options).reverse_merge( - :host => request.host_with_port, - :protocol => request.protocol, - :_path_segments => request.symbolized_path_parameters - ).freeze + else + @_url_options end end end -- cgit v1.2.3 From 2f326b7f27349b933fe617d83b3f80c6573ce5d8 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Mon, 27 Sep 2010 15:13:11 -0300 Subject: Remove warning "URI.unescape is obsolete" from actionpack. Signed-off-by: Santiago Pastorino <santiago@wyeworks.com> --- actionpack/lib/action_controller.rb | 1 + actionpack/lib/action_controller/caching/actions.rb | 6 ++---- actionpack/lib/action_controller/caching/pages.rb | 3 ++- actionpack/lib/action_controller/test_case.rb | 4 ---- actionpack/lib/action_controller/uri_parser.rb | 9 +++++++++ actionpack/lib/action_dispatch/routing/route_set.rb | 6 ++---- 6 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 actionpack/lib/action_controller/uri_parser.rb (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index e02578eafd..787439db87 100644 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -8,6 +8,7 @@ module ActionController autoload :Caching autoload :Metal autoload :Middleware + autoload :UriParser autoload_under "metal" do autoload :Compatibility diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index e00f4a7b1d..cd352f69fc 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -141,6 +141,8 @@ module ActionController #:nodoc: end class ActionCachePath + include UriParser + attr_reader :path, :extension # If +infer_extension+ is true, the cache path extension is looked up from the request's @@ -163,10 +165,6 @@ module ActionController #:nodoc: path << ".#{extension}" if extension and !path.ends_with?(extension) uri_parser.unescape(path) end - - def uri_parser - @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI - end end end end diff --git a/actionpack/lib/action_controller/caching/pages.rb b/actionpack/lib/action_controller/caching/pages.rb index b845c6f6f9..f0e00718ac 100644 --- a/actionpack/lib/action_controller/caching/pages.rb +++ b/actionpack/lib/action_controller/caching/pages.rb @@ -1,5 +1,4 @@ require 'fileutils' -require 'uri' require 'active_support/core_ext/class/attribute_accessors' module ActionController #:nodoc: @@ -58,6 +57,8 @@ module ActionController #:nodoc: end module ClassMethods + include UriParser + # Expires the page that was cached with the +path+ as a key. Example: # expire_page "/lists/show" def expire_page(path) diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 676828957a..f1ff57f0cb 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -129,10 +129,6 @@ module ActionController def self.new_escaped(strings) new strings.collect {|str| uri_parser.unescape str} end - - def uri_parser - @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI - end end def assign_parameters(routes, controller_path, action, parameters = {}) diff --git a/actionpack/lib/action_controller/uri_parser.rb b/actionpack/lib/action_controller/uri_parser.rb new file mode 100644 index 0000000000..8e2a3f69eb --- /dev/null +++ b/actionpack/lib/action_controller/uri_parser.rb @@ -0,0 +1,9 @@ +require 'uri' + +module ActionController #:nodoc: + module UriParser + def uri_parser + @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI + end + end +end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index a203ee5934..4289e78641 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -5,6 +5,8 @@ require 'active_support/core_ext/object/to_query' module ActionDispatch module Routing class RouteSet #:nodoc: + include ActionController::UriParser + PARAMETERS_KEY = 'action_dispatch.request.path_parameters' class Dispatcher #:nodoc: @@ -68,10 +70,6 @@ module ActionDispatch def split_glob_param!(params) params[@glob_param] = params[@glob_param].split('/').map { |v| uri_parser.unescape(v) } end - - def uri_parser - @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI - end end # A NamedRouteCollection instance is a collection of named routes, and also -- cgit v1.2.3 From 1ab2ab07b5e7c4031c014175887e9f20b8f60a4c Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Mon, 27 Sep 2010 15:18:35 -0300 Subject: Remove more warnings shadowing outer local variable. Signed-off-by: Santiago Pastorino <santiago@wyeworks.com> --- actionpack/lib/action_controller/metal/helpers.rb | 6 +++--- actionpack/lib/action_controller/vendor/html-scanner/html/node.rb | 6 +++--- actionpack/lib/action_dispatch/testing/assertions/selector.rb | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/helpers.rb b/actionpack/lib/action_controller/metal/helpers.rb index f10fc66b52..d14831b763 100644 --- a/actionpack/lib/action_controller/metal/helpers.rb +++ b/actionpack/lib/action_controller/metal/helpers.rb @@ -96,9 +96,9 @@ module ActionController def all_helpers_from_path(path) helpers = [] - Array.wrap(path).each do |p| - extract = /^#{Regexp.quote(p.to_s)}\/?(.*)_helper.rb$/ - helpers += Dir["#{p}/**/*_helper.rb"].map { |file| file.sub(extract, '\1') } + Array.wrap(path).each do |_path| + extract = /^#{Regexp.quote(_path.to_s)}\/?(.*)_helper.rb$/ + helpers += Dir["#{_path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1') } end helpers.sort! helpers.uniq! diff --git a/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb b/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb index c82324dee6..22b3243104 100644 --- a/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb +++ b/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb @@ -18,14 +18,14 @@ module HTML #:nodoc: hash[k] = Conditions.new(v) when :children hash[k] = v = keys_to_symbols(v) - v.each do |key,v2| + v.each do |key,value| case key when :count, :greater_than, :less_than # keys are valid, and require no further processing when :only - v[key] = Conditions.new(v2) + v[key] = Conditions.new(value) else - raise "illegal key #{k.inspect} => #{v2.inspect}" + raise "illegal key #{key.inspect} => #{value.inspect}" end end else diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index 86fba87586..353be10d20 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -513,8 +513,8 @@ module ActionDispatch node.content.gsub(/<!\[CDATA\[(.*)(\]\]>)?/m) { Rack::Utils.escapeHTML($1) } end - selected = elements.map do |ele| - text = ele.children.select{ |c| not c.tag? }.map{ |c| fix_content[c] }.join + selected = elements.map do |_element| + text = _element.children.select{ |c| not c.tag? }.map{ |c| fix_content[c] }.join root = HTML::Document.new(CGI.unescapeHTML("<encoded>#{text}</encoded>")).root css_select(root, "encoded:root", &block)[0] end -- cgit v1.2.3 From 8adb24016d76a2257b79f4566de66e1b88e56c71 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Mon, 27 Sep 2010 16:17:32 -0300 Subject: Define @_routes inside method, makes more sense and will be initialized when called anywhere. Signed-off-by: Santiago Pastorino <santiago@wyeworks.com> --- actionpack/lib/action_dispatch/routing/route_set.rb | 2 +- actionpack/lib/action_dispatch/routing/url_for.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 4289e78641..66b487ba6d 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -318,7 +318,7 @@ module ActionDispatch singleton_class.send(:define_method, :_routes) { routes } end - define_method(:_routes) { @_routes || routes } + define_method(:_routes) { @_routes ||= nil; @_routes || routes } end helpers diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index 045c9ec77d..e836cf7c8e 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -128,7 +128,6 @@ module ActionDispatch when String options when nil, Hash - @_routes ||= nil _routes.url_for((options || {}).reverse_merge!(url_options).symbolize_keys) else polymorphic_url(options) -- cgit v1.2.3 From dd83140b24dcb8a27e226c9de286318a44d7fab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Mon, 27 Sep 2010 22:58:31 +0200 Subject: Properly initialize variables inside the initialize method. --- actionpack/lib/action_dispatch/routing/route_set.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 66b487ba6d..e25b30ffa6 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -304,9 +304,9 @@ module ActionDispatch extend ActiveSupport::Concern include UrlFor - @routes = routes + @_routes = routes class << self - delegate :url_for, :to => '@routes' + delegate :url_for, :to => '@_routes' end extend routes.named_routes.module @@ -318,7 +318,12 @@ module ActionDispatch singleton_class.send(:define_method, :_routes) { routes } end - define_method(:_routes) { @_routes ||= nil; @_routes || routes } + def initialize(*) + @_routes = nil + super + end + + define_method(:_routes) { @_routes || routes } end helpers -- cgit v1.2.3 From 72f37bd8bc5b3beb1e8a2d1ac2de2c045cd0cfd2 Mon Sep 17 00:00:00 2001 From: Diego Carrion <dc.rec1@gmail.com> Date: Sat, 18 Sep 2010 11:00:23 -0300 Subject: renderer calls object.to_json when rendering :json => object [#5655 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim <jose.valim@gmail.com> --- actionpack/lib/action_controller/metal/renderers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/renderers.rb b/actionpack/lib/action_controller/metal/renderers.rb index 0be07cd1fc..f9b226b7c9 100644 --- a/actionpack/lib/action_controller/metal/renderers.rb +++ b/actionpack/lib/action_controller/metal/renderers.rb @@ -71,7 +71,7 @@ module ActionController end add :json do |json, options| - json = ActiveSupport::JSON.encode(json, options) unless json.respond_to?(:to_str) + json = json.to_json(options) unless json.respond_to?(:to_str) json = "#{options[:callback]}(#{json})" unless options[:callback].blank? self.content_type ||= Mime::JSON self.response_body = json -- cgit v1.2.3 From 8aa86babad2eddb5244ba79b4e3b5702e7e77217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Tue, 28 Sep 2010 00:39:10 +0200 Subject: Fix tests on 1.9.2. --- actionpack/lib/action_controller/metal.rb | 1 + actionpack/lib/action_dispatch/routing/route_set.rb | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index 7fcc4e7211..ace1aabe03 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -87,6 +87,7 @@ module ActionController @_status = 200 @_request = nil @_response = nil + @_routes = nil super end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index e25b30ffa6..9271191f6d 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -318,11 +318,6 @@ module ActionDispatch singleton_class.send(:define_method, :_routes) { routes } end - def initialize(*) - @_routes = nil - super - end - define_method(:_routes) { @_routes || routes } end -- cgit v1.2.3 From 197a995bc548e206bb907c40d75f8ed70fa5a923 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Mon, 27 Sep 2010 20:57:26 -0300 Subject: Move uri parser to AS as URI.parser method to reuse it in AP and ARes. --- actionpack/lib/action_controller.rb | 2 +- actionpack/lib/action_controller/caching/actions.rb | 4 +--- actionpack/lib/action_controller/caching/pages.rb | 8 +------- actionpack/lib/action_controller/uri_parser.rb | 9 --------- actionpack/lib/action_dispatch/routing/route_set.rb | 10 ++-------- 5 files changed, 5 insertions(+), 28 deletions(-) delete mode 100644 actionpack/lib/action_controller/uri_parser.rb (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index 787439db87..5b81cd39f4 100644 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -8,7 +8,6 @@ module ActionController autoload :Caching autoload :Metal autoload :Middleware - autoload :UriParser autoload_under "metal" do autoload :Compatibility @@ -73,4 +72,5 @@ require 'active_support/core_ext/load_error' require 'active_support/core_ext/module/attr_internal' require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/name_error' +require 'active_support/core_ext/uri' require 'active_support/inflector' diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index cd352f69fc..d69d96b974 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -141,8 +141,6 @@ module ActionController #:nodoc: end class ActionCachePath - include UriParser - attr_reader :path, :extension # If +infer_extension+ is true, the cache path extension is looked up from the request's @@ -163,7 +161,7 @@ module ActionController #:nodoc: def normalize!(path) path << 'index' if path[-1] == ?/ path << ".#{extension}" if extension and !path.ends_with?(extension) - uri_parser.unescape(path) + URI.parser.unescape(path) end end end diff --git a/actionpack/lib/action_controller/caching/pages.rb b/actionpack/lib/action_controller/caching/pages.rb index f0e00718ac..df4d500069 100644 --- a/actionpack/lib/action_controller/caching/pages.rb +++ b/actionpack/lib/action_controller/caching/pages.rb @@ -57,8 +57,6 @@ module ActionController #:nodoc: end module ClassMethods - include UriParser - # Expires the page that was cached with the +path+ as a key. Example: # expire_page "/lists/show" def expire_page(path) @@ -100,7 +98,7 @@ module ActionController #:nodoc: private def page_cache_file(path) - name = (path.empty? || path == "/") ? "/index" : uri_parser.unescape(path.chomp('/')) + name = (path.empty? || path == "/") ? "/index" : URI.parser.unescape(path.chomp('/')) name << page_cache_extension unless (name.split('/').last || name).include? '.' return name end @@ -112,10 +110,6 @@ module ActionController #:nodoc: def instrument_page_cache(name, path) ActiveSupport::Notifications.instrument("#{name}.action_controller", :path => path){ yield } end - - def uri_parser - @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI - end end # Expires the page that was cached with the +options+ as a key. Example: diff --git a/actionpack/lib/action_controller/uri_parser.rb b/actionpack/lib/action_controller/uri_parser.rb deleted file mode 100644 index 8e2a3f69eb..0000000000 --- a/actionpack/lib/action_controller/uri_parser.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'uri' - -module ActionController #:nodoc: - module UriParser - def uri_parser - @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI - end - end -end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 66b487ba6d..66e6ecc74c 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -5,8 +5,6 @@ require 'active_support/core_ext/object/to_query' module ActionDispatch module Routing class RouteSet #:nodoc: - include ActionController::UriParser - PARAMETERS_KEY = 'action_dispatch.request.path_parameters' class Dispatcher #:nodoc: @@ -68,7 +66,7 @@ module ActionDispatch end def split_glob_param!(params) - params[@glob_param] = params[@glob_param].split('/').map { |v| uri_parser.unescape(v) } + params[@glob_param] = params[@glob_param].split('/').map { |v| URI.parser.unescape(v) } end end @@ -546,7 +544,7 @@ module ActionDispatch params.each do |key, value| if value.is_a?(String) value = value.dup.force_encoding(Encoding::BINARY) if value.encoding_aware? - params[key] = uri_parser.unescape(value) + params[key] = URI.parser.unescape(value) end end @@ -563,10 +561,6 @@ module ActionDispatch end private - def uri_parser - @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI - end - def handle_positional_args(options) return unless args = options.delete(:_positional_args) -- cgit v1.2.3 From 71acc2737aa346ee57f9fc21252a508ae83367a4 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Tue, 28 Sep 2010 07:57:26 +0800 Subject: Move uri parser to AS as URI.parser method to reuse it in AP and ARes. --- actionpack/lib/action_controller.rb | 2 +- actionpack/lib/action_controller/caching/actions.rb | 4 +--- actionpack/lib/action_controller/caching/pages.rb | 8 +------- actionpack/lib/action_controller/uri_parser.rb | 9 --------- actionpack/lib/action_dispatch/routing/route_set.rb | 10 ++-------- 5 files changed, 5 insertions(+), 28 deletions(-) delete mode 100644 actionpack/lib/action_controller/uri_parser.rb (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index 787439db87..5b81cd39f4 100644 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -8,7 +8,6 @@ module ActionController autoload :Caching autoload :Metal autoload :Middleware - autoload :UriParser autoload_under "metal" do autoload :Compatibility @@ -73,4 +72,5 @@ require 'active_support/core_ext/load_error' require 'active_support/core_ext/module/attr_internal' require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/name_error' +require 'active_support/core_ext/uri' require 'active_support/inflector' diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index cd352f69fc..d69d96b974 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -141,8 +141,6 @@ module ActionController #:nodoc: end class ActionCachePath - include UriParser - attr_reader :path, :extension # If +infer_extension+ is true, the cache path extension is looked up from the request's @@ -163,7 +161,7 @@ module ActionController #:nodoc: def normalize!(path) path << 'index' if path[-1] == ?/ path << ".#{extension}" if extension and !path.ends_with?(extension) - uri_parser.unescape(path) + URI.parser.unescape(path) end end end diff --git a/actionpack/lib/action_controller/caching/pages.rb b/actionpack/lib/action_controller/caching/pages.rb index f0e00718ac..df4d500069 100644 --- a/actionpack/lib/action_controller/caching/pages.rb +++ b/actionpack/lib/action_controller/caching/pages.rb @@ -57,8 +57,6 @@ module ActionController #:nodoc: end module ClassMethods - include UriParser - # Expires the page that was cached with the +path+ as a key. Example: # expire_page "/lists/show" def expire_page(path) @@ -100,7 +98,7 @@ module ActionController #:nodoc: private def page_cache_file(path) - name = (path.empty? || path == "/") ? "/index" : uri_parser.unescape(path.chomp('/')) + name = (path.empty? || path == "/") ? "/index" : URI.parser.unescape(path.chomp('/')) name << page_cache_extension unless (name.split('/').last || name).include? '.' return name end @@ -112,10 +110,6 @@ module ActionController #:nodoc: def instrument_page_cache(name, path) ActiveSupport::Notifications.instrument("#{name}.action_controller", :path => path){ yield } end - - def uri_parser - @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI - end end # Expires the page that was cached with the +options+ as a key. Example: diff --git a/actionpack/lib/action_controller/uri_parser.rb b/actionpack/lib/action_controller/uri_parser.rb deleted file mode 100644 index 8e2a3f69eb..0000000000 --- a/actionpack/lib/action_controller/uri_parser.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'uri' - -module ActionController #:nodoc: - module UriParser - def uri_parser - @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI - end - end -end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 9271191f6d..8d9f0cfdeb 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -5,8 +5,6 @@ require 'active_support/core_ext/object/to_query' module ActionDispatch module Routing class RouteSet #:nodoc: - include ActionController::UriParser - PARAMETERS_KEY = 'action_dispatch.request.path_parameters' class Dispatcher #:nodoc: @@ -68,7 +66,7 @@ module ActionDispatch end def split_glob_param!(params) - params[@glob_param] = params[@glob_param].split('/').map { |v| uri_parser.unescape(v) } + params[@glob_param] = params[@glob_param].split('/').map { |v| URI.parser.unescape(v) } end end @@ -546,7 +544,7 @@ module ActionDispatch params.each do |key, value| if value.is_a?(String) value = value.dup.force_encoding(Encoding::BINARY) if value.encoding_aware? - params[key] = uri_parser.unescape(value) + params[key] = URI.parser.unescape(value) end end @@ -563,10 +561,6 @@ module ActionDispatch end private - def uri_parser - @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI - end - def handle_positional_args(options) return unless args = options.delete(:_positional_args) -- cgit v1.2.3 From b8c565fbd68343b419b05a53b4e1844062d1197e Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Tue, 28 Sep 2010 15:10:15 -0300 Subject: Initialize @app if it doesn't exists. --- actionpack/lib/action_dispatch/testing/integration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 3204115e9f..8c05462d0d 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -308,7 +308,7 @@ module ActionDispatch include ActionDispatch::Assertions def app - @app + @app ||= nil end # Reset the current session. This is useful for testing multiple sessions -- cgit v1.2.3 From 4bce8e3c7510cd1bc1821af208d05e8c87349fb2 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Tue, 28 Sep 2010 15:10:55 -0300 Subject: No need to call super here. Use yield instead block.call --- actionpack/lib/action_dispatch/middleware/stack.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/middleware/stack.rb b/actionpack/lib/action_dispatch/middleware/stack.rb index db7f342bc5..9ea188c3e2 100644 --- a/actionpack/lib/action_dispatch/middleware/stack.rb +++ b/actionpack/lib/action_dispatch/middleware/stack.rb @@ -41,9 +41,8 @@ module ActionDispatch end end - def initialize(*args, &block) - super(*args) - block.call(self) if block_given? + def initialize(*args) + yield(self) if block_given? end def insert(index, *args, &block) -- cgit v1.2.3 From 8ee27afd064bccfc63b21f126109a9b20ce72bd5 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Tue, 28 Sep 2010 15:21:44 -0300 Subject: Don't define _test_case method if already defined. --- actionpack/lib/action_view/test_case.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 32fd8c5e21..de23a67cb6 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -137,8 +137,10 @@ module ActionView def make_test_case_available_to_view! test_case_instance = self _helpers.module_eval do - define_method(:_test_case) { test_case_instance } - private :_test_case + unless private_method_defined?(:_test_case) + define_method(:_test_case) { test_case_instance } + private :_test_case + end end end -- cgit v1.2.3 From 1ef2b47fb12a94f960b34c4bb1e6ad1f9c900e18 Mon Sep 17 00:00:00 2001 From: Aaron Patterson <aaron.patterson@gmail.com> Date: Tue, 28 Sep 2010 11:22:16 -0700 Subject: convert inject to map + join --- actionpack/lib/action_view/helpers/form_options_helper.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 43cbba8a0a..83434a9340 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -395,12 +395,12 @@ module ActionView # <b>Note:</b> Only the <tt><optgroup></tt> and <tt><option></tt> tags are returned, so you still have to # wrap the output in an appropriate <tt><select></tt> tag. def option_groups_from_collection_for_select(collection, group_method, group_label_method, option_key_method, option_value_method, selected_key = nil) - collection.inject("") do |options_for_select, group| + collection.map do |group| group_label_string = eval("group.#{group_label_method}") - options_for_select += "<optgroup label=\"#{html_escape(group_label_string)}\">" - options_for_select += options_from_collection_for_select(eval("group.#{group_method}"), option_key_method, option_value_method, selected_key) - options_for_select += '</optgroup>' - end.html_safe + "<optgroup label=\"#{html_escape(group_label_string)}\">" + + options_from_collection_for_select(eval("group.#{group_method}"), option_key_method, option_value_method, selected_key) + + '</optgroup>' + end.join.html_safe end # Returns a string of <tt><option></tt> tags, like <tt>options_for_select</tt>, but -- cgit v1.2.3 From adcc5e11fe5edd2883b6ec4d08ab72180a973155 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Tue, 28 Sep 2010 15:29:40 -0300 Subject: @selected may not be defined here, avoid warning. --- actionpack/lib/action_dispatch/testing/assertions/selector.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index 353be10d20..9ae4f65db9 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -197,7 +197,7 @@ module ActionDispatch # This usually happens when passing a node/element that # happens to be nil. raise ArgumentError, "First argument is either selector or element to select, but nil found. Perhaps you called assert_select with an element that does not exist?" - elsif @selected + elsif defined?(@selected) && @selected root = HTML::Node.new(nil) root.children.concat @selected else -- cgit v1.2.3 From 04c4f47fed6ced3f4158107b7cc40a7ea1b4913c Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Tue, 28 Sep 2010 15:33:48 -0300 Subject: Initialize @sub_templates --- actionpack/lib/action_view/template/error.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/template/error.rb b/actionpack/lib/action_view/template/error.rb index b1839b65e5..423e1e0bf5 100644 --- a/actionpack/lib/action_view/template/error.rb +++ b/actionpack/lib/action_view/template/error.rb @@ -52,6 +52,7 @@ module ActionView def initialize(template, assigns, original_exception) @template, @assigns, @original_exception = template, assigns.dup, original_exception + @sub_templates = nil @backtrace = original_exception.backtrace end -- cgit v1.2.3 From 059d609a1a59300faefdc2d4186bae13b30c9699 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Tue, 28 Sep 2010 15:46:30 -0300 Subject: Avoid more uninitialized variable warnings. --- actionpack/lib/abstract_controller/rendering.rb | 2 +- actionpack/lib/action_dispatch/testing/assertions/selector.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 5d9b35d297..cc6a7f4047 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -66,7 +66,7 @@ module AbstractController attr_writer :view_context_class def view_context_class - @view_context_class || self.class.view_context_class + (@view_context_class ||= nil) || self.class.view_context_class end def initialize(*) diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index 9ae4f65db9..f5ecb9a199 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -187,6 +187,7 @@ module ActionDispatch def assert_select(*args, &block) # Start with optional element followed by mandatory selector. arg = args.shift + @selected ||= nil if arg.is_a?(HTML::Node) # First argument is a node (tag or text, but also HTML root), @@ -197,7 +198,7 @@ module ActionDispatch # This usually happens when passing a node/element that # happens to be nil. raise ArgumentError, "First argument is either selector or element to select, but nil found. Perhaps you called assert_select with an element that does not exist?" - elsif defined?(@selected) && @selected + elsif @selected root = HTML::Node.new(nil) root.children.concat @selected else -- cgit v1.2.3 From 7c8b43ed4fba035033e28cc47358fc3908584880 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Tue, 28 Sep 2010 15:53:32 -0300 Subject: Ask if the instance variable is defined before asking for it, avoid *many* warnings. --- actionpack/lib/action_view/helpers/form_helper.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 8bae6d2796..7e49052c24 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -991,7 +991,11 @@ module ActionView end def object - @object || @template_object.instance_variable_get("@#{@object_name}") + if @object + @object + elsif @template_object.instance_variable_defined?("@#{@object_name}") + @template_object.instance_variable_get("@#{@object_name}") + end rescue NameError # As @object_name may contain the nested syntax (item[subobject]) we # need to fallback to nil. -- cgit v1.2.3 From c9416546a209847e2167edf49de7b4f6c9950694 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Tue, 28 Sep 2010 16:09:31 -0300 Subject: Use parenthesis to avoid ambiguous first argument warning. --- actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb index d18b162a93..c3fa4dba0a 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb @@ -19,7 +19,7 @@ <% end %> <% traces.each do |name, trace| %> - <div id="<%= name.gsub /\s/, '-' %>" style="display: <%= name == "Application Trace" ? 'block' : 'none' %>;"> + <div id="<%= name.gsub /\s/, '-' %>" style="display: <%= (name == "Application Trace") ? 'block' : 'none' %>;"> <pre><code><%=h trace.join "\n" %></code></pre> </div> <% end %> -- cgit v1.2.3 From 540e87256df08d350e9eb572408e5f68fa59f42b Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Tue, 28 Sep 2010 16:12:07 -0300 Subject: Remove remaining warnings on _trace by adding parenthesis to gsub arguments. --- .../lib/action_dispatch/middleware/templates/rescues/_trace.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb index c3fa4dba0a..8771b5fd6d 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb @@ -12,14 +12,14 @@ <div id="traces"> <% names.each do |name| %> <% - show = "document.getElementById('#{name.gsub /\s/, '-'}').style.display='block';" - hide = (names - [name]).collect {|hide_name| "document.getElementById('#{hide_name.gsub /\s/, '-'}').style.display='none';"} + show = "document.getElementById('#{name.gsub(/\s/, '-')}').style.display='block';" + hide = (names - [name]).collect {|hide_name| "document.getElementById('#{hide_name.gsub(/\s/, '-')}').style.display='none';"} %> <a href="#" onclick="<%= hide.join %><%= show %>; return false;"><%= name %></a> <%= '|' unless names.last == name %> <% end %> <% traces.each do |name, trace| %> - <div id="<%= name.gsub /\s/, '-' %>" style="display: <%= (name == "Application Trace") ? 'block' : 'none' %>;"> + <div id="<%= name.gsub(/\s/, '-') %>" style="display: <%= (name == "Application Trace") ? 'block' : 'none' %>;"> <pre><code><%=h trace.join "\n" %></code></pre> </div> <% end %> -- cgit v1.2.3 From 6286b63f27b6b36b9603c4c68600f8f352b84137 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Tue, 28 Sep 2010 16:20:48 -0300 Subject: Remove warings from rescues: don't define more than once debug_hash method and ask if @response if defined. --- .../middleware/templates/rescues/_request_and_response.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb index e963b04524..97f7cf0bbe 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb @@ -14,7 +14,7 @@ def debug_hash(hash) hash.sort_by { |k, v| k.to_s }.map { |k, v| "#{k}: #{v.inspect rescue $!.message}" }.join("\n") - end + end unless self.class.method_defined?(:debug_hash) %> <h2 style="margin-top: 30px">Request</h2> @@ -28,4 +28,4 @@ <h2 style="margin-top: 30px">Response</h2> -<p><b>Headers</b>: <pre><%=h @response ? @response.headers.inspect.gsub(',', ",\n") : 'None' %></pre></p> +<p><b>Headers</b>: <pre><%=h defined?(@response) ? @response.headers.inspect.gsub(',', ",\n") : 'None' %></pre></p> -- cgit v1.2.3 From eea61a030e96625c53c57b63f0a9449850cf78df Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Tue, 28 Sep 2010 16:24:42 -0300 Subject: Initialize @compiled_at if it is not. --- actionpack/lib/action_dispatch/middleware/static.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/middleware/static.rb b/actionpack/lib/action_dispatch/middleware/static.rb index 581cadbeb4..6d442b91f5 100644 --- a/actionpack/lib/action_dispatch/middleware/static.rb +++ b/actionpack/lib/action_dispatch/middleware/static.rb @@ -7,6 +7,7 @@ module ActionDispatch @compiled_at = Regexp.compile(/^#{Regexp.escape(at)}/) unless @at.blank? @compiled_root = Regexp.compile(/^#{Regexp.escape(root)}/) @file_server = ::Rack::File.new(root) + @compiled_at ||= nil end def match?(path) -- cgit v1.2.3 From da8f9ca4329499fc9cc9c3f999a9d6eecdc801d3 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Tue, 28 Sep 2010 16:27:05 -0300 Subject: Remove more warnings on variables. --- actionpack/lib/action_dispatch/routing/url_for.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index e836cf7c8e..7be0f2769a 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -136,6 +136,7 @@ module ActionDispatch protected def _with_routes(routes) + @_routes ||= nil old_routes, @_routes = @_routes, routes yield ensure -- cgit v1.2.3 From 4d6e178f888c8287eb59e14bd9ecb77b4d71455b Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Tue, 28 Sep 2010 16:31:21 -0300 Subject: Remove method if exists, avoid calling Array#first so many times. --- actionpack/lib/action_dispatch/middleware/callbacks.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/middleware/callbacks.rb b/actionpack/lib/action_dispatch/middleware/callbacks.rb index e4ae480bfb..0bb950d1cc 100644 --- a/actionpack/lib/action_dispatch/middleware/callbacks.rb +++ b/actionpack/lib/action_dispatch/middleware/callbacks.rb @@ -19,9 +19,11 @@ module ActionDispatch # replace the existing callback. Passing an identifier is a suggested # practice if the code adding a preparation block may be reloaded. def self.to_prepare(*args, &block) - if args.first.is_a?(Symbol) && block_given? - define_method :"__#{args.first}", &block - set_callback(:prepare, :"__#{args.first}") + first_arg = args.first + if first_arg.is_a?(Symbol) && block_given? + remove_method :"__#{first_arg}" if method_defined?(:"__#{first_arg}") + define_method :"__#{first_arg}", &block + set_callback(:prepare, :"__#{first_arg}") else set_callback(:prepare, *args, &block) end -- cgit v1.2.3 From 19d9fffb9b8350b03cf8b1e3a3249eba06d22c1a Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Tue, 28 Sep 2010 17:08:10 -0300 Subject: Use redefine_method instead define_method, it may be already defined. --- actionpack/lib/action_dispatch/routing/route_set.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 66e6ecc74c..71a320ce9c 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -313,7 +313,7 @@ module ActionDispatch # Yes plz - JP included do routes.install_helpers(self) - singleton_class.send(:define_method, :_routes) { routes } + singleton_class.send(:redefine_method, :_routes) { routes } end define_method(:_routes) { @_routes ||= nil; @_routes || routes } -- cgit v1.2.3 From 3f94b45262577b70a1d9f3aea45e0e4f07a2bbaa Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Tue, 28 Sep 2010 17:08:43 -0300 Subject: Remove more warnings: no need to define attr_accessor if already exists. Initialize ivar. --- actionpack/lib/action_controller/test_case.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index f1ff57f0cb..70a5de7f30 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -462,9 +462,11 @@ module ActionController # The exception is stored in the exception accessor for further inspection. module RaiseActionExceptions def self.included(base) - base.class_eval do - attr_accessor :exception - protected :exception, :exception= + unless base.method_defined?(:exception) && base.method_defined?(:exception=) + base.class_eval do + attr_accessor :exception + protected :exception, :exception= + end end end -- cgit v1.2.3 From 523f98099d331908db6ab4c45f7657e61a8a4d5f Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Tue, 28 Sep 2010 18:01:48 -0300 Subject: Remove more warnings on AP. --- actionpack/lib/action_dispatch/middleware/session/abstract_store.rb | 4 ++-- actionpack/lib/action_dispatch/testing/assertions/selector.rb | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb index 348a2d1eb2..ea49b30630 100644 --- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb @@ -102,8 +102,8 @@ module ActionDispatch def destroy clear - @by.send(:destroy, @env) if @by - @env[ENV_SESSION_OPTIONS_KEY][:id] = nil if @env && @env[ENV_SESSION_OPTIONS_KEY] + @by.send(:destroy, @env) if defined?(@by) && @by + @env[ENV_SESSION_OPTIONS_KEY][:id] = nil if defined?(@env) && @env && @env[ENV_SESSION_OPTIONS_KEY] @loaded = false end diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index f5ecb9a199..2b862fb7d6 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -67,7 +67,7 @@ module ActionDispatch arg = args.shift elsif arg == nil raise ArgumentError, "First argument is either selector or element to select, but nil found. Perhaps you called assert_select with an element that does not exist?" - elsif @selected + elsif defined?(@selected) && @selected matches = [] @selected.each do |selected| @@ -443,6 +443,7 @@ module ActionDispatch assert_block("") { true } # to count the assertion if block_given? && !([:remove, :show, :hide, :toggle].include? rjs_type) begin + @selected ||= nil in_scope, @selected = @selected, matches yield matches ensure -- cgit v1.2.3 From 357f59447d79a09d7a84fa8c2bc7892b5fc02ca9 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Tue, 28 Sep 2010 18:20:54 -0300 Subject: Initialize @path. --- actionpack/lib/action_view/template/resolver.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb index c9e20ca14e..a261e08dbc 100644 --- a/actionpack/lib/action_view/template/resolver.rb +++ b/actionpack/lib/action_view/template/resolver.rb @@ -6,6 +6,7 @@ module ActionView # = Action View Resolver class Resolver def initialize + @path = nil @cached = Hash.new { |h1,k1| h1[k1] = Hash.new { |h2,k2| h2[k2] = Hash.new { |h3, k3| h3[k3] = {} } } } end -- cgit v1.2.3 From 0fa9c5392ec24a7d1017d03aa00a2bac32f53158 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Tue, 28 Sep 2010 18:25:24 -0300 Subject: Define @_layout if it is not defined. --- actionpack/lib/abstract_controller/layouts.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index 958e7f7ec8..bbc9739f14 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -345,6 +345,7 @@ module AbstractController # * <tt>template</tt> - The template object for the default layout (or nil) def _default_layout(require_layout = false) begin + @_layout ||= nil layout_name = _layout if action_has_layout? rescue NameError => e raise NoMethodError, -- cgit v1.2.3 From 14f9904e0fc6d8a1e5627ac64c4b5b14e95177c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Wed, 29 Sep 2010 11:18:31 +0200 Subject: Avoid (@_var ||= nil) pattern by using initialize methods and ensuring everyone calls super as expected. --- actionpack/lib/abstract_controller/layouts.rb | 4 +-- actionpack/lib/abstract_controller/rendering.rb | 2 +- actionpack/lib/abstract_controller/url_for.rb | 1 - actionpack/lib/action_dispatch/middleware/stack.rb | 4 +++ .../lib/action_dispatch/middleware/static.rb | 3 +-- actionpack/lib/action_dispatch/routing/url_for.rb | 6 ++++- .../lib/action_dispatch/testing/integration.rb | 1 + actionpack/lib/action_view/helpers/form_helper.rb | 31 ++++++++++++---------- actionpack/lib/action_view/test_case.rb | 22 +++++++-------- 9 files changed, 41 insertions(+), 33 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index bbc9739f14..5c853c3034 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -345,11 +345,9 @@ module AbstractController # * <tt>template</tt> - The template object for the default layout (or nil) def _default_layout(require_layout = false) begin - @_layout ||= nil layout_name = _layout if action_has_layout? rescue NameError => e - raise NoMethodError, - "You specified #{@_layout.inspect} as the layout, but no such method was found" + raise e.class, "Coult not render layout: #{e.message}" end if require_layout && action_has_layout? && !layout_name diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index cc6a7f4047..5d9b35d297 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -66,7 +66,7 @@ module AbstractController attr_writer :view_context_class def view_context_class - (@view_context_class ||= nil) || self.class.view_context_class + @view_context_class || self.class.view_context_class end def initialize(*) diff --git a/actionpack/lib/abstract_controller/url_for.rb b/actionpack/lib/abstract_controller/url_for.rb index 2e9de22ecd..e5d5bef6b4 100644 --- a/actionpack/lib/abstract_controller/url_for.rb +++ b/actionpack/lib/abstract_controller/url_for.rb @@ -1,7 +1,6 @@ module AbstractController module UrlFor extend ActiveSupport::Concern - include ActionDispatch::Routing::UrlFor def _routes diff --git a/actionpack/lib/action_dispatch/middleware/stack.rb b/actionpack/lib/action_dispatch/middleware/stack.rb index 9ea188c3e2..e3cd779756 100644 --- a/actionpack/lib/action_dispatch/middleware/stack.rb +++ b/actionpack/lib/action_dispatch/middleware/stack.rb @@ -41,7 +41,11 @@ module ActionDispatch end end + # Use this instead of super to work around a warning. + alias :array_initialize :initialize + def initialize(*args) + array_initialize(*args) yield(self) if block_given? end diff --git a/actionpack/lib/action_dispatch/middleware/static.rb b/actionpack/lib/action_dispatch/middleware/static.rb index 6d442b91f5..cf13938331 100644 --- a/actionpack/lib/action_dispatch/middleware/static.rb +++ b/actionpack/lib/action_dispatch/middleware/static.rb @@ -4,10 +4,9 @@ module ActionDispatch class FileHandler def initialize(at, root) @at, @root = at.chomp('/'), root.chomp('/') - @compiled_at = Regexp.compile(/^#{Regexp.escape(at)}/) unless @at.blank? + @compiled_at = (Regexp.compile(/^#{Regexp.escape(at)}/) unless @at.blank?) @compiled_root = Regexp.compile(/^#{Regexp.escape(root)}/) @file_server = ::Rack::File.new(root) - @compiled_at ||= nil end def match?(path) diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index 7be0f2769a..bfdea41f60 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -98,6 +98,11 @@ module ActionDispatch end end + def initialize(*) + @_routes = nil + super + end + def url_options default_url_options end @@ -136,7 +141,6 @@ module ActionDispatch protected def _with_routes(routes) - @_routes ||= nil old_routes, @_routes = @_routes, routes yield ensure diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 8c05462d0d..4d25bb8d7b 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -171,6 +171,7 @@ module ActionDispatch # Create and initialize a new Session instance. def initialize(app) + super @app = app # If the app is a Rails app, make url_helpers available on the session diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 7e49052c24..c47fac05ef 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -850,7 +850,7 @@ module ActionView extend ActiveSupport::Concern include Helpers::CaptureHelper, Context, Helpers::TagHelper, Helpers::FormTagHelper - attr_reader :method_name, :object_name + attr_reader :object, :method_name, :object_name DEFAULT_FIELD_OPTIONS = { "size" => 30 } DEFAULT_RADIO_OPTIONS = { } @@ -859,14 +859,9 @@ module ActionView def initialize(object_name, method_name, template_object, object = nil) @object_name, @method_name = object_name.to_s.dup, method_name.to_s.dup @template_object = template_object - @object = object - if @object_name.sub!(/\[\]$/,"") || @object_name.sub!(/\[\]\]$/,"]") - if (object ||= @template_object.instance_variable_get("@#{Regexp.last_match.pre_match}")) && object.respond_to?(:to_param) - @auto_index = object.to_param - else - raise ArgumentError, "object[] naming but object param and @object var don't exist or don't respond to to_param: #{object.inspect}" - end - end + @object_name.sub!(/\[\]$/,"") || @object_name.sub!(/\[\]\]$/,"]") + @object = retrieve_object(object) + @auto_index = retrieve_autoindex(Regexp.last_match.pre_match) if Regexp.last_match end def to_label_tag(text = nil, options = {}, &block) @@ -990,18 +985,26 @@ module ActionView content_tag(tag_name, value(object), options) end - def object - if @object - @object + def retrieve_object(object) + if object + object elsif @template_object.instance_variable_defined?("@#{@object_name}") @template_object.instance_variable_get("@#{@object_name}") end rescue NameError - # As @object_name may contain the nested syntax (item[subobject]) we - # need to fallback to nil. + # As @object_name may contain the nested syntax (item[subobject]) we need to fallback to nil. nil end + def retrieve_autoindex(pre_match) + object = self.object || @template_object.instance_variable_get("@#{pre_match}") + if object && object.respond_to?(:to_param) + object.to_param + else + raise ArgumentError, "object[] naming but object param and @object var don't exist or don't respond to to_param: #{object.inspect}" + end + end + def value(object) self.class.value(object, @method_name) end diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index de23a67cb6..915c2f90d7 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -20,12 +20,12 @@ module ActionView end def initialize + super self.class.controller_path = "" @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new @request.env.delete('PATH_INFO') - @params = {} end end @@ -156,15 +156,15 @@ module ActionView # The instance of ActionView::Base that is used by +render+. def view @view ||= begin - view = ActionView::Base.new(ActionController::Base.view_paths, {}, @controller) - view.singleton_class.send :include, _helpers - view.singleton_class.send :include, @controller._routes.url_helpers - view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash" - view.extend(Locals) - view.locals = self.locals - view.output_buffer = self.output_buffer - view - end + view = ActionView::Base.new(ActionController::Base.view_paths, {}, @controller) + view.singleton_class.send :include, _helpers + view.singleton_class.send :include, @controller._routes.url_helpers + view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash" + view.extend(Locals) + view.locals = self.locals + view.output_buffer = self.output_buffer + view + end end alias_method :_view, :view @@ -201,7 +201,7 @@ module ActionView def method_missing(selector, *args) if @controller.respond_to?(:_routes) && - @controller._routes.named_routes.helpers.include?(selector) + @controller._routes.named_routes.helpers.include?(selector) @controller.__send__(selector, *args) else super -- cgit v1.2.3 From 392df0fc06a985e607c89c8a0090cb036adc5b7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Wed, 29 Sep 2010 11:19:22 +0200 Subject: @_etag is not used anywhere. --- actionpack/lib/action_dispatch/http/response.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index a5d082c6a2..151c90167b 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -43,7 +43,6 @@ module ActionDispatch # :nodoc: @writer = lambda { |x| @body << x } @block = nil @length = 0 - @_etag = nil @status, @header = status, header self.body = body @@ -141,7 +140,6 @@ module ActionDispatch # :nodoc: assign_default_content_type_and_charset! handle_conditional_get! self["Set-Cookie"] = self["Set-Cookie"].join("\n") if self["Set-Cookie"].respond_to?(:join) - self["ETag"] = @_etag if @_etag super end -- cgit v1.2.3 From b1ae796284850e29d5ad0fc769e55ed4a43676a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Wed, 29 Sep 2010 11:28:38 +0200 Subject: Fix an error on 1.8.7. --- actionpack/lib/action_dispatch/testing/integration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 4d25bb8d7b..fee8cad9f5 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -171,7 +171,7 @@ module ActionDispatch # Create and initialize a new Session instance. def initialize(app) - super + super() @app = app # If the app is a Rails app, make url_helpers available on the session -- cgit v1.2.3 From f63d35fba55867111427bfeb54c31b11e02d5d3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Wed, 29 Sep 2010 14:24:32 +0200 Subject: Ensure that named routes do not overwrite previously defined routes. --- actionpack/lib/action_dispatch/routing/mapper.rb | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 5e95d8ed39..0cb02c5b80 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -62,7 +62,6 @@ module ActionDispatch if using_match_shorthand?(path_without_format, @options) to_shorthand = @options[:to].blank? @options[:to] ||= path_without_format[1..-1].sub(%r{/([^/]*)$}, '#\1') - @options[:as] ||= Mapper.normalize_name(path_without_format) end @options.merge!(default_controller_and_action(to_shorthand)) @@ -924,9 +923,14 @@ module ActionDispatch if action.to_s =~ /^[\w\/]+$/ options[:action] ||= action unless action.to_s.include?("/") - options[:as] = name_for_action(action, options[:as]) else - options[:as] = name_for_action(options[:as]) + action = nil + end + + if options.key?(:as) && !options[:as] + options.delete(:as) + else + options[:as] = name_for_action(options[:as], action) end super(path, options) @@ -1092,18 +1096,16 @@ module ActionDispatch path || @scope[:path_names][name.to_sym] || name.to_s end - def prefix_name_for_action(action, as) - if as.present? + def prefix_name_for_action(as, action) + if as as.to_s - elsif as - nil elsif !canonical_action?(action, @scope[:scope_level]) action.to_s end end - def name_for_action(action, as=nil) - prefix = prefix_name_for_action(action, as) + def name_for_action(as, action) + prefix = prefix_name_for_action(as, action) prefix = Mapper.normalize_name(prefix) if prefix name_prefix = @scope[:as] @@ -1127,7 +1129,8 @@ module ActionDispatch [name_prefix, member_name, prefix] end - name.select(&:present?).join("_").presence + candidate = name.select(&:present?).join("_").presence + candidate unless as.nil? && @set.routes.map(&:name).include?(candidate) end end -- cgit v1.2.3 From 626881577949ffce8370e097aa3efb3fec47d4f5 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Wed, 29 Sep 2010 12:40:01 -0300 Subject: Initialize @view_context_class and cache view_context_class value. --- actionpack/lib/abstract_controller/rendering.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 5d9b35d297..918def3e81 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -66,7 +66,7 @@ module AbstractController attr_writer :view_context_class def view_context_class - @view_context_class || self.class.view_context_class + @view_context_class ||= self.class.view_context_class end def initialize(*) -- cgit v1.2.3 From 152580ee00205b42de45950d69349c6eab6dd291 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Wed, 29 Sep 2010 11:37:08 -0300 Subject: Don't try to interpolate string if there's no interpolation point at all. --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 0cb02c5b80..189da138d8 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -349,7 +349,7 @@ module ActionDispatch options = args.last.is_a?(Hash) ? args.pop : {} path = args.shift || block - path_proc = path.is_a?(Proc) ? path : proc { |params| params.empty? ? path : (path % params) } + path_proc = path.is_a?(Proc) ? path : proc { |params| (params.empty? || !path.match(/%{\w*}/)) ? path : (path % params) } status = options[:status] || 301 lambda do |env| -- cgit v1.2.3 From 8823b85010a217df555b981a453384e24ce7da47 Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Wed, 29 Sep 2010 12:13:58 -0300 Subject: Remove redundant conditional. --- actionpack/lib/action_dispatch/testing/assertions/response.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index 10b122557a..e381b9abdf 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -84,11 +84,7 @@ module ActionDispatch when %r{^\w[\w\d+.-]*:.*} fragment when String - if fragment =~ %r{^\w[\w\d+.-]*:.*} - fragment - else - @request.protocol + @request.host_with_port + fragment - end + @request.protocol + @request.host_with_port + fragment when :back raise RedirectBackError unless refer = @request.headers["Referer"] refer -- cgit v1.2.3 From c37800aae123d21d53a49433cac2e0a2479c6bbd Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Wed, 29 Sep 2010 12:55:43 -0300 Subject: _ is not a valid scheme name character, \w includes it and also is redundant with \d. 'The scheme name consists of a letter followed by any combination of letters, digits, and the plus ("+"), period ("."), or hyphen ("-") characters; and is terminated by a colon (":").' --- actionpack/lib/action_dispatch/testing/assertions/response.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index e381b9abdf..1558c3ae05 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -81,7 +81,7 @@ module ActionDispatch def normalize_argument_to_redirection(fragment) case fragment - when %r{^\w[\w\d+.-]*:.*} + when %r{^\w[A-Za-z\d+.-]*:.*} fragment when String @request.protocol + @request.host_with_port + fragment -- cgit v1.2.3 From 258f7b586e68ab8e6421ea3e43707ada5db20fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Wed, 29 Sep 2010 10:34:37 -0700 Subject: Fix a small typo (ht: masterkain) --- actionpack/lib/abstract_controller/layouts.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index 5c853c3034..e706dbd902 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -347,7 +347,7 @@ module AbstractController begin layout_name = _layout if action_has_layout? rescue NameError => e - raise e.class, "Coult not render layout: #{e.message}" + raise e.class, "Could not render layout: #{e.message}" end if require_layout && action_has_layout? && !layout_name -- cgit v1.2.3 From 6371e5b99f933ebe462784b5272fdf12e9602e5a Mon Sep 17 00:00:00 2001 From: Emilio Tagua <miloops@gmail.com> Date: Wed, 29 Sep 2010 14:35:24 -0300 Subject: We can't assign @view_context_class here, define super() in test instead if we want to avoid warnings. --- actionpack/lib/abstract_controller/rendering.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 918def3e81..5d9b35d297 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -66,7 +66,7 @@ module AbstractController attr_writer :view_context_class def view_context_class - @view_context_class ||= self.class.view_context_class + @view_context_class || self.class.view_context_class end def initialize(*) -- cgit v1.2.3 From c57f5d58ea5ba60b0997017ab322481377c81c2c Mon Sep 17 00:00:00 2001 From: Aaron Patterson <aaron.patterson@gmail.com> Date: Wed, 29 Sep 2010 10:39:17 -0700 Subject: no need to call e.class --- actionpack/lib/abstract_controller/layouts.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index e706dbd902..b68c7d9216 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -347,7 +347,7 @@ module AbstractController begin layout_name = _layout if action_has_layout? rescue NameError => e - raise e.class, "Could not render layout: #{e.message}" + raise e, "Could not render layout: #{e.message}" end if require_layout && action_has_layout? && !layout_name -- cgit v1.2.3 From a5f8f5908116081a3461409eda53e62d997d5b40 Mon Sep 17 00:00:00 2001 From: Aaron Patterson <aaron.patterson@gmail.com> Date: Wed, 29 Sep 2010 11:47:27 -0700 Subject: dry up action_methods --- actionpack/lib/abstract_controller/base.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb index 85270d84d8..ce88803a9c 100644 --- a/actionpack/lib/abstract_controller/base.rb +++ b/actionpack/lib/abstract_controller/base.rb @@ -61,13 +61,13 @@ module AbstractController def action_methods @action_methods ||= begin # All public instance methods of this class, including ancestors - methods = public_instance_methods(true).map { |m| m.to_s }.to_set - + methods = (public_instance_methods(true) - # Except for public instance methods of Base and its ancestors - internal_methods.map { |m| m.to_s } + + internal_methods + # Be sure to include shadowed public instance methods of this class - public_instance_methods(false).map { |m| m.to_s } - + public_instance_methods(false)).map { |x| x.to_s } - # And always exclude explicitly hidden actions - hidden_actions + hidden_actions.to_a # Clear out AS callback method pollution methods.reject { |method| method =~ /_one_time_conditions/ } -- cgit v1.2.3 From 1d9a219307ec5cc506635ee0bd3d368955d5b4a6 Mon Sep 17 00:00:00 2001 From: Aaron Patterson <aaron.patterson@gmail.com> Date: Wed, 29 Sep 2010 11:53:34 -0700 Subject: oops, missed a uniq --- actionpack/lib/abstract_controller/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb index ce88803a9c..f9f6eb945e 100644 --- a/actionpack/lib/abstract_controller/base.rb +++ b/actionpack/lib/abstract_controller/base.rb @@ -65,7 +65,7 @@ module AbstractController # Except for public instance methods of Base and its ancestors internal_methods + # Be sure to include shadowed public instance methods of this class - public_instance_methods(false)).map { |x| x.to_s } - + public_instance_methods(false)).uniq.map { |x| x.to_s } - # And always exclude explicitly hidden actions hidden_actions.to_a -- cgit v1.2.3 From 2437356cdacf2b774147b4da38de1d137e0a8b26 Mon Sep 17 00:00:00 2001 From: Aaron Patterson <aaron.patterson@gmail.com> Date: Wed, 29 Sep 2010 15:37:38 -0700 Subject: removing lollerject --- actionpack/lib/action_controller/metal/http_authentication.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb index 6a7e170306..53444f31a8 100644 --- a/actionpack/lib/action_controller/metal/http_authentication.rb +++ b/actionpack/lib/action_controller/metal/http_authentication.rb @@ -214,7 +214,7 @@ module ActionController def encode_credentials(http_method, credentials, password, password_is_ha1) credentials[:response] = expected_response(http_method, credentials[:uri], credentials, password, password_is_ha1) - "Digest " + credentials.sort_by {|x| x[0].to_s }.inject([]) {|a, v| a << "#{v[0]}='#{v[1]}'" }.join(', ') + "Digest " + credentials.sort_by {|x| x[0].to_s }.map {|v| "#{v[0]}='#{v[1]}'" }.join(', ') end def decode_credentials_header(request) -- cgit v1.2.3 From 3f88f26d1e17277dfa85a22bb01c1db558b6addf Mon Sep 17 00:00:00 2001 From: Aaron Patterson <aaron.patterson@gmail.com> Date: Wed, 29 Sep 2010 15:41:06 -0700 Subject: removing more lolinject --- .../lib/action_controller/metal/http_authentication.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb index 53444f31a8..e0c5eaca84 100644 --- a/actionpack/lib/action_controller/metal/http_authentication.rb +++ b/actionpack/lib/action_controller/metal/http_authentication.rb @@ -423,14 +423,13 @@ module ActionController # Returns nil if no token is found. def token_and_options(request) if header = request.authorization.to_s[/^Token (.*)/] - values = $1.split(','). - inject({}) do |memo, value| - value.strip! # remove any spaces between commas and values - key, value = value.split(/\=\"?/) # split key=value pairs - value.chomp!('"') # chomp trailing " in value - value.gsub!(/\\\"/, '"') # unescape remaining quotes - memo.update(key => value) - end + values = Hash[$1.split(',').map do |value| + value.strip! # remove any spaces between commas and values + key, value = value.split(/\=\"?/) # split key=value pairs + value.chomp!('"') # chomp trailing " in value + value.gsub!(/\\\"/, '"') # unescape remaining quotes + [key, value] + end] [values.delete("token"), values.with_indifferent_access] end end -- cgit v1.2.3 From ab0d216b670e13d6f65e82dfdeb3d08c75101274 Mon Sep 17 00:00:00 2001 From: Aaron Patterson <aaron.patterson@gmail.com> Date: Wed, 29 Sep 2010 15:43:27 -0700 Subject: reduce function calls on Array --- actionpack/lib/action_controller/metal/http_authentication.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb index e0c5eaca84..547cec7081 100644 --- a/actionpack/lib/action_controller/metal/http_authentication.rb +++ b/actionpack/lib/action_controller/metal/http_authentication.rb @@ -441,9 +441,8 @@ module ActionController # # Returns String. def encode_credentials(token, options = {}) - values = ["token=#{token.to_s.inspect}"] - options.each do |key, value| - values << "#{key}=#{value.to_s.inspect}" + values = ["token=#{token.to_s.inspect}"] + options.map do |key, value| + "#{key}=#{value.to_s.inspect}" end "Token #{values * ", "}" end -- cgit v1.2.3 From 78ac9c2be738ff48c847a26ae8fc4464e881e184 Mon Sep 17 00:00:00 2001 From: Aaron Patterson <aaron.patterson@gmail.com> Date: Wed, 29 Sep 2010 16:09:58 -0700 Subject: dry up method checking in the request object --- actionpack/lib/action_dispatch/http/request.rb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index 7a28228817..09d6ba8223 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -54,11 +54,7 @@ module ActionDispatch # the application should use), this \method returns the overridden # value, not the original. def request_method - @request_method ||= begin - method = env["REQUEST_METHOD"] - HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}") - method - end + @request_method ||= check_method(env["REQUEST_METHOD"]) end # Returns a symbol form of the #request_method @@ -70,11 +66,7 @@ module ActionDispatch # even if it was overridden by middleware. See #request_method for # more information. def method - @method ||= begin - method = env["rack.methodoverride.original_method"] || env['REQUEST_METHOD'] - HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}") - method - end + @method ||= check_method(env["rack.methodoverride.original_method"] || env['REQUEST_METHOD']) end # Returns a symbol form of the #method @@ -246,5 +238,12 @@ module ActionDispatch def local? LOCALHOST.any? { |local_ip| local_ip === remote_addr && local_ip === remote_ip } end + + private + + def check_method(name) + HTTP_METHOD_LOOKUP[name] || raise(ActionController::UnknownHttpMethod, "#{name}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}") + name + end end end -- cgit v1.2.3 From 2eef53b163353898a0f96d559e3f80600eb6ba15 Mon Sep 17 00:00:00 2001 From: Aaron Patterson <aaron.patterson@gmail.com> Date: Wed, 29 Sep 2010 16:17:56 -0700 Subject: removing useless code --- actionpack/lib/action_view/helpers/form_options_helper.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 83434a9340..7d6aca0470 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -297,7 +297,6 @@ module ActionView def options_for_select(container, selected = nil) return container if String === container - container = container.to_a if Hash === container selected, disabled = extract_selected_and_disabled(selected).map do | r | Array.wrap(r).map(&:to_s) end -- cgit v1.2.3 From a40e3c1a9604ab3737ad2465c8f6a6db0fe0cc78 Mon Sep 17 00:00:00 2001 From: Aaron Patterson <aaron.patterson@gmail.com> Date: Wed, 29 Sep 2010 16:40:47 -0700 Subject: removing crazy finalizer code until there is proof that we need it --- actionpack/lib/action_view/template.rb | 9 --------- 1 file changed, 9 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index a999a0b7d7..405e1736ba 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -101,14 +101,6 @@ module ActionView attr_reader :source, :identifier, :handler, :virtual_path, :formats, :original_encoding - Finalizer = proc do |method_name, mod| - proc do - mod.module_eval do - remove_possible_method method_name - end - end - end - def initialize(source, identifier, handler, details) @source = source @identifier = identifier @@ -253,7 +245,6 @@ module ActionView begin mod.module_eval(source, identifier, 0) - ObjectSpace.define_finalizer(self, Finalizer[method_name, mod]) method_name rescue Exception => e # errors from template code -- cgit v1.2.3 From 8efdffeda31b520b9b534dc614c6039404288c26 Mon Sep 17 00:00:00 2001 From: Neeraj Singh <neerajdotname@gmail.com> Date: Thu, 30 Sep 2010 02:22:00 +0800 Subject: no need of nil check --- actionpack/lib/action_controller/test_case.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 70a5de7f30..1af75fc2d7 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -394,7 +394,7 @@ module ActionController parameters ||= {} @request.assign_parameters(@routes, @controller.class.name.underscore.sub(/_controller$/, ''), action.to_s, parameters) - @request.session = ActionController::TestSession.new(session) unless session.nil? + @request.session = ActionController::TestSession.new(session) if session @request.session["flash"] = @request.flash.update(flash || {}) @request.session["flash"].sweep -- cgit v1.2.3 From 692f5184c405b3b0f9b6ac02c37aaefb7d2ffb62 Mon Sep 17 00:00:00 2001 From: Neeraj Singh <neerajdotname@gmail.com> Date: Thu, 30 Sep 2010 02:24:47 +0800 Subject: no need to check for nil? --- actionpack/lib/action_dispatch/middleware/session/abstract_store.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb index ea49b30630..db0187c015 100644 --- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb @@ -165,7 +165,7 @@ module ActionDispatch return response unless value cookie = { :value => value } - unless options[:expire_after].nil? + if options[:expire_after] cookie[:expires] = Time.now + options.delete(:expire_after) end -- cgit v1.2.3 From 08a08d97dd1307ab9544cc55fbd398c6acdc4c89 Mon Sep 17 00:00:00 2001 From: Neeraj Singh <neerajdotname@gmail.com> Date: Thu, 30 Sep 2010 02:26:22 +0800 Subject: no need to check for nil? --- actionpack/lib/action_view/helpers/form_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index c47fac05ef..cabe272cc7 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1015,7 +1015,7 @@ module ActionView module ClassMethods def value(object, method_name) - object.send method_name unless object.nil? + object.send method_name if object end def value_before_type_cast(object, method_name) @@ -1055,7 +1055,7 @@ module ActionView private def add_default_name_and_id_for_value(tag_value, options) - unless tag_value.nil? + if tag_value pretty_tag_value = tag_value.to_s.gsub(/\s/, "_").gsub(/[^-\w]/, "").downcase specified_id = options["id"] add_default_name_and_id(options) -- cgit v1.2.3 From 618407db56b39a4130e05779339534ae2ebf883e Mon Sep 17 00:00:00 2001 From: Neeraj Singh <neerajdotname@gmail.com> Date: Thu, 30 Sep 2010 02:27:13 +0800 Subject: another case of extra nil? check --- actionpack/lib/action_view/helpers/text_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 3bc5afc2c4..94348cf9fa 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -365,7 +365,7 @@ module ActionView # <% end %> def current_cycle(name = "default") cycle = get_cycle(name) - cycle.current_value unless cycle.nil? + cycle.current_value if cycle end # Resets a cycle so that it starts from the first element the next time -- cgit v1.2.3 From 29c32e832908e13f0e360bbe47c80d5578bffba1 Mon Sep 17 00:00:00 2001 From: Aaron Patterson <aaron.patterson@gmail.com> Date: Wed, 29 Sep 2010 17:57:39 -0700 Subject: tag value can be false, so nil? check is necessary --- actionpack/lib/action_view/helpers/form_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index cabe272cc7..1836baaf12 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1055,7 +1055,7 @@ module ActionView private def add_default_name_and_id_for_value(tag_value, options) - if tag_value + unless tag_value.nil? pretty_tag_value = tag_value.to_s.gsub(/\s/, "_").gsub(/[^-\w]/, "").downcase specified_id = options["id"] add_default_name_and_id(options) -- cgit v1.2.3 From 7e057d11aa21383394e570d0de8f4d5f3729d024 Mon Sep 17 00:00:00 2001 From: Aaron Patterson <aaron.patterson@gmail.com> Date: Wed, 29 Sep 2010 18:23:33 -0700 Subject: fixing regexp warnings --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 189da138d8..0c6e1b37a7 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -349,7 +349,7 @@ module ActionDispatch options = args.last.is_a?(Hash) ? args.pop : {} path = args.shift || block - path_proc = path.is_a?(Proc) ? path : proc { |params| (params.empty? || !path.match(/%{\w*}/)) ? path : (path % params) } + path_proc = path.is_a?(Proc) ? path : proc { |params| (params.empty? || !path.match(/%\{\w*\}/)) ? path : (path % params) } status = options[:status] || 301 lambda do |env| -- cgit v1.2.3 From 31752f3516e5977b459cc713ae50515b20fda67b Mon Sep 17 00:00:00 2001 From: Aaron Patterson <aaron.patterson@gmail.com> Date: Wed, 29 Sep 2010 18:32:51 -0700 Subject: avoid creating a block if possible --- actionpack/lib/action_dispatch/routing/mapper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 0c6e1b37a7..0a888505d2 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -345,10 +345,10 @@ module ActionDispatch # Redirect any path to another path: # # match "/stories" => redirect("/posts") - def redirect(*args, &block) + def redirect(*args) options = args.last.is_a?(Hash) ? args.pop : {} - path = args.shift || block + path = args.shift || Proc.new path_proc = path.is_a?(Proc) ? path : proc { |params| (params.empty? || !path.match(/%\{\w*\}/)) ? path : (path % params) } status = options[:status] || 301 -- cgit v1.2.3 From 69f97f469747777ed1c457715f5361f6b8a0ab7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Thu, 30 Sep 2010 07:25:06 +0200 Subject: Use .find here as it is simpler and faster. --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 0a888505d2..47aed0273c 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1130,7 +1130,7 @@ module ActionDispatch end candidate = name.select(&:present?).join("_").presence - candidate unless as.nil? && @set.routes.map(&:name).include?(candidate) + candidate unless as.nil? && @set.routes.find { |r| r.name == candidate } end end -- cgit v1.2.3 From 22b11a41cc764bc0f7b0c0f518a5289230428597 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki <drogus@gmail.com> Date: Sat, 25 Sep 2010 19:22:32 +0200 Subject: Allow mounting engines at '/' Without that commit script_name always become '/', which results in paths like //posts/1 instead of /posts/1 --- actionpack/lib/action_dispatch/routing/route_set.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 5d18dfe369..99a3019f3a 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -511,7 +511,7 @@ module ActionDispatch end script_name = options.delete(:script_name) - path = (script_name.blank? ? _generate_prefix(options) : script_name).to_s + path = (script_name.blank? ? _generate_prefix(options) : script_name.chomp('/')).to_s path_options = options.except(*RESERVED_OPTIONS) path_options = yield(path_options) if block_given? -- cgit v1.2.3 From ec5d846ac6137e60d81257041e4fde82c0480b32 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki <drogus@gmail.com> Date: Sun, 26 Sep 2010 00:17:06 +0200 Subject: Properly reload routes defined in class definition Sometimes it's easier to define routes inside Engine or Application class definition (e.g. one file applications). The problem with such case is that if there is a plugin that has config/routes.rb file, it will trigger routes reload on application. Since routes definition for application is not in config/routes.rb file routes_reloader will fail to reload application's routes properly. With this commit you can pass routes definition as a block to routes method, which will allow to properly reload it: class MyApp::Application < Rails::Application routes do resources :users end end --- actionpack/lib/action_dispatch/routing/route_set.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 99a3019f3a..32f41934f1 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -1,6 +1,7 @@ require 'rack/mount' require 'forwardable' require 'active_support/core_ext/object/to_query' +require 'active_support/core_ext/hash/slice' module ActionDispatch module Routing -- cgit v1.2.3 From 6a55ca346e543e4e112648cca2a01230c32b21ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Thu, 30 Sep 2010 11:40:51 +0200 Subject: Revert "removing crazy finalizer code until there is proof that we need it" This reverts commit a40e3c1a9604ab3737ad2465c8f6a6db0fe0cc78. --- actionpack/lib/action_view/template.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index 405e1736ba..164d177dcc 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -101,6 +101,16 @@ module ActionView attr_reader :source, :identifier, :handler, :virtual_path, :formats, :original_encoding + # This finalizer is needed (and exactly with a proc inside another proc) + # otherwise templates leak in development. + Finalizer = proc do |method_name, mod| + proc do + mod.module_eval do + remove_possible_method method_name + end + end + end + def initialize(source, identifier, handler, details) @source = source @identifier = identifier @@ -245,6 +255,7 @@ module ActionView begin mod.module_eval(source, identifier, 0) + ObjectSpace.define_finalizer(self, Finalizer[method_name, mod]) method_name rescue Exception => e # errors from template code -- cgit v1.2.3