mailer_generator_test.rb 1.7 KB
Newer Older
J
José Valim 已提交
1 2 3 4 5 6 7 8 9 10
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
J
José Valim 已提交
11
    assert_file "app/models/notifier.rb", /class Notifier < ActionMailer::Base/
J
José Valim 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
  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
J
José Valim 已提交
28 29
    assert_file "app/views/notifier/foo.erb", /app\/views\/notifier\/foo/
    assert_file "app/views/notifier/bar.erb", /app\/views\/notifier\/bar/
J
José Valim 已提交
30 31 32 33 34 35 36 37 38 39 40 41
  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

J
José Valim 已提交
42 43 44 45 46 47
  def test_actions_are_turned_into_methods
    run_generator
    assert_file "app/models/notifier.rb", /def foo/
    assert_file "app/models/notifier.rb", /def bar/
  end

J
José Valim 已提交
48 49 50 51 52 53 54
  protected

    def run_generator(args=["notifier", "foo", "bar"])
      silence(:stdout) { Rails::Generators::MailerGenerator.start args, :root => destination_root }
    end

end