<commit_before>require 'generators/generators_test_helper'
require 'rails/generators/rails/controller/controller_generator'
require 'rails/generators/rails/model/model_generator'
require 'rails/generators/mailer/mailer_generator'
require 'rails/generators/rails/scaffold/scaffold_generator'

class NamespacedGeneratorTestCase < Rails::Generators::TestCase
  include GeneratorsTestHelper

  def setup
    super
    Rails::Generators.namespace = TestApp
  end
end

class NamespacedControllerGeneratorTest < NamespacedGeneratorTestCase
  arguments %w(Account foo bar)
  tests Rails::Generators::ControllerGenerator

  setup :copy_routes

  def test_namespaced_controller_skeleton_is_created
    run_generator
    assert_file "app/controllers/test_app/account_controller.rb",
                /require_dependency "test_app\/application_controller"/,
                /module TestApp/,
                /  class AccountController < ApplicationController/

    assert_file "test/controllers/test_app/account_controller_test.rb",
                /module TestApp/,
                /  class AccountControllerTest/
  end

  def test_skipping_namespace
    run_generator ["Account", "--skip-namespace"]
    assert_file "app/controllers/account_controller.rb", /class AccountController < ApplicationController/
    assert_file "app/helpers/account_helper.rb", /module AccountHelper/
  end

  def test_namespaced_controller_with_additional_namespace
    run_generator ["admin/account"]
    assert_file "app/controllers/test_app/admin/account_controller.rb", /module TestApp/, /  class Admin::AccountController < ApplicationController/ do |contents|
      assert_match %r(require_dependency "test_app/application_controller"), contents
    end
  end

  def test_helpr_is_also_namespaced
    run_generator
    assert_file "app/helpers/test_app/account_helper.rb", /module TestApp/, /  module AccountHelper/<commit_msg>Fix typo in generators test helpr -> helper [ci skip]<commit_after>require 'generators/generators_test_helper'
require 'rails/generators/rails/controller/controller_generator'
require 'rails/generators/rails/model/model_generator'
require 'rails/generators/mailer/mailer_generator'
require 'rails/generators/rails/scaffold/scaffold_generator'

class NamespacedGeneratorTestCase < Rails::Generators::TestCase
  include GeneratorsTestHelper

  def setup
    super
    Rails::Generators.namespace = TestApp
  end
end

class NamespacedControllerGeneratorTest < NamespacedGeneratorTestCase
  arguments %w(Account foo bar)
  tests Rails::Generators::ControllerGenerator

  setup :copy_routes

  def test_namespaced_controller_skeleton_is_created
    run_generator
    assert_file "app/controllers/test_app/account_controller.rb",
                /require_dependency "test_app\/application_controller"/,
                /module TestApp/,
                /  class AccountController < ApplicationController/

    assert_file "test/controllers/test_app/account_controller_test.rb",
                /module TestApp/,
                /  class AccountControllerTest/
  end

  def test_skipping_namespace
    run_generator ["Account", "--skip-namespace"]
    assert_file "app/controllers/account_controller.rb", /class AccountController < ApplicationController/
    assert_file "app/helpers/account_helper.rb", /module AccountHelper/
  end

  def test_namespaced_controller_with_additional_namespace
    run_generator ["admin/account"]
    assert_file "app/controllers/test_app/admin/account_controller.rb", /module TestApp/, /  class Admin::AccountController < ApplicationController/ do |contents|
      assert_match %r(require_dependency "test_app/application_controller"), contents
    end
  end

  def test_helper_is_also_namespaced
    run_generator
    assert_file "app/helpers/test_app/account_helper.rb", /module TestApp/, /  module AccountHelper/
{'fraction_non_alphanumeric': 0.07810466024472794, 'fraction_numerical': 0.0, 'mean_word_length': 4.40365682137834, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 4, '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': '3310679', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1031, 'n_words': 197}