Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add mailer lookup similar to controller lookup

Allow mailer spec tests to be nested just like controller spec tests.
Add test coverage for nested spec tests.
  • Loading branch information...
commit 701800c9d4493f0e1a298627151229c748421603 1 parent fe51221
@blowmage authored
View
9 lib/minitest/rails/action_mailer.rb
@@ -9,10 +9,17 @@ class TestCase < MiniTest::Rails::ActiveSupport::TestCase
register_spec_type(self) do |desc|
desc < ::ActionMailer::Base if desc.is_a?(Class)
end
-
register_spec_type(/Mailer( ?Test)?\z/i, self)
include ::ActionMailer::TestCase::Behavior
+
+ def self.determine_default_mailer(name)
+ mailer = determine_constant_from_test_name(name) do |constant|
+ Class === constant && constant < ::ActionMailer::Base
+ end
+ raise ::ActionMailer::NonInferrableMailerError.new(name) if mailer.nil?
+ mailer
+ end
end
end
end
View
111 test/rails/action_mailer/test_mailers.rb
@@ -0,0 +1,111 @@
+require "minitest/autorun"
+require "rails"
+
+require "action_mailer"
+require "minitest/rails/action_mailer"
+
+class TestTestMailer < ActionMailer::Base; end
+
+class CrazyNameMailerTest < MiniTest::Rails::ActionMailer::TestCase
+ tests TestTestMailer
+
+ def test_set_mailer_class_manual
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+class CrazySymbolNameMailerTest < MiniTest::Rails::ActionMailer::TestCase
+ tests :test_test_mailer
+
+ def test_set_mailer_class_manual_using_symbol
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+class CrazyStringNameMailerTest < MiniTest::Rails::ActionMailer::TestCase
+ tests 'test_test_mailer'
+
+ def test_set_mailer_class_manual_using_string
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+describe TestTestMailer do
+ it "gets the mailer from the test name" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+describe TestTestMailer, :action do
+ it "gets the mailer from the test name" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+describe TestTestMailer do
+ describe "nested" do
+ it "gets the mailer from the test name" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+ end
+end
+
+describe TestTestMailer, :action do
+ describe "nested" do
+ it "gets the mailer from the test name" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+ end
+end
+
+describe "TestTestMailer" do
+ it "gets the mailer from the test name" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+describe "TestTestMailerTest" do
+ it "gets the mailer from the test name" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+describe "AnotherCrazySymbolNameMailerTest" do
+ tests :test_test_mailer
+
+ it "gets the mailer after setting it with a symbol" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+describe "AnotherCrazyStringNameMailerTest" do
+ tests 'test_test_mailer'
+
+ it "gets the mailer after setting it with a string" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+describe "Another Crazy Name Mailer Test" do
+ tests TestTestMailer
+
+ it "gets the mailer after setting it manually" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+describe "Another Crazy Symbol Name Mailer Test" do
+ tests :test_test_mailer
+
+ it "gets the mailer after setting it with a symbol" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+describe "Another Crazy String Name Mailer Test" do
+ tests 'test_test_mailer'
+
+ it "gets the mailer after setting it with a string" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
View
0  test/rails/test_action_mailer_spec_type.rb → test/rails/action_mailer/test_spec_type.rb
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.