mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Cleaning up more tests and code that needed to work in both old and new base
This commit is contained in:
parent
55ee0ba7f5
commit
65102c8f1a
7 changed files with 37 additions and 90 deletions
|
@ -48,6 +48,7 @@ module ActionView
|
|||
autoload :TemplateHandlers, 'action_view/template/handlers'
|
||||
autoload :TextTemplate, 'action_view/template/text'
|
||||
autoload :Helpers, 'action_view/helpers'
|
||||
autoload :FileSystemResolverWithFallback, 'action_view/template/resolver'
|
||||
end
|
||||
|
||||
class ERB
|
||||
|
|
|
@ -146,11 +146,7 @@ class PerformActionTest < ActionController::TestCase
|
|||
def test_method_missing_is_not_an_action_name
|
||||
use_controller MethodMissingController
|
||||
|
||||
if defined?(ActionController::Http)
|
||||
assert ! @controller.__send__(:action_method?, 'method_missing')
|
||||
else
|
||||
assert ! @controller.__send__(:action_methods).include?('method_missing')
|
||||
end
|
||||
assert ! @controller.__send__(:action_method?, 'method_missing')
|
||||
|
||||
get :method_missing
|
||||
assert_response :success
|
||||
|
|
|
@ -9,24 +9,20 @@ class ActionController::Base
|
|||
end unless method_defined?(pending)
|
||||
end
|
||||
|
||||
if defined?(ActionController::Http)
|
||||
def before_filters
|
||||
filters = _process_action_callbacks.select { |c| c.kind == :before }
|
||||
filters.map! { |c| c.instance_variable_get(:@raw_filter) }
|
||||
end
|
||||
def before_filters
|
||||
filters = _process_action_callbacks.select { |c| c.kind == :before }
|
||||
filters.map! { |c| c.instance_variable_get(:@raw_filter) }
|
||||
end
|
||||
end
|
||||
|
||||
if defined?(ActionController::Http)
|
||||
def assigns(key = nil)
|
||||
assigns = {}
|
||||
instance_variable_names.each do |ivar|
|
||||
next if ActionController::Base.protected_instance_variables.include?(ivar)
|
||||
assigns[ivar[1..-1]] = instance_variable_get(ivar)
|
||||
end
|
||||
|
||||
key.nil? ? assigns : assigns[key.to_s]
|
||||
def assigns(key = nil)
|
||||
assigns = {}
|
||||
instance_variable_names.each do |ivar|
|
||||
next if ActionController::Base.protected_instance_variables.include?(ivar)
|
||||
assigns[ivar[1..-1]] = instance_variable_get(ivar)
|
||||
end
|
||||
|
||||
key.nil? ? assigns : assigns[key.to_s]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -598,22 +594,11 @@ class FilterTest < ActionController::TestCase
|
|||
assert_equal "before and after", assigns["execution_log"]
|
||||
end
|
||||
|
||||
for_tag(:old_base) do
|
||||
def test_prepending_and_appending_around_filter
|
||||
controller = test_process(MixedFilterController)
|
||||
assert_equal " before aroundfilter before procfilter before appended aroundfilter " +
|
||||
" after appended aroundfilter after aroundfilter after procfilter ",
|
||||
MixedFilterController.execution_log
|
||||
end
|
||||
end
|
||||
|
||||
for_tag(:new_base) do
|
||||
def test_prepending_and_appending_around_filter
|
||||
controller = test_process(MixedFilterController)
|
||||
assert_equal " before aroundfilter before procfilter before appended aroundfilter " +
|
||||
" after appended aroundfilter after procfilter after aroundfilter ",
|
||||
MixedFilterController.execution_log
|
||||
end
|
||||
def test_prepending_and_appending_around_filter
|
||||
controller = test_process(MixedFilterController)
|
||||
assert_equal " before aroundfilter before procfilter before appended aroundfilter " +
|
||||
" after appended aroundfilter after procfilter after aroundfilter ",
|
||||
MixedFilterController.execution_log
|
||||
end
|
||||
|
||||
def test_rendering_breaks_filtering_chain
|
||||
|
@ -876,14 +861,6 @@ class YieldingAroundFiltersTest < ActionController::TestCase
|
|||
assert_raise(After) { test_process(controller,'raises_after') }
|
||||
end
|
||||
|
||||
for_tag(:old_base) do
|
||||
def test_with_method
|
||||
controller = ControllerWithFilterMethod
|
||||
assert_nothing_raised { test_process(controller,'no_raise') }
|
||||
assert_raise(After) { test_process(controller,'raises_after') }
|
||||
end
|
||||
end
|
||||
|
||||
def test_with_proc
|
||||
test_process(ControllerWithProcFilter,'no_raise')
|
||||
assert assigns['before']
|
||||
|
@ -906,18 +883,9 @@ class YieldingAroundFiltersTest < ActionController::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
for_tag(:old_base) do
|
||||
def test_filter_order_with_all_filter_types
|
||||
test_process(ControllerWithAllTypesOfFilters,'no_raise')
|
||||
assert_equal 'before around (before yield) around_again (before yield) around_again (after yield) around (after yield) after', assigns['ran_filter'].join(' ')
|
||||
end
|
||||
end
|
||||
|
||||
for_tag(:new_base) do
|
||||
def test_filter_order_with_all_filter_types
|
||||
test_process(ControllerWithAllTypesOfFilters,'no_raise')
|
||||
assert_equal 'before around (before yield) around_again (before yield) around_again (after yield) after around (after yield)', assigns['ran_filter'].join(' ')
|
||||
end
|
||||
def test_filter_order_with_all_filter_types
|
||||
test_process(ControllerWithAllTypesOfFilters,'no_raise')
|
||||
assert_equal 'before around (before yield) around_again (before yield) around_again (after yield) after around (after yield)', assigns['ran_filter'].join(' ')
|
||||
end
|
||||
|
||||
def test_filter_order_with_skip_filter_method
|
||||
|
|
|
@ -127,11 +127,7 @@ class HelperTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_all_helpers
|
||||
methods = if defined?(ActionController::Http)
|
||||
AllHelpersController._helpers.instance_methods.map {|m| m.to_s}
|
||||
else
|
||||
AllHelpersController.master_helper_module.instance_methods.map {|m| m.to_s}
|
||||
end
|
||||
methods = AllHelpersController._helpers.instance_methods.map {|m| m.to_s}
|
||||
|
||||
# abc_helper.rb
|
||||
assert methods.include?('bare_a')
|
||||
|
@ -147,12 +143,7 @@ class HelperTest < Test::Unit::TestCase
|
|||
@controller_class.helpers_dir = File.dirname(__FILE__) + '/../fixtures/alternate_helpers'
|
||||
|
||||
# Reload helpers
|
||||
if defined?(ActionController::Http)
|
||||
@controller_class._helpers = Module.new
|
||||
else
|
||||
@controller_class.master_helper_module = Module.new
|
||||
end
|
||||
|
||||
@controller_class._helpers = Module.new
|
||||
@controller_class.helper :all
|
||||
|
||||
# helpers/abc_helper.rb should not be included
|
||||
|
@ -184,11 +175,7 @@ class HelperTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def master_helper_methods
|
||||
if defined?(ActionController::Http)
|
||||
@controller_class._helpers.instance_methods.map {|m| m.to_s }
|
||||
else
|
||||
@controller_class.master_helper_module.instance_methods.map {|m| m.to_s }
|
||||
end
|
||||
@controller_class._helpers.instance_methods.map {|m| m.to_s }
|
||||
end
|
||||
|
||||
def missing_methods
|
||||
|
|
|
@ -519,16 +519,14 @@ class MimeControllerLayoutsTest < ActionController::TestCase
|
|||
assert_equal 'Hello iPhone', @response.body
|
||||
end
|
||||
|
||||
for_tag(:old_base) do
|
||||
def test_format_with_inherited_layouts
|
||||
@controller = SuperPostController.new
|
||||
def test_format_with_inherited_layouts
|
||||
@controller = SuperPostController.new
|
||||
|
||||
get :index
|
||||
assert_equal 'Super Firefox', @response.body
|
||||
get :index
|
||||
assert_equal '<html><div id="html">Super Firefox</div></html>', @response.body
|
||||
|
||||
@request.accept = "text/iphone"
|
||||
get :index
|
||||
assert_equal '<html><div id="super_iphone">Super iPhone</div></html>', @response.body
|
||||
end
|
||||
@request.accept = "text/iphone"
|
||||
get :index
|
||||
assert_equal '<html><div id="super_iphone">Super iPhone</div></html>', @response.body
|
||||
end
|
||||
end
|
||||
|
|
|
@ -45,8 +45,8 @@ class SendFileTest < ActionController::TestCase
|
|||
assert_equal file_data, response.body
|
||||
end
|
||||
|
||||
for_tag(:old_base) do
|
||||
def test_file_stream
|
||||
def test_file_stream
|
||||
pending do
|
||||
response = nil
|
||||
assert_nothing_raised { response = process('file') }
|
||||
assert_not_nil response
|
||||
|
|
|
@ -4,9 +4,8 @@ class BodyPartsTest < ActionController::TestCase
|
|||
RENDERINGS = [Object.new, Object.new, Object.new]
|
||||
|
||||
class TestController < ActionController::Base
|
||||
def performed?
|
||||
defined?(ActionController::Http) ? true : super
|
||||
end
|
||||
def performed?() true end
|
||||
|
||||
def index
|
||||
RENDERINGS.each do |rendering|
|
||||
@template.punctuate_body! rendering
|
||||
|
@ -19,11 +18,9 @@ class BodyPartsTest < ActionController::TestCase
|
|||
|
||||
def test_body_parts
|
||||
get :index
|
||||
pending(:old_base) do
|
||||
# TestProcess buffers body_parts into body
|
||||
# TODO: Rewrite test w/o going through process
|
||||
assert_equal RENDERINGS, @response.body_parts
|
||||
end
|
||||
# TestProcess buffers body_parts into body
|
||||
# TODO: Rewrite test w/o going through process
|
||||
assert_equal RENDERINGS, @response.body_parts
|
||||
assert_equal RENDERINGS.join, @response.body
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue