diff options
author | José Valim <jose.valim@gmail.com> | 2011-10-09 02:15:19 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-10-09 02:15:19 -0700 |
commit | 501e5b0d7ff995070e66d4322ed03bd882639258 (patch) | |
tree | 10341d3a391c1fe62808b34dd7cf49323428bd8f | |
parent | bedd6dcd432f55460624455b5026d1d52c1967d4 (diff) | |
parent | 8df7fe3f630e13da1585c151f6f2f986ea7dcdfd (diff) | |
download | rails-501e5b0d7ff995070e66d4322ed03bd882639258.tar.gz rails-501e5b0d7ff995070e66d4322ed03bd882639258.tar.bz2 rails-501e5b0d7ff995070e66d4322ed03bd882639258.zip |
Merge pull request #3196 from avakhov/patch-am-av-tests-2
Improve tests method for ActionView::TestCase and ActionMailer::TestCase
-rw-r--r-- | actionmailer/lib/action_mailer/test_case.rb | 9 | ||||
-rw-r--r-- | actionmailer/test/test_test.rb | 28 | ||||
-rw-r--r-- | actionpack/lib/action_view/test_case.rb | 7 | ||||
-rw-r--r-- | actionpack/test/template/test_test.rb | 16 |
4 files changed, 58 insertions, 2 deletions
diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb index 63e18147f6..c4de029694 100644 --- a/actionmailer/lib/action_mailer/test_case.rb +++ b/actionmailer/lib/action_mailer/test_case.rb @@ -17,7 +17,14 @@ module ActionMailer module ClassMethods def tests(mailer) - self._mailer_class = mailer + case mailer + when String, Symbol + self._mailer_class = mailer.to_s.camelize.constantize + when Module + self._mailer_class = mailer + else + raise NonInferrableMailerError.new(mailer) + end end def mailer_class diff --git a/actionmailer/test/test_test.rb b/actionmailer/test/test_test.rb new file mode 100644 index 0000000000..86fd37bea6 --- /dev/null +++ b/actionmailer/test/test_test.rb @@ -0,0 +1,28 @@ +require 'abstract_unit' + +class TestTestMailer < ActionMailer::Base +end + +class CrazyNameMailerTest < ActionMailer::TestCase + tests TestTestMailer + + def test_set_mailer_class_manual + assert_equal TestTestMailer, self.class.mailer_class + end +end + +class CrazySymbolNameMailerTest < 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 < ActionMailer::TestCase + tests 'test_test_mailer' + + def test_set_mailer_class_manual_using_string + assert_equal TestTestMailer, self.class.mailer_class + end +end diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 1db079d0e3..9ebe498192 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -50,7 +50,12 @@ module ActionView module ClassMethods def tests(helper_class) - self.helper_class = helper_class + case helper_class + when String, Symbol + self.helper_class = "#{helper_class.to_s.underscore}_helper".camelize.safe_constantize + when Module + self.helper_class = helper_class + end end def determine_default_helper_class(name) diff --git a/actionpack/test/template/test_test.rb b/actionpack/test/template/test_test.rb index bf789cd8b7..adcbf1447f 100644 --- a/actionpack/test/template/test_test.rb +++ b/actionpack/test/template/test_test.rb @@ -62,3 +62,19 @@ class CrazyHelperTest < ActionView::TestCase assert_equal PeopleHelper, self.class.helper_class end end + +class CrazySymbolHelperTest < ActionView::TestCase + tests :people + + def test_set_helper_class_using_symbol + assert_equal PeopleHelper, self.class.helper_class + end +end + +class CrazyStringHelperTest < ActionView::TestCase + tests 'people' + + def test_set_helper_class_using_string + assert_equal PeopleHelper, self.class.helper_class + end +end |