Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

More fixes in the tests #3

Merged
merged 2 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 25, 2012
  1. @rafaelfranca

    Remove Action Mailer observers stuff since they don't have anything to

    rafaelfranca authored
    do with Active Record Observers
  2. @rafaelfranca
This page is out of date. Refresh to see the latest.
View
2  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
View
24 lib/active_record-observers/action_mailer/base.rb
@@ -1,24 +0,0 @@
-module ActionMailer
- # Action Mailer provides hooks into the Mail observer and interceptor methods. These allow you to
- # register classes that are called during the mail delivery life cycle.
- #
- # An observer class must implement the <tt>:delivered_email(message)</tt> method which will be
- # called once for every email sent after the email has been sent.
- #
- class Base
- class << self
- # Register one or more Observers which will be notified when mail is delivered.
- def register_observers(*observers)
- observers.flatten.compact.each { |observer| register_observer(observer) }
- end
-
- # Register an Observer which will be notified when mail is delivered.
- # Either a class or a string can be passed in as the Observer. If a string is passed in
- # it will be <tt>constantize</tt>d.
- def register_observer(observer)
- delivery_observer = (observer.is_a?(String) ? observer.constantize : observer)
- Mail.register_observer(delivery_observer)
- end
- end
- end
-end
View
10 lib/active_record-observers/action_mailer/railtie.rb
@@ -1,10 +0,0 @@
-module ActionMailer
- class Railtie
- initializer "action_mailer.register_observers" do |app|
-
- ActiveSupport.on_load(:action_mailer) do
- register_observers(options.delete(:observers))
- end
- end
- end
-end
View
4 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)
View
4 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
View
2  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'
View
1  lib/active_record-observers/activerecord/observer.rb
@@ -1,3 +1,4 @@
+require 'active_record-observers/active_model/active_model'
module ActiveRecord
# = Active Record Observer
View
76 test/action_mailer/base_test.rb
@@ -1,76 +0,0 @@
-require 'minitest/autorun'
-require 'action_mailer'
-
-FIXTURE_LOAD_PATH = File.expand_path('fixtures', File.dirname(__FILE__))
-ActionMailer::Base.view_paths = FIXTURE_LOAD_PATH
-
-class MockSMTP
- def self.deliveries
- @@deliveries
- end
-
- def initialize
- @@deliveries = []
- end
-
- def sendmail(mail, from, to)
- @@deliveries << [mail, from, to]
- end
-
- def start(*args)
- yield self
- end
-end
-
-class Net::SMTP
- def self.new(*args)
- MockSMTP.new
- end
-end
-
-class BaseMailer < ActionMailer::Base
- self.mailer_name = "base_mailer"
-
- default :to => 'system@test.lindsaar.net',
- :from => 'jose@test.plataformatec.com',
- :reply_to => 'mikel@test.lindsaar.net'
-
- def welcome(hash = {})
- headers['X-SPAM'] = "Not SPAM"
- mail({:subject => "The first email on new API!"}.merge!(hash))
- end
-end
-
-class BaseTest < ActiveSupport::TestCase
- class MyObserver
- def self.delivered_email(mail)
- end
- end
-
- class MySecondObserver
- def self.delivered_email(mail)
- end
- end
-
- test "you can register an observer to the mail object that gets informed on email delivery" do
- ActionMailer::Base.register_observer(MyObserver)
- mail = BaseMailer.welcome
- MyObserver.expects(:delivered_email).with(mail)
- mail.deliver
- end
-
- test "you can register an observer using its stringified name to the mail object that gets informed on email delivery" do
- ActionMailer::Base.register_observer("BaseTest::MyObserver")
- mail = BaseMailer.welcome
- MyObserver.expects(:delivered_email).with(mail)
- mail.deliver
- end
-
- test "you can register multiple observers to the mail object that both get informed on email delivery" do
- ActionMailer::Base.register_observers("BaseTest::MyObserver", MySecondObserver)
- mail = BaseMailer.welcome
- MyObserver.expects(:delivered_email).with(mail)
- MySecondObserver.expects(:delivered_email).with(mail)
- mail.deliver
- end
-end
View
0  test/action_mailer/fixtures/base_mailer/welcome.html
No changes.
View
53 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
Something went wrong with that request. Please try again.