From c9f89dedc3bc6a597d868988797986c0e95434d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 25 Sep 2012 19:58:26 -0300 Subject: [PATCH] Make the Action Pack tests pass --- active_record-observers.gemspec | 2 + .../actionpack/action_controller/caching.rb | 4 +- .../active_model/active_model.rb | 4 +- .../active_model/observing.rb | 2 +- .../activerecord/observer.rb | 1 + test/actionpack/controller/filters_test.rb | 53 +++++++++++++++++++ 6 files changed, 61 insertions(+), 5 deletions(-) diff --git a/active_record-observers.gemspec b/active_record-observers.gemspec index 3177dec..ff00313 100644 --- a/active_record-observers.gemspec +++ b/active_record-observers.gemspec @@ -18,6 +18,8 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'minitest', '>= 3' gem.add_development_dependency 'mocha' gem.add_development_dependency 'activerecord', '~> 4.0.0.beta' + gem.add_development_dependency 'activemodel', '~> 4.0.0.beta' gem.add_development_dependency 'actionmailer', '~> 4.0.0.beta' + gem.add_development_dependency 'actionpack', '~> 4.0.0.beta' gem.add_development_dependency 'sqlite3', '~> 1.3' end diff --git a/lib/active_record-observers/actionpack/action_controller/caching.rb b/lib/active_record-observers/actionpack/action_controller/caching.rb index b3fc99c..7a4fdc3 100644 --- a/lib/active_record-observers/actionpack/action_controller/caching.rb +++ b/lib/active_record-observers/actionpack/action_controller/caching.rb @@ -2,8 +2,8 @@ module ActionController #:nodoc: module Caching eager_autoload do - autoload :Sweeper, 'action_controller/caching/sweeping' - autoload :Sweeping, 'action_controller/caching/sweeping' + autoload :Sweeper, 'active_record-observers/actionpack/action_controller/caching/sweeping' + autoload :Sweeping, 'active_record-observers/actionpack/action_controller/caching/sweeping' end include Sweeping if defined?(ActiveRecord) diff --git a/lib/active_record-observers/active_model/active_model.rb b/lib/active_record-observers/active_model/active_model.rb index 85b5247..47c77f5 100644 --- a/lib/active_record-observers/active_model/active_model.rb +++ b/lib/active_record-observers/active_model/active_model.rb @@ -1,4 +1,4 @@ module ActiveModel - autoload :Observer, 'active_model/observing' - autoload :Observing + autoload :Observer, 'active_record-observers/active_model/observing' + autoload :Observing, 'active_record-observers/active_model/observing' end diff --git a/lib/active_record-observers/active_model/observing.rb b/lib/active_record-observers/active_model/observing.rb index 3b089b8..5704ff4 100644 --- a/lib/active_record-observers/active_model/observing.rb +++ b/lib/active_record-observers/active_model/observing.rb @@ -1,5 +1,5 @@ require 'singleton' -require 'active_model/observer_array' +require 'active_record-observers/active_model/observer_array' require 'active_support/core_ext/module/aliasing' require 'active_support/core_ext/module/remove_method' require 'active_support/core_ext/string/inflections' diff --git a/lib/active_record-observers/activerecord/observer.rb b/lib/active_record-observers/activerecord/observer.rb index 6b2f6f9..684e028 100644 --- a/lib/active_record-observers/activerecord/observer.rb +++ b/lib/active_record-observers/activerecord/observer.rb @@ -1,3 +1,4 @@ +require 'active_record-observers/active_model/active_model' module ActiveRecord # = Active Record Observer diff --git a/test/actionpack/controller/filters_test.rb b/test/actionpack/controller/filters_test.rb index 17ed722..fb491c7 100644 --- a/test/actionpack/controller/filters_test.rb +++ b/test/actionpack/controller/filters_test.rb @@ -1,5 +1,39 @@ +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 @@ -11,6 +45,16 @@ def error 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 @@ -39,5 +83,14 @@ 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