<commit_before>require 'generators/generators_test_helper'
require 'generators/rails/mailer/mailer_generator'

class MailerGeneratorTest < Rails::Generators::TestCase
  include GeneratorsTestHelper
  arguments %w(notifier foo bar)

  def test_mailer_skeleton_is_created
    run_generator
    assert_file "app/mailers/notifier.rb" do |mailer|
      assert_match /class Notifier < ActionMailer::Base/, mailer
      assert_match /default :from => "<EMAIL>"/, mailer
    end
  end

  def test_mailer_with_i18n_helper
    run_generator
    assert_file "app/mailers/notifier.rb" do |mailer|
      assert_match /en\.actionmailer\.notifier\.foo\.subject/, mailer
      assert_match /en\.actionmailer\.notifier\.bar\.subject/, mailer
    end
  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/functional/notifier_test.rb", /class NotifierTest < ActionMailer::TestCase/
    assert_file "test/fixtures/notifier/foo", /app\/views\/notifier\/foo$/
    assert_file "test/fixtures/notifier/bar", /app\/views\/notifier\/bar$/
  end

  def test_invokes_default_template_engine
    run_generator
    assert_file "app/views/notifier/foo.text.erb" do |view|
      assert_match /app\/views\/notifier\/foo$/, view
      assert_match /<%= @greeting %>/, view
    end

    assert_file "app/views/notifier/bar.text.erb" do |view|
      assert_match /app\/views\/notifier\/bar$/, view
      assert_match /<%= @greeting %>/, view
    end
  end

  def test_invokes_default_template_engine_even_with_no_action<commit_msg>Also revert mailer generator test changes in 8b50f89<commit_after>require 'generators/generators_test_helper'
require 'generators/rails/mailer/mailer_generator'

class MailerGeneratorTest < Rails::Generators::TestCase
  include GeneratorsTestHelper
  arguments %w(notifier foo bar)

  def test_mailer_skeleton_is_created
    run_generator
    assert_file "app/mailers/notifier.rb" do |mailer|
      assert_match /class Notifier < ActionMailer::Base/, mailer
      assert_match /default :from => "<EMAIL>"/, mailer
    end
  end

  def test_mailer_with_i18n_helper
    run_generator
    assert_file "app/mailers/notifier.rb" do |mailer|
      assert_match /en\.actionmailer\.notifier\.foo\.subject/, mailer
      assert_match /en\.actionmailer\.notifier\.bar\.subject/, mailer
    end
  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/functional/notifier_test.rb", /class NotifierTest < ActionMailer::TestCase/
    assert_file "test/fixtures/notifier/foo", /app\/views\/notifier\/foo$/
    assert_file "test/fixtures/notifier/bar", /app\/views\/notifier\/bar$/
  end

  def test_invokes_default_template_engine
    run_generator
    assert_file "app/views/notifier/foo.text.erb" do |view|
      assert_match %r(app/views/notifier/foo\.text\.erb), view
      assert_match /<%= @greeting %>/, view
    end

    assert_file "app/views/notifier/bar.text.erb" do |view|
      assert_match %r(app/views/notifier/bar\.text\.erb), view
      assert_match /<%= @greeting %>/, view
    end
  end

  def test_invokes_default_template_engine_even_with_no_action
{'fraction_non_alphanumeric': 0.10463463178845607, 'fraction_numerical': 0.0025589991470002845, 'mean_word_length': 3.8060109289617485, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '523140', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1126, 'n_words': 228}