diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/abstract_controller/rendering.rb | 13 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/compatibility.rb | 8 | ||||
-rw-r--r-- | actionpack/lib/action_controller/test_case.rb | 12 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/testing/integration.rb | 3 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers.rb | 5 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/benchmark_helper.rb | 13 | ||||
-rw-r--r-- | actionpack/lib/action_view/test_case.rb | 52 | ||||
-rw-r--r-- | actionpack/lib/sprockets/static_compiler.rb | 3 | ||||
-rw-r--r-- | actionpack/test/abstract_unit.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/filters_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/view_paths_test.rb | 8 | ||||
-rw-r--r-- | actionpack/test/template/benchmark_helper_test.rb | 24 | ||||
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 4 | ||||
-rw-r--r-- | actionpack/test/template/test_case_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/ts_isolated.rb | 2 |
15 files changed, 98 insertions, 55 deletions
diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 9019c07bca..ddc93464cd 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -1,6 +1,5 @@ require "abstract_controller/base" require "action_view" -require "active_support/core_ext/object/instance_variables" module AbstractController class DoubleRenderError < Error @@ -109,20 +108,20 @@ module AbstractController view_renderer.render(view_context, options) end - DEFAULT_PROTECTED_INSTANCE_VARIABLES = %w( - @_action_name @_response_body @_formats @_prefixes @_config - @_view_context_class @_view_renderer @_lookup_context - ) + DEFAULT_PROTECTED_INSTANCE_VARIABLES = [ + :@_action_name, :@_response_body, :@_formats, :@_prefixes, :@_config, + :@_view_context_class, :@_view_renderer, :@_lookup_context + ] # This method should return a hash with assigns. # You can overwrite this configuration per controller. # :api: public def view_assigns hash = {} - variables = instance_variable_names + variables = instance_variables variables -= protected_instance_variables variables -= DEFAULT_PROTECTED_INSTANCE_VARIABLES - variables.each { |name| hash[name.to_s[1, name.length]] = instance_variable_get(name) } + variables.each { |name| hash[name[1..-1]] = instance_variable_get(name) } hash end diff --git a/actionpack/lib/action_controller/metal/compatibility.rb b/actionpack/lib/action_controller/metal/compatibility.rb index 05dca445a4..43719d5808 100644 --- a/actionpack/lib/action_controller/metal/compatibility.rb +++ b/actionpack/lib/action_controller/metal/compatibility.rb @@ -18,10 +18,10 @@ module ActionController delegate :default_charset=, :to => "ActionDispatch::Response" end - self.protected_instance_variables = %w( - @_status @_headers @_params @_env @_response @_request - @_view_runtime @_stream @_url_options @_action_has_layout - ) + self.protected_instance_variables = [ + :@_status, :@_headers, :@_params, :@_env, :@_response, :@_request, + :@_view_runtime, :@_stream, :@_url_options, :@_action_has_layout + ] def rescue_action(env) raise env["action_dispatch.rescue.exception"] diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 05e9362463..d09d3d844b 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -326,6 +326,12 @@ module ActionController # # assert_redirected_to page_url(:title => 'foo') class TestCase < ActiveSupport::TestCase + + # Use AS::TestCase for the base class when describing a model + register_spec_type(self) do |desc| + desc < ActionController::Base + end + module Behavior extend ActiveSupport::Concern include ActionDispatch::TestProcess @@ -425,7 +431,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) if args.first.is_a?(String) @request.env['RAW_POST_DATA'] = args.shift @@ -500,8 +506,8 @@ module ActionController def check_required_ivars # Sanity check for required instance variables so we can give an # understandable error message. - %w(@routes @controller @request @response).each do |iv_name| - if !(instance_variable_names.include?(iv_name) || instance_variable_names.include?(iv_name.to_sym)) || instance_variable_get(iv_name).nil? + [:@routes, :@controller, :@request, :@response].each do |iv_name| + if !instance_variable_defined?(iv_name) || instance_variable_get(iv_name).nil? raise "#{iv_name} is nil: make sure you set it in your test's setup method." end end diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 26db8662a8..08b7ff49c2 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -4,7 +4,6 @@ require 'active_support/core_ext/kernel/singleton_class' require 'active_support/core_ext/object/inclusion' require 'active_support/core_ext/object/try' require 'rack/test' -require 'test/unit/assertions' module ActionDispatch module Integration #:nodoc: @@ -127,7 +126,7 @@ module ActionDispatch class Session DEFAULT_HOST = "www.example.com" - include Test::Unit::Assertions + include MiniTest::Assertions include TestProcess, RequestHelpers, Assertions %w( status status_message headers body redirect? ).each do |method| diff --git a/actionpack/lib/action_view/helpers.rb b/actionpack/lib/action_view/helpers.rb index 262e0f1010..f2a3a494bc 100644 --- a/actionpack/lib/action_view/helpers.rb +++ b/actionpack/lib/action_view/helpers.rb @@ -1,5 +1,3 @@ -require 'active_support/benchmarkable' - module ActionView #:nodoc: module Helpers #:nodoc: extend ActiveSupport::Autoload @@ -7,6 +5,7 @@ module ActionView #:nodoc: autoload :ActiveModelHelper autoload :AssetTagHelper autoload :AtomFeedHelper + autoload :BenchmarkHelper autoload :CacheHelper autoload :CaptureHelper autoload :ControllerHelper @@ -33,10 +32,10 @@ module ActionView #:nodoc: extend SanitizeHelper::ClassMethods end - include ActiveSupport::Benchmarkable include ActiveModelHelper include AssetTagHelper include AtomFeedHelper + include BenchmarkHelper include CacheHelper include CaptureHelper include ControllerHelper diff --git a/actionpack/lib/action_view/helpers/benchmark_helper.rb b/actionpack/lib/action_view/helpers/benchmark_helper.rb new file mode 100644 index 0000000000..dfdd5a786d --- /dev/null +++ b/actionpack/lib/action_view/helpers/benchmark_helper.rb @@ -0,0 +1,13 @@ +require 'active_support/benchmarkable' + +module ActionView + module Helpers + module BenchmarkHelper + include ActiveSupport::Benchmarkable + + def benchmark(*) + capture { super } + end + end + end +end diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 9ebe498192..c734c914db 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -183,32 +183,32 @@ module ActionView alias_method :_view, :view - INTERNAL_IVARS = %w{ - @__name__ - @__io__ - @_assertion_wrapped - @_assertions - @_result - @_routes - @controller - @layouts - @locals - @method_name - @output_buffer - @partials - @passed - @rendered - @request - @routes - @templates - @options - @test_passed - @view - @view_context_class - } + INTERNAL_IVARS = [ + :@__name__, + :@__io__, + :@_assertion_wrapped, + :@_assertions, + :@_result, + :@_routes, + :@controller, + :@layouts, + :@locals, + :@method_name, + :@output_buffer, + :@partials, + :@passed, + :@rendered, + :@request, + :@routes, + :@templates, + :@options, + :@test_passed, + :@view, + :@view_context_class + ] def _user_defined_ivars - instance_variables.map(&:to_s) - INTERNAL_IVARS + instance_variables - INTERNAL_IVARS end # Returns a Hash of instance variables and their values, as defined by @@ -216,8 +216,8 @@ module ActionView # rendered. This is generally intended for internal use and extension # frameworks. def view_assigns - Hash[_user_defined_ivars.map do |var| - [var[1, var.length].to_sym, instance_variable_get(var)] + Hash[_user_defined_ivars.map do |ivar| + [ivar[1..-1].to_sym, instance_variable_get(ivar)] end] end diff --git a/actionpack/lib/sprockets/static_compiler.rb b/actionpack/lib/sprockets/static_compiler.rb index 32a9d66e6e..719df0bd51 100644 --- a/actionpack/lib/sprockets/static_compiler.rb +++ b/actionpack/lib/sprockets/static_compiler.rb @@ -11,6 +11,7 @@ module Sprockets @digest = options.key?(:digest) ? options.delete(:digest) : true @manifest = options.key?(:manifest) ? options.delete(:manifest) : true @manifest_path = options.delete(:manifest_path) || target + @zip_files = options.delete(:zip_files) || /\.(?:css|html|js|svg|txt|xml)$/ end def compile @@ -36,7 +37,7 @@ module Sprockets filename = File.join(target, path) FileUtils.mkdir_p File.dirname(filename) asset.write_to(filename) - asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/ + asset.write_to("#{filename}.gz") if filename.to_s =~ @zip_files end end diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index a875a9f8b0..0a25d7ba47 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -21,7 +21,7 @@ silence_warnings do Encoding.default_external = "UTF-8" end -require 'test/unit' +require 'minitest/autorun' require 'abstract_controller' require 'action_controller' require 'action_view' diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index d5e3da4d88..9ad0dc75f5 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -16,7 +16,7 @@ class ActionController::Base def assigns(key = nil) assigns = {} - instance_variable_names.each do |ivar| + instance_variables.each do |ivar| next if ActionController::Base.protected_instance_variables.include?(ivar) assigns[ivar[1..-1]] = instance_variable_get(ivar) end diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb index f5ac886c20..872f171c42 100644 --- a/actionpack/test/controller/view_paths_test.rb +++ b/actionpack/test/controller/view_paths_test.rb @@ -16,9 +16,11 @@ class ViewLoadPathsTest < ActionController::TestCase end end - class Test::SubController < ActionController::Base - layout 'test/sub' - def hello_world; render(:template => 'test/hello_world'); end + module Test + class SubController < ActionController::Base + layout 'test/sub' + def hello_world; render(:template => 'test/hello_world'); end + end end def setup diff --git a/actionpack/test/template/benchmark_helper_test.rb b/actionpack/test/template/benchmark_helper_test.rb new file mode 100644 index 0000000000..1bdda22959 --- /dev/null +++ b/actionpack/test/template/benchmark_helper_test.rb @@ -0,0 +1,24 @@ +require 'abstract_unit' +require 'stringio' + +class BenchmarkHelperTest < ActionView::TestCase + include RenderERBUtils + tests ActionView::Helpers::BenchmarkHelper + + def test_output_in_erb + output = render_erb("Hello <%= benchmark do %>world<% end %>") + expected = 'Hello world' + assert_equal expected, output + end + + def test_returns_value_from_block + assert_equal 'test', benchmark { 'test' } + end + + def test_default_message + log = StringIO.new + self.stubs(:logger).returns(Logger.new(log)) + benchmark {} + assert_match(log.rewind && log.read, /Benchmarking \(\d+.\d+ms\)/) + end +end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index ad0cc41d69..82e001732d 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -875,7 +875,7 @@ class FormHelperTest < ActionView::TestCase def test_form_for_with_remote_without_html @post.persisted = false - def @post.to_key; nil; end + @post.stubs(:to_key).returns(nil) form_for(@post, :remote => true) do |f| concat f.text_field(:title) concat f.text_area(:body) @@ -1025,7 +1025,7 @@ class FormHelperTest < ActionView::TestCase old_locale, I18n.locale = I18n.locale, :submit @post.persisted = false - def @post.to_key; nil; end + @post.stubs(:to_key).returns(nil) form_for(@post) do |f| concat f.submit end diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb index a75f1bc981..37858c1ba2 100644 --- a/actionpack/test/template/test_case_test.rb +++ b/actionpack/test/template/test_case_test.rb @@ -155,7 +155,7 @@ module ActionView test "view_assigns excludes internal ivars" do INTERNAL_IVARS.each do |ivar| assert defined?(ivar), "expected #{ivar} to be defined" - assert !view_assigns.keys.include?(ivar.sub('@','').to_sym), "expected #{ivar} to be excluded from view_assigns" + assert !view_assigns.keys.include?(ivar.to_s.sub('@', '').to_sym), "expected #{ivar} to be excluded from view_assigns" end end end diff --git a/actionpack/test/ts_isolated.rb b/actionpack/test/ts_isolated.rb index cb775508ff..7430de2299 100644 --- a/actionpack/test/ts_isolated.rb +++ b/actionpack/test/ts_isolated.rb @@ -1,7 +1,7 @@ $:.unshift(File.dirname(__FILE__)) $:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib') -require 'test/unit' +require 'minitest/autorun' require 'rbconfig' require 'active_support/core_ext/kernel/reporting' require 'abstract_unit' |