diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/generators/erb/mailer/mailer_generator.rb | 4 | ||||
-rw-r--r-- | railties/test/generators/mailer_generator_test.rb | 48 |
2 files changed, 52 insertions, 0 deletions
diff --git a/railties/lib/generators/erb/mailer/mailer_generator.rb b/railties/lib/generators/erb/mailer/mailer_generator.rb index 9b615d6608..286e6ae70a 100644 --- a/railties/lib/generators/erb/mailer/mailer_generator.rb +++ b/railties/lib/generators/erb/mailer/mailer_generator.rb @@ -3,6 +3,10 @@ module Erb class MailerGenerator < Base argument :actions, :type => :array, :default => [] + def create_view_folder + empty_directory File.join("app", "views", file_path) + end + def create_view_files actions.each do |action| @action, @path = action, File.join(file_path, action) diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb new file mode 100644 index 0000000000..2574ed43bd --- /dev/null +++ b/railties/test/generators/mailer_generator_test.rb @@ -0,0 +1,48 @@ +require 'abstract_unit' +require 'generators/generators_test_helper' +require 'generators/erb/mailer/mailer_generator' +require 'generators/rails/mailer/mailer_generator' +require 'generators/test_unit/mailer/mailer_generator' + +class MailerGeneratorTest < GeneratorsTestCase + + def test_mailer_skeleton_is_created + run_generator + assert_file "app/models/notifier.rb" + end + + def test_check_class_collision + content = capture(:stderr){ run_generator ["object"] } + assert_match /The name 'Object' is either already used in your application or reserved/, content + end + + def test_invokes_default_test_framework + run_generator + assert_file "test/unit/notifier_test.rb" + assert_file "test/fixtures/notifier/foo" + assert_file "test/fixtures/notifier/bar" + end + + def test_invokes_default_template_engine + run_generator + assert_file "app/views/notifier/foo.erb" + assert_file "app/views/notifier/bar.erb" + end + + def test_invokes_default_template_engine_even_with_no_action + run_generator ["notifier"] + assert_file "app/views/notifier" + end + + def test_logs_if_the_template_engine_cannot_be_found + content = run_generator ["notifier", "foo", "bar", "--template-engine=unknown"] + assert_match /Could not find and invoke 'unknown:generators:mailer'/, content + end + + protected + + def run_generator(args=["notifier", "foo", "bar"]) + silence(:stdout) { Rails::Generators::MailerGenerator.start args, :root => destination_root } + end + +end |