diff options
Diffstat (limited to 'actionpack')
38 files changed, 198 insertions, 98 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 48ba1518e0..0ffae5086e 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,10 @@ ## Rails 4.0.0 (unreleased) ## +* `BestStandardsSupport` middleware now appends it's `X-UA-Compatible` value to app's + returned value if any. Fix #8086 + + *Nikita Afanasenko* + * `date_select` helper accepts `with_css_classes: true` to add css classes similar with type of generated select tags. @@ -134,16 +139,6 @@ *Tima Maslyuchenko* -* Fixed a bug with shorthand routes scoped with the `:module` option not - adding the module to the controller as described in issue #6497. - This should now work properly: - - scope :module => "engine" do - get "api/version" # routes to engine/api#version - end - - *Luiz Felipe Garcia Pereira* - * Sprockets integration has been extracted from Action Pack to the `sprockets-rails` gem. `rails` gem is depending on `sprockets-rails` by default. diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb index 388e043f0b..56dc9ab7a1 100644 --- a/actionpack/lib/abstract_controller/base.rb +++ b/actionpack/lib/abstract_controller/base.rb @@ -34,6 +34,15 @@ module AbstractController @abstract = true end + def inherited(klass) # :nodoc: + # define the abstract ivar on subclasses so that we don't get + # uninitialized ivar warnings + unless klass.instance_variable_defined?(:@abstract) + klass.instance_variable_set(:@abstract, false) + end + super + end + # A list of all internal methods for a controller. This finds the first # abstract superclass of a controller, and gets a list of all public # instance methods on that abstract class. Public instance methods of @@ -42,6 +51,7 @@ module AbstractController # (ActionController::Metal and ActionController::Base are defined as abstract) def internal_methods controller = self + controller = controller.superclass until controller.abstract? controller.public_instance_methods(true) end diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 3da2834af0..4b984d0558 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -51,7 +51,7 @@ module AbstractController @view_context_class ||= begin routes = respond_to?(:_routes) && _routes helpers = respond_to?(:_helpers) && _helpers - + Class.new(ActionView::Base) do if routes include routes.url_helpers diff --git a/actionpack/lib/action_controller/metal/exceptions.rb b/actionpack/lib/action_controller/metal/exceptions.rb index 3c9d0c86a7..3844dbf2a6 100644 --- a/actionpack/lib/action_controller/metal/exceptions.rb +++ b/actionpack/lib/action_controller/metal/exceptions.rb @@ -3,6 +3,15 @@ module ActionController end class BadRequest < ActionControllerError #:nodoc: + attr_reader :original_exception + + def initialize(type = nil, e = nil) + return super() unless type && e + + super("Invalid #{type} parameters: #{e.message}") + @original_exception = e + set_backtrace e.backtrace + end end class RenderError < ActionControllerError #:nodoc: diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index 73f2e94cd1..04dc1d37f7 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -196,7 +196,7 @@ module ActionController def permit(*filters) params = self.class.new - filters.each do |filter| + filters.flatten.each do |filter| case filter when Symbol, String then if has_key?(filter) diff --git a/actionpack/lib/action_controller/record_identifier.rb b/actionpack/lib/action_controller/record_identifier.rb index bffd2a02d0..b49128c184 100644 --- a/actionpack/lib/action_controller/record_identifier.rb +++ b/actionpack/lib/action_controller/record_identifier.rb @@ -8,12 +8,12 @@ module ActionController 'ActionView::RecodIdentifier module.' def dom_id(record, prefix = nil) - ActiveSupport::Deprecation.warn 'dom_id ' + MESSAGE + ActiveSupport::Deprecation.warn('dom_id ' + MESSAGE) ActionView::RecordIdentifier.dom_id(record, prefix) end def dom_class(record, prefix = nil) - ActiveSupport::Deprecation.warn 'dom_class ' + MESSAGE + ActiveSupport::Deprecation.warn('dom_class ' + MESSAGE) ActionView::RecordIdentifier.dom_class(record, prefix) end end diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index d007133183..5aecb59df9 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -476,7 +476,7 @@ module ActionController def process(action, http_method = 'GET', *args) check_required_ivars - http_method, args = handle_old_process_api(http_method, args) + http_method, args = handle_old_process_api(http_method, args, caller) if args.first.is_a?(String) && http_method != 'HEAD' @request.env['RAW_POST_DATA'] = args.shift @@ -579,10 +579,10 @@ module ActionController end end - def handle_old_process_api(http_method, args) + def handle_old_process_api(http_method, args, callstack) # 4.0: Remove this method. if http_method.is_a?(Hash) - ActiveSupport::Deprecation.warn("TestCase#process now expects the HTTP method as second argument: process(action, http_method, params, session, flash)") + ActiveSupport::Deprecation.warn("TestCase#process now expects the HTTP method as second argument: process(action, http_method, params, session, flash)", callstack) args.unshift(http_method) http_method = args.last.is_a?(String) ? args.last : "GET" end diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index fc8825d6d9..3de927abc8 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -251,21 +251,17 @@ module ActionDispatch # Override Rack's GET method to support indifferent access def GET - begin - @env["action_dispatch.request.query_parameters"] ||= (normalize_parameters(super) || {}) - rescue TypeError => e - raise ActionController::BadRequest, "Invalid query parameters: #{e.message}" - end + @env["action_dispatch.request.query_parameters"] ||= (normalize_parameters(super) || {}) + rescue TypeError => e + raise ActionController::BadRequest.new(:query, e) end alias :query_parameters :GET # Override Rack's POST method to support indifferent access def POST - begin - @env["action_dispatch.request.request_parameters"] ||= (normalize_parameters(super) || {}) - rescue TypeError => e - raise ActionController::BadRequest, "Invalid request parameters: #{e.message}" - end + @env["action_dispatch.request.request_parameters"] ||= (normalize_parameters(super) || {}) + rescue TypeError => e + raise ActionController::BadRequest.new(:request, e) end alias :request_parameters :POST diff --git a/actionpack/lib/action_dispatch/middleware/best_standards_support.rb b/actionpack/lib/action_dispatch/middleware/best_standards_support.rb index 69adcc419f..d338996240 100644 --- a/actionpack/lib/action_dispatch/middleware/best_standards_support.rb +++ b/actionpack/lib/action_dispatch/middleware/best_standards_support.rb @@ -15,7 +15,13 @@ module ActionDispatch def call(env) status, headers, body = @app.call(env) - headers["X-UA-Compatible"] = @header + + if headers["X-UA-Compatible"] && @header + headers["X-UA-Compatible"] << "," << @header.to_s + else + headers["X-UA-Compatible"] = @header + end + [status, headers, body] end end diff --git a/actionpack/lib/action_dispatch/middleware/remote_ip.rb b/actionpack/lib/action_dispatch/middleware/remote_ip.rb index ec15a2a715..5abf8f2802 100644 --- a/actionpack/lib/action_dispatch/middleware/remote_ip.rb +++ b/actionpack/lib/action_dispatch/middleware/remote_ip.rb @@ -63,9 +63,9 @@ module ActionDispatch }x def initialize(env, middleware) - @env = env - @middleware = middleware - @calculated_ip = false + @env = env + @middleware = middleware + @ip = nil end # Determines originating IP address. REMOTE_ADDR is the standard @@ -100,9 +100,7 @@ module ActionDispatch end def to_s - return @ip if @calculated_ip - @calculated_ip = true - @ip = calculate_ip + @ip ||= calculate_ip end private diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index e337e30766..045299281c 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -182,7 +182,7 @@ module ActionDispatch controller ||= default_controller action ||= default_action - unless controller.is_a?(Regexp) + unless controller.is_a?(Regexp) || to_shorthand controller = [@scope[:module], controller].compact.join("/").presence end diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 2928263163..95cd89a166 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -3,6 +3,7 @@ require 'uri' require 'active_support/core_ext/kernel/singleton_class' require 'active_support/core_ext/object/try' require 'rack/test' +require 'minitest/unit' module ActionDispatch module Integration #:nodoc: @@ -497,8 +498,7 @@ module ActionDispatch def self.app if !@@app && !ActionDispatch.test_app - ActiveSupport::Deprecation.warn "Rails application fallback is deprecated " \ - "and no longer works, please set ActionDispatch.test_app", caller + ActiveSupport::Deprecation.warn "Rails application fallback is deprecated and no longer works, please set ActionDispatch.test_app" end @@app || ActionDispatch.test_app diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 77d8794b7d..459f95bb73 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -69,7 +69,7 @@ module ActionView options = include_seconds_or_options else ActiveSupport::Deprecation.warn "distance_of_time_in_words and time_ago_in_words now accept :include_seconds " + - "as a part of options hash, not a boolean argument", caller + "as a part of options hash, not a boolean argument" options[:include_seconds] ||= !!include_seconds_or_options end diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index b87c2e936f..6abf1e1751 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1181,8 +1181,7 @@ module ActionView def initialize(object_name, object, template, options, block=nil) if block - ActiveSupport::Deprecation.warn( - "Giving a block to FormBuilder is deprecated and has no effect anymore.") + ActiveSupport::Deprecation.warn "Giving a block to FormBuilder is deprecated and has no effect anymore." end @nested_child_index = {} diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index a33b233ed5..b7b3db959e 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -519,7 +519,9 @@ module ActionView else prompt = options options = {} - ActiveSupport::Deprecation.warn "Passing the prompt to grouped_options_for_select as an argument is deprecated. Please use an options hash like `{ prompt: #{prompt.inspect} }`." + message = "Passing the prompt to grouped_options_for_select as an argument is deprecated. " \ + "Please use an options hash like `{ prompt: #{prompt.inspect} }`." + ActiveSupport::Deprecation.warn message end body = "".html_safe diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 0257a13bc4..7f42d6e9c3 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -425,13 +425,17 @@ module ActionView options = options.stringify_keys if disable_with = options.delete("disable_with") - ActiveSupport::Deprecation.warn ":disable_with option is deprecated and will be removed from Rails 4.1. Use ':data => { :disable_with => \'Text\' }' instead" + message = ":disable_with option is deprecated and will be removed from Rails 4.1. " \ + "Use 'data: { disable_with: \'Text\' }' instead." + ActiveSupport::Deprecation.warn message options["data-disable-with"] = disable_with end if confirm = options.delete("confirm") - ActiveSupport::Deprecation.warn ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead'" + message = ":confirm option is deprecated and will be removed from Rails 4.1. " \ + "Use 'data: { confirm: \'Text\' }' instead'." + ActiveSupport::Deprecation.warn message options["data-confirm"] = confirm end @@ -483,13 +487,17 @@ module ActionView options = options.stringify_keys if disable_with = options.delete("disable_with") - ActiveSupport::Deprecation.warn ":disable_with option is deprecated and will be removed from Rails 4.1. Use ':data => { :disable_with => \'Text\' }' instead" + message = ":disable_with option is deprecated and will be removed from Rails 4.1. " \ + "Use 'data: { disable_with: \'Text\' }' instead." + ActiveSupport::Deprecation.warn message options["data-disable-with"] = disable_with end if confirm = options.delete("confirm") - ActiveSupport::Deprecation.warn ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead'" + message = ":confirm option is deprecated and will be removed from Rails 4.1. " \ + "Use 'data: { confirm: \'Text\' }' instead'." + ActiveSupport::Deprecation.warn message options["data-confirm"] = confirm end @@ -533,7 +541,9 @@ module ActionView options = options.stringify_keys if confirm = options.delete("confirm") - ActiveSupport::Deprecation.warn ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead'" + message = ":confirm option is deprecated and will be removed from Rails 4.1. " \ + "Use 'data: { confirm: \'Text\' }' instead'." + ActiveSupport::Deprecation.warn message options["data-confirm"] = confirm end diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index a30326349a..1a99fc7091 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -78,7 +78,8 @@ module ActionView # # => <input class="ok" onclick="alert('Hello world!');" type="button" value="Greeting" /> # def button_to_function(name, function=nil, html_options={}) - message = "button_to_function is deprecated and will be removed from Rails 4.1. Use Unobtrusive JavaScript instead." + message = "button_to_function is deprecated and will be removed from Rails 4.1. We recomend to use Unobtrusive JavaScript instead. " + + "See http://guides.rubyonrails.org/working_with_javascript_in_rails.html#unobtrusive-javascript" ActiveSupport::Deprecation.warn message onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function};" @@ -99,7 +100,8 @@ module ActionView # # => <a class="nav_link" href="#" onclick="alert('Hello world!'); return false;">Greeting</a> # def link_to_function(name, function, html_options={}) - message = "link_to_function is deprecated and will be removed from Rails 4.1. Use Unobtrusive JavaScript instead." + message = "link_to_function is deprecated and will be removed from Rails 4.1. We recomend to use Unobtrusive JavaScript instead. " + + "See http://guides.rubyonrails.org/working_with_javascript_in_rails.html#unobtrusive-javascript" ActiveSupport::Deprecation.warn message onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;" diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 9bfda0ee9c..fd671c9c07 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -577,7 +577,9 @@ module ActionView method = html_options.delete('method') if confirm - ActiveSupport::Deprecation.warn ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead" + message = ":confirm option is deprecated and will be removed from Rails 4.1. " \ + "Use 'data: { confirm: \'Text\' }' instead." + ActiveSupport::Deprecation.warn message html_options["data-confirm"] = confirm end @@ -585,7 +587,9 @@ module ActionView add_method_to_attributes!(html_options, method) if method if disable_with - ActiveSupport::Deprecation.warn ":disable_with option is deprecated and will be removed from Rails 4.1. Use ':data => { :disable_with => \'Text\' }' instead" + message = ":disable_with option is deprecated and will be removed from Rails 4.1. " \ + "Use 'data: { disable_with: \'Text\' }' instead." + ActiveSupport::Deprecation.warn message html_options["data-disable-with"] = disable_with end diff --git a/actionpack/lib/action_view/renderer/template_renderer.rb b/actionpack/lib/action_view/renderer/template_renderer.rb index 156ad4e547..2a5ea5a711 100644 --- a/actionpack/lib/action_view/renderer/template_renderer.rb +++ b/actionpack/lib/action_view/renderer/template_renderer.rb @@ -29,8 +29,11 @@ module ActionView handler = Template.handler_for_extension(options[:type] || "erb") Template.new(options[:inline], "inline template", handler, :locals => keys) elsif options.key?(:template) - options[:template].respond_to?(:render) ? - options[:template] : find_template(options[:template], options[:prefixes], false, keys, @details) + if options[:template].respond_to?(:render) + options[:template] + else + find_template(options[:template], options[:prefixes], false, keys, @details) + end else raise ArgumentError, "You invoked render but did not give any of :partial, :template, :inline, :file or :text option." end diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index 379cdc8a25..aefc42be48 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -149,7 +149,8 @@ module ActionView end def mime_type - ActiveSupport::Deprecation.warn 'Template#mime_type is deprecated and will be removed in Rails 4.1. Please use type method instead.' + message = 'Template#mime_type is deprecated and will be removed in Rails 4.1. Please use type method instead.' + ActiveSupport::Deprecation.warn message @mime_type ||= Mime::Type.lookup_by_extension(@formats.first.to_s) if @formats.first end diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb index 25c6fd4aa8..fc77c1485d 100644 --- a/actionpack/lib/action_view/template/resolver.rb +++ b/actionpack/lib/action_view/template/resolver.rb @@ -232,8 +232,14 @@ module ActionView def extract_handler_and_format(path, default_formats) pieces = File.basename(path).split(".") pieces.shift + extension = pieces.pop - ActiveSupport::Deprecation.warn "The file #{path} did not specify a template handler. The default is currently ERB, but will change to RAW in the future." unless extension + unless extension + message = "The file #{path} did not specify a template handler. The default is currently ERB, " \ + "but will change to RAW in the future." + ActiveSupport::Deprecation.warn message + end + handler = Template.handler_for_extension(extension) format = pieces.last && Template::Types[pieces.last] [handler, format] diff --git a/actionpack/test/activerecord/controller_runtime_test.rb b/actionpack/test/activerecord/controller_runtime_test.rb index 2d789395ce..1df826fe2b 100644 --- a/actionpack/test/activerecord/controller_runtime_test.rb +++ b/actionpack/test/activerecord/controller_runtime_test.rb @@ -15,7 +15,7 @@ class ControllerRuntimeLogSubscriberTest < ActionController::TestCase def zero render :inline => "Zero DB runtime" end - + def redirect Project.all redirect_to :action => 'show' @@ -63,18 +63,18 @@ class ControllerRuntimeLogSubscriberTest < ActionController::TestCase assert_equal 2, @logger.logged(:info).size assert_match(/\(Views: [\d.]+ms \| ActiveRecord: 0.0ms\)/, @logger.logged(:info)[1]) end - + def test_log_with_active_record_when_redirecting get :redirect wait assert_equal 3, @logger.logged(:info).size assert_match(/\(ActiveRecord: [\d.]+ms\)/, @logger.logged(:info)[2]) end - + def test_include_time_query_time_after_rendering get :db_after_render wait - + assert_equal 2, @logger.logged(:info).size assert_match(/\(Views: [\d.]+ms \| ActiveRecord: ([1-9][\d.]+)ms\)/, @logger.logged(:info)[1]) end diff --git a/actionpack/test/controller/default_url_options_with_filter_test.rb b/actionpack/test/controller/default_url_options_with_filter_test.rb index ef028e8cdb..9a9ab17fee 100644 --- a/actionpack/test/controller/default_url_options_with_filter_test.rb +++ b/actionpack/test/controller/default_url_options_with_filter_test.rb @@ -16,7 +16,7 @@ class ControllerWithBeforeFilterAndDefaultUrlOptions < ActionController::Base def default_url_options {:locale => "de"} - end + end end class ControllerWithBeforeFilterAndDefaultUrlOptionsTest < ActionController::TestCase diff --git a/actionpack/test/controller/http_basic_authentication_test.rb b/actionpack/test/controller/http_basic_authentication_test.rb index 7286b249c7..2dcfda02a7 100644 --- a/actionpack/test/controller/http_basic_authentication_test.rb +++ b/actionpack/test/controller/http_basic_authentication_test.rb @@ -19,7 +19,7 @@ class HttpBasicAuthenticationTest < ActionController::TestCase def show render :text => 'Only for loooooong credentials' end - + def search render :text => 'All inline' end @@ -118,7 +118,7 @@ class HttpBasicAuthenticationTest < ActionController::TestCase assert assigns(:logged_in) assert_equal 'Definitely Maybe', @response.body end - + test "authenticate with class method" do @request.env['HTTP_AUTHORIZATION'] = encode_credentials('David', 'Goliath') get :search diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index b21d35c846..d183b0be17 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -240,7 +240,7 @@ class RespondToControllerTest < ActionController::TestCase assert_equal 'HTML', @response.body @request.accept = "text/javascript, text/html" - + assert_raises(ActionController::UnknownFormat) do xhr :get, :just_xml end diff --git a/actionpack/test/controller/new_base/middleware_test.rb b/actionpack/test/controller/new_base/middleware_test.rb index ccef060863..6b7b5e10e3 100644 --- a/actionpack/test/controller/new_base/middleware_test.rb +++ b/actionpack/test/controller/new_base/middleware_test.rb @@ -25,14 +25,14 @@ module MiddlewareTest result end end - + class BlockMiddleware attr_accessor :configurable_message def initialize(app, &block) @app = app yield(self) if block_given? end - + def call(env) result = @app.call(env) result[1]["Configurable-Message"] = configurable_message diff --git a/actionpack/test/controller/new_base/render_partial_test.rb b/actionpack/test/controller/new_base/render_partial_test.rb index b4a25c49c9..2f1aa22208 100644 --- a/actionpack/test/controller/new_base/render_partial_test.rb +++ b/actionpack/test/controller/new_base/render_partial_test.rb @@ -28,7 +28,7 @@ module RenderPartial @test_unchanged = 'hello' end end - + class ChildController < BasicController; end class TestPartial < Rack::TestCase diff --git a/actionpack/test/controller/parameters/parameters_permit_test.rb b/actionpack/test/controller/parameters/parameters_permit_test.rb index ad970f0a9a..fc63470174 100644 --- a/actionpack/test/controller/parameters/parameters_permit_test.rb +++ b/actionpack/test/controller/parameters/parameters_permit_test.rb @@ -77,4 +77,8 @@ class ParametersPermitTest < ActiveSupport::TestCase ActionController::Parameters.permit_all_parameters = false end end + + test "permitting parameters as an array" do + assert_equal "32", @params[:person].permit([ :age ])[:age] + end end diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index 97ede35317..8bf3096888 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -134,7 +134,7 @@ class SendFileTest < ActionController::TestCase @controller.headers = {} assert_raise(ArgumentError){ @controller.send(:send_file_headers!, options) } end - + def test_send_file_headers_guess_type_from_extension { 'image.png' => 'image/png', diff --git a/actionpack/test/dispatch/best_standards_support_test.rb b/actionpack/test/dispatch/best_standards_support_test.rb new file mode 100644 index 0000000000..0737c40a39 --- /dev/null +++ b/actionpack/test/dispatch/best_standards_support_test.rb @@ -0,0 +1,34 @@ +require 'abstract_unit' + +class BestStandardsSupportTest < ActiveSupport::TestCase + def test_with_best_standards_support + _, headers, _ = app(true, {}).call({}) + assert_equal "IE=Edge,chrome=1", headers["X-UA-Compatible"] + end + + def test_with_builtin_best_standards_support + _, headers, _ = app(:builtin, {}).call({}) + assert_equal "IE=Edge", headers["X-UA-Compatible"] + end + + def test_without_best_standards_support + _, headers, _ = app(false, {}).call({}) + assert_equal nil, headers["X-UA-Compatible"] + end + + def test_appends_to_app_headers + app_headers = { "X-UA-Compatible" => "requiresActiveX=true" } + _, headers, _ = app(true, app_headers).call({}) + + expects = "requiresActiveX=true,IE=Edge,chrome=1" + assert_equal expects, headers["X-UA-Compatible"] + end + + private + + def app(type, headers) + app = proc { [200, headers, "response"] } + ActionDispatch::BestStandardsSupport.new(app, type) + end + +end diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index a2b9571660..e2964f9071 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -550,15 +550,30 @@ class RequestTest < ActiveSupport::TestCase test "parameters still accessible after rack parse error" do mock_rack_env = { "QUERY_STRING" => "x[y]=1&x[y][][w]=2", "rack.input" => "foo" } request = nil - begin - request = stub_request(mock_rack_env) - request.parameters - rescue ActionController::BadRequest + request = stub_request(mock_rack_env) + + assert_raises(ActionController::BadRequest) do # rack will raise a TypeError when parsing this query string + request.parameters end + assert_equal({}, request.parameters) end + test "we have access to the original exception" do + mock_rack_env = { "QUERY_STRING" => "x[y]=1&x[y][][w]=2", "rack.input" => "foo" } + request = nil + request = stub_request(mock_rack_env) + + e = assert_raises(ActionController::BadRequest) do + # rack will raise a TypeError when parsing this query string + request.parameters + end + + assert e.original_exception + assert_equal e.original_exception.backtrace, e.backtrace + end + test "formats with accept header" do request = stub_request 'HTTP_ACCEPT' => 'text/html' request.expects(:parameters).at_least_once.returns({}) diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 93d89f7568..34606512dc 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -281,6 +281,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest scope(':version', :version => /.+/) do resources :users, :id => /.+?/, :format => /json|xml/ end + + get "products/list" end get 'sprockets.js' => ::TestRoutingMapper::SprocketsApp @@ -363,7 +365,6 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest resources :errors, :shallow => true do resources :notices end - get 'api/version' end scope :path => 'api' do @@ -1301,10 +1302,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_equal 'account#shorthand', @response.body end - def test_match_shorthand_with_module - assert_equal '/api/version', api_version_path - get '/api/version' - assert_equal 'api/api#version', @response.body + def test_match_shorthand_inside_namespace_with_controller + assert_equal '/api/products/list', api_products_list_path + get '/api/products/list' + assert_equal 'api/products#list', @response.body end def test_dynamically_generated_helpers_on_collection_do_not_clobber_resources_url_helper diff --git a/actionpack/test/template/digestor_test.rb b/actionpack/test/template/digestor_test.rb index b9d26da3af..f493c8201d 100644 --- a/actionpack/test/template/digestor_test.rb +++ b/actionpack/test/template/digestor_test.rb @@ -63,7 +63,7 @@ class TemplateDigestorTest < ActionView::TestCase change_template("comments/_comment") end end - + def test_directory_depth_dependency assert_digest_difference("level/below/index") do change_template("level/below/_header") diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 945dff2a29..0a94fa079b 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -411,7 +411,7 @@ class FormTagHelperTest < ActionView::TestCase end def test_submit_tag_with_deprecated_confirmation - assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead" do + assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do assert_dom_equal( %(<input name='commit' type='submit' value='Save' data-confirm="Are you sure?" />), submit_tag("Save", :confirm => "Are you sure?") @@ -478,7 +478,7 @@ class FormTagHelperTest < ActionView::TestCase end def test_button_tag_with_deprecated_confirmation - assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead" do + assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do assert_dom_equal( %(<button name="button" type="submit" data-confirm="Are you sure?">Save</button>), button_tag("Save", :type => "submit", :confirm => "Are you sure?") @@ -494,7 +494,7 @@ class FormTagHelperTest < ActionView::TestCase end def test_image_submit_tag_with_deprecated_confirmation - assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead" do + assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do assert_dom_equal( %(<input type="image" src="/images/save.gif" data-confirm="Are you sure?" />), image_submit_tag("save.gif", :confirm => "Are you sure?") diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index 58784c26fa..56919dc592 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -43,42 +43,42 @@ class JavaScriptHelperTest < ActionView::TestCase end def test_button_to_function - assert_deprecated "button_to_function is deprecated and will be removed from Rails 4.1. Use Unobtrusive JavaScript instead." do + assert_deprecated do assert_dom_equal %(<input type="button" onclick="alert('Hello world!');" value="Greeting" />), button_to_function("Greeting", "alert('Hello world!')") end end def test_button_to_function_with_onclick - assert_deprecated "button_to_function is deprecated and will be removed from Rails 4.1. Use Unobtrusive JavaScript instead." do + assert_deprecated do assert_dom_equal "<input onclick=\"alert('Goodbye World :('); alert('Hello world!');\" type=\"button\" value=\"Greeting\" />", button_to_function("Greeting", "alert('Hello world!')", :onclick => "alert('Goodbye World :(')") end end def test_button_to_function_without_function - assert_deprecated "button_to_function is deprecated and will be removed from Rails 4.1. Use Unobtrusive JavaScript instead." do + assert_deprecated do assert_dom_equal "<input onclick=\";\" type=\"button\" value=\"Greeting\" />", button_to_function("Greeting") end end def test_link_to_function - assert_deprecated "link_to_function is deprecated and will be removed from Rails 4.1. Use Unobtrusive JavaScript instead." do + assert_deprecated do assert_dom_equal %(<a href="#" onclick="alert('Hello world!'); return false;">Greeting</a>), link_to_function("Greeting", "alert('Hello world!')") end end def test_link_to_function_with_existing_onclick - assert_deprecated "link_to_function is deprecated and will be removed from Rails 4.1. Use Unobtrusive JavaScript instead." do + assert_deprecated do assert_dom_equal %(<a href="#" onclick="confirm('Sanity!'); alert('Hello world!'); return false;">Greeting</a>), link_to_function("Greeting", "alert('Hello world!')", :onclick => "confirm('Sanity!')") end end def test_function_with_href - assert_deprecated "link_to_function is deprecated and will be removed from Rails 4.1. Use Unobtrusive JavaScript instead." do + assert_deprecated do assert_dom_equal %(<a href="http://example.com/" onclick="alert('Hello world!'); return false;">Greeting</a>), link_to_function("Greeting", "alert('Hello world!')", :href => 'http://example.com/') end diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index ddf5c6a1b3..4e6a676fc6 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -451,12 +451,12 @@ module RenderTestCases assert_equal %(<title>David</title>), @view.render(:file => "test/layout_render_object") end - + def test_render_with_passing_couple_extensions_to_one_register_template_handler_function_call ActionView::Template.register_template_handler :foo1, :foo2, CustomHandler assert_equal @view.render(:inline => "Hello, World!", :type => :foo1), @view.render(:inline => "Hello, World!", :type => :foo2) end - + def test_render_throws_exception_when_no_extensions_passed_to_register_template_handler_function_call assert_raises(ArgumentError) { ActionView::Template.register_template_handler CustomHandler } end diff --git a/actionpack/test/template/tag_helper_test.rb b/actionpack/test/template/tag_helper_test.rb index f0a7ce0bc9..9e711c6529 100644 --- a/actionpack/test/template/tag_helper_test.rb +++ b/actionpack/test/template/tag_helper_test.rb @@ -87,6 +87,11 @@ class TagHelperTest < ActionView::TestCase assert_equal "<p class=\"song play>\">limelight</p>", str end + def test_content_tag_with_data_attributes + assert_dom_equal '<p data-number="1" data-string="hello" data-string-with-quotes="double"quote"party"">limelight</p>', + content_tag('p', "limelight", data: { number: 1, string: 'hello', string_with_quotes: 'double"quote"party"' }) + end + def test_cdata_section assert_equal "<![CDATA[<hello world>]]>", cdata_section("<hello world>") end @@ -118,8 +123,8 @@ class TagHelperTest < ActionView::TestCase def test_data_attributes ['data', :data].each { |data| - assert_dom_equal '<a data-a-float="3.14" data-a-big-decimal="-123.456" data-a-number="1" data-array="[1,2,3]" data-hash="{"key":"value"}" data-string="hello" data-symbol="foo" />', - tag('a', { data => { :a_float => 3.14, :a_big_decimal => BigDecimal.new("-123.456"), :a_number => 1, :string => 'hello', :symbol => :foo, :array => [1, 2, 3], :hash => { :key => 'value'} } }) + assert_dom_equal '<a data-a-float="3.14" data-a-big-decimal="-123.456" data-a-number="1" data-array="[1,2,3]" data-hash="{"key":"value"}" data-string-with-quotes="double"quote"party"" data-string="hello" data-symbol="foo" />', + tag('a', { data => { a_float: 3.14, a_big_decimal: BigDecimal.new("-123.456"), a_number: 1, string: 'hello', symbol: :foo, array: [1, 2, 3], hash: { key: 'value'}, string_with_quotes: 'double"quote"party"' } }) } end end diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index bbfdf7f944..1bb625213d 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -95,7 +95,7 @@ class UrlHelperTest < ActiveSupport::TestCase end def test_button_to_with_deprecated_confirm - assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead" do + assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do assert_dom_equal( %{<form method="post" action="http://www.example.com" class="button_to"><div><input data-confirm="Are you sure?" type="submit" value="Hello" /></div></form>}, button_to("Hello", "http://www.example.com", confirm: "Are you sure?") @@ -111,7 +111,7 @@ class UrlHelperTest < ActiveSupport::TestCase end def test_button_to_with_javascript_deprecated_disable_with - assert_deprecated ":disable_with option is deprecated and will be removed from Rails 4.1. Use ':data => { :disable_with => \'Text\' }' instead" do + assert_deprecated ":disable_with option is deprecated and will be removed from Rails 4.1. Use 'data: { disable_with: \'Text\' }' instead" do assert_dom_equal( %{<form method="post" action="http://www.example.com" class="button_to"><div><input data-disable-with="Greeting..." type="submit" value="Hello" /></div></form>}, button_to("Hello", "http://www.example.com", disable_with: "Greeting...") @@ -134,7 +134,7 @@ class UrlHelperTest < ActiveSupport::TestCase end def test_button_to_with_remote_and_javascript_with_deprecated_confirm - assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead" do + assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do assert_dom_equal( %{<form method="post" action="http://www.example.com" class="button_to" data-remote="true"><div><input data-confirm="Are you sure?" type="submit" value="Hello" /></div></form>}, button_to("Hello", "http://www.example.com", remote: true, confirm: "Are you sure?") @@ -150,7 +150,7 @@ class UrlHelperTest < ActiveSupport::TestCase end def test_button_to_with_remote_and_javascript_deprecated_disable_with - assert_deprecated ":disable_with option is deprecated and will be removed from Rails 4.1. Use ':data => { :disable_with => \'Text\' }' instead" do + assert_deprecated ":disable_with option is deprecated and will be removed from Rails 4.1. Use 'data: { disable_with: \'Text\' }' instead" do assert_dom_equal( %{<form method="post" action="http://www.example.com" class="button_to" data-remote="true"><div><input data-disable-with="Greeting..." type="submit" value="Hello" /></div></form>}, button_to("Hello", "http://www.example.com", remote: true, disable_with: "Greeting...") @@ -267,19 +267,19 @@ class UrlHelperTest < ActiveSupport::TestCase end def test_link_tag_with_deprecated_confirm - assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead" do + assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do assert_dom_equal( %{<a href="http://www.example.com" data-confirm="Are you sure?">Hello</a>}, link_to("Hello", "http://www.example.com", confirm: "Are you sure?") ) end - assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead" do + assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do assert_dom_equal( %{<a href="http://www.example.com" data-confirm="You cant possibly be sure, can you?">Hello</a>}, link_to("Hello", "http://www.example.com", confirm: "You cant possibly be sure, can you?") ) end - assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead" do + assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do assert_dom_equal( %{<a href="http://www.example.com" data-confirm="You cant possibly be sure,\n can you?">Hello</a>}, link_to("Hello", "http://www.example.com", confirm: "You cant possibly be sure,\n can you?") @@ -351,7 +351,7 @@ class UrlHelperTest < ActiveSupport::TestCase end def test_link_tag_using_post_javascript_and_with_deprecated_confirm - assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead" do + assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do assert_dom_equal( %{<a href="http://www.example.com" data-method="post" rel="nofollow" data-confirm="Are you serious?">Hello</a>}, link_to("Hello", "http://www.example.com", method: :post, confirm: "Are you serious?") @@ -367,7 +367,7 @@ class UrlHelperTest < ActiveSupport::TestCase end def test_link_tag_using_delete_javascript_and_href_and_with_deprecated_confirm - assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead" do + assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do assert_dom_equal( %{<a href="\#" rel="nofollow" data-confirm="Are you serious?" data-method="delete">Destroy</a>}, link_to("Destroy", "http://www.example.com", method: :delete, href: '#', confirm: "Are you serious?") |