Skip to content
This repository
Browse code

Fixed that you don't have to call super in ActionMailer::TestCase#set…

…up (closes #10406) [jamesgolick]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8536 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 6a6367d7d207e54fced36b58a1abdd7ef0d36f82 1 parent 64b4c18
David Heinemeier Hansson authored January 03, 2008
5  actionmailer/CHANGELOG
... ...
@@ -1,3 +1,8 @@
  1
+*SVN*
  2
+
  3
+* Fixed that you don't have to call super in ActionMailer::TestCase#setup #10406 [jamesgolick]
  4
+
  5
+
1 6
 *2.0.2* (December 16th, 2007)
2 7
 
3 8
 * Included in Rails 2.0.2
15  actionmailer/lib/action_mailer/test_case.rb
@@ -33,7 +33,7 @@ def determine_default_mailer(name)
33 33
       end
34 34
     end
35 35
 
36  
-    def setup
  36
+    def setup_with_mailer
37 37
       ActionMailer::Base.delivery_method = :test
38 38
       ActionMailer::Base.perform_deliveries = true
39 39
       ActionMailer::Base.deliveries = []
@@ -42,6 +42,19 @@ def setup
42 42
       @expected.set_content_type "text", "plain", { "charset" => charset }
43 43
       @expected.mime_version = '1.0'
44 44
     end
  45
+    alias_method :setup, :setup_with_mailer
  46
+
  47
+    def self.method_added(method)
  48
+      if method.to_s == 'setup'
  49
+        unless method_defined?(:setup_without_mailer)
  50
+          alias_method :setup_without_mailer, :setup
  51
+          define_method(:setup) do
  52
+            setup_with_mailer
  53
+            setup_without_mailer
  54
+          end
  55
+        end
  56
+      end
  57
+    end
45 58
 
46 59
     private
47 60
       def charset
18  actionmailer/test/test_helper_test.rb
@@ -115,3 +115,21 @@ def test_assert_no_emails_failure
115 115
     assert_match /0 .* but 1/, error.message
116 116
   end
117 117
 end
  118
+
  119
+class AnotherTestHelperMailerTest < ActionMailer::TestCase
  120
+
  121
+  tests TestHelperMailer
  122
+
  123
+  def setup
  124
+    # Should not override ActionMailer setup methods
  125
+    @test_var = "a value"
  126
+  end
  127
+
  128
+  def test_should_still_setup_mailer
  129
+    assert @expected.is_a?(TMail::Mail)
  130
+  end
  131
+  
  132
+  def test_should_run_overridden_setup_method
  133
+    assert @test_var
  134
+  end
  135
+end

0 notes on commit 6a6367d

Please sign in to comment.
Something went wrong with that request. Please try again.