Skip to content

Commit

Permalink
Cleanup the actionpack related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Mendonça França committed Sep 25, 2012
1 parent 56e0aee commit d91b86f
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 119 deletions.
Expand Up @@ -79,34 +79,34 @@ def around(controller)
end

protected
# gets the action cache path for the given options.
def action_path_for(options)
Actions::ActionCachePath.new(controller, options).path
end
# gets the action cache path for the given options.
def action_path_for(options)
Actions::ActionCachePath.new(controller, options).path
end

# Retrieve instance variables set in the controller.
def assigns(key)
controller.instance_variable_get("@#{key}")
end
# Retrieve instance variables set in the controller.
def assigns(key)
controller.instance_variable_get("@#{key}")
end

private
def clean_up
# Clean up, so that the controller can be collected after this request
self.controller = nil
end
def clean_up
# Clean up, so that the controller can be collected after this request
self.controller = nil
end

def callback(timing)
controller_callback_method_name = "#{timing}_#{controller.controller_name.underscore}"
action_callback_method_name = "#{controller_callback_method_name}_#{controller.action_name}"
def callback(timing)
controller_callback_method_name = "#{timing}_#{controller.controller_name.underscore}"
action_callback_method_name = "#{controller_callback_method_name}_#{controller.action_name}"

__send__(controller_callback_method_name) if respond_to?(controller_callback_method_name, true)
__send__(action_callback_method_name) if respond_to?(action_callback_method_name, true)
end
__send__(controller_callback_method_name) if respond_to?(controller_callback_method_name, true)
__send__(action_callback_method_name) if respond_to?(action_callback_method_name, true)
end

def method_missing(method, *arguments, &block)
return super unless @controller
@controller.__send__(method, *arguments, &block)
end
def method_missing(method, *arguments, &block)
return super unless @controller
@controller.__send__(method, *arguments, &block)
end
end
end
end
Expand Down
96 changes: 0 additions & 96 deletions test/actionpack/controller/filters_test.rb

This file was deleted.

72 changes: 71 additions & 1 deletion test/actionpack/controller/sweeper_test.rb
@@ -1,5 +1,65 @@
require 'minitest/autorun'
require 'action_controller'
require 'active_record-observers/activerecord/observer'
require 'active_record-observers/actionpack/action_controller/caching'

SharedTestRoutes = ActionDispatch::Routing::RouteSet.new

class AppSweeper < ActionController::Caching::Sweeper; end

class SweeperTestController < ActionController::Base
include SharedTestRoutes.url_helpers

cache_sweeper :app_sweeper

def show
render text: 'hello world'
end

def error
raise StandardError.new
end
end

class SweeperTest < ActionController::TestCase
class ::AppSweeper < ActionController::Caching::Sweeper; end
def setup
@routes = SharedTestRoutes

@routes.draw do
get ':controller(/:action)'
end

super
end

def test_sweeper_should_not_ignore_no_method_error
sweeper = ActionController::Caching::Sweeper.send(:new)
assert_raise NoMethodError do
sweeper.send_not_defined
end
end

def test_sweeper_should_not_block_rendering
response = test_process(SweeperTestController)
assert_equal 'hello world', response.body
end

def test_sweeper_should_clean_up_if_exception_is_raised
assert_raise StandardError do
test_process(SweeperTestController, 'error')
end
assert_nil AppSweeper.instance.controller
end

def test_before_method_of_sweeper_should_always_return_true
sweeper = ActionController::Caching::Sweeper.send(:new)
assert sweeper.before(SweeperTestController.new)
end

def test_after_method_of_sweeper_should_always_return_nil
sweeper = ActionController::Caching::Sweeper.send(:new)
assert_nil sweeper.after(SweeperTestController.new)
end

def test_sweeper_should_not_ignore_unknown_method_calls
sweeper = ActionController::Caching::Sweeper.send(:new)
Expand All @@ -9,4 +69,14 @@ def test_sweeper_should_not_ignore_unknown_method_calls
end
end
end

private

def test_process(controller, action = "show")
@controller = controller.is_a?(Class) ? controller.new : controller
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new

process(action)
end
end

0 comments on commit d91b86f

Please sign in to comment.