Permalink
Browse files

Cleanup the actionpack related tests

  • Loading branch information...
1 parent 56e0aee commit d91b86fdbfaaf8a701194014a0d2d7e883c3ae09 Rafael Mendonça França committed Sep 25, 2012
@@ -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
@@ -1,96 +0,0 @@
-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
-
-module ActionController
- class Base
- include SharedTestRoutes.url_helpers
- end
-end
-
-class FilterTest < ActionController::TestCase
- class TestController < ActionController::Base
- before_filter :ensure_login
- after_filter :clean_up
-
- def show
- render :inline => "ran action"
- end
-
- private
- def ensure_login
- @ran_filter ||= []
- @ran_filter << "ensure_login"
- end
-
- def clean_up
- @ran_after_filter ||= []
- @ran_after_filter << "clean_up"
- end
- end
-
- class ::AppSweeper < ActionController::Caching::Sweeper; end
-
- class SweeperTestController < ActionController::Base
- cache_sweeper :app_sweeper
- def show
- render :text => 'hello world'
- end
-
- def error
- raise StandardError.new
- end
- 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(TestController.new)
- end
-
- def test_after_method_of_sweeper_should_always_return_nil
- sweeper = ActionController::Caching::Sweeper.send(:new)
- assert_nil sweeper.after(TestController.new)
- 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
-
@@ -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)
@@ -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.