Skip to content

Commit

Permalink
Cleaning up more tests and code that needed to work in both old and n…
Browse files Browse the repository at this point in the history
…ew base
  • Loading branch information
Yehuda Katz + Carl Lerche committed Jun 17, 2009
1 parent 55ee0ba commit 65102c8
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 90 deletions.
1 change: 1 addition & 0 deletions actionpack/lib/action_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def self.load_all!
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
Expand Down
6 changes: 1 addition & 5 deletions actionpack/test/controller/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,7 @@ def test_get_on_priv_should_show_selector
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
Expand Down
68 changes: 18 additions & 50 deletions actionpack/test/controller/filters_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,20 @@ class << self
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

Expand Down Expand Up @@ -598,22 +594,11 @@ def test_having_properties_in_around_filter
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
Expand Down Expand Up @@ -876,14 +861,6 @@ def test_with_instance
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']
Expand All @@ -906,18 +883,9 @@ def test_nested_filters
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
Expand Down
19 changes: 3 additions & 16 deletions actionpack/test/controller/helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,7 @@ def test_helper_for_acronym_controller
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')
Expand All @@ -147,12 +143,7 @@ def test_all_helpers_with_alternate_helper_dir
@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
Expand Down Expand Up @@ -184,11 +175,7 @@ def expected_helper_methods
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
Expand Down
16 changes: 7 additions & 9 deletions actionpack/test/controller/mime_responds_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -519,16 +519,14 @@ def test_missing_layout_renders_properly
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
4 changes: 2 additions & 2 deletions actionpack/test/controller/send_file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def test_file_nostream
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
Expand Down
13 changes: 5 additions & 8 deletions actionpack/test/template/body_parts_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,11 +18,9 @@ def index

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

0 comments on commit 65102c8

Please sign in to comment.