require 'rails/generators/test_unit/scaffold/scaffold_generator' require 'generators/goma/helpers/helpers' module TestUnit module Generators module Goma class ScaffoldGenerator < ::TestUnit::Generators::ScaffoldGenerator include ::Goma::Generators::Helpers source_root File.expand_path('../templates', __FILE__) class_option :controller_type, required: true class_option :resource_name def create_test_files template "#{options[:controller_type]}_functional_test.rb", File.join("test/controllers", controller_class_path, "#{controller_file_name}_controller_test.rb") end def inject_controller_test_helpers path = File.expand_path('test/test_helper.rb', destination_root) File.open path do |f| unless f.read =~ /class\s+ActionController::TestCase/ append_to_file path do <<-RUBY.strip_heredoc class ActionController::TestCase end RUBY end end end inject_into_class('test/test_helper.rb', 'ActionController::TestCase', " include Goma::ControllerTestHelpers\n") end end end end end