aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
blob: 8939813304294b962ce99dc297328e29fb2ffc36 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'rails/generators/test_unit'
require 'rails/generators/resource_helpers'

module TestUnit # :nodoc:
  module Generators # :nodoc:
    class ScaffoldGenerator < Base # :nodoc:
      include Rails::Generators::ResourceHelpers

      check_class_collision suffix: "ControllerTest"

      argument :attributes, type: :array, default: [], banner: "field:type field:type"

      def create_test_files
        template "functional_test.rb",
                 File.join("test/controllers", controller_class_path, "#{controller_file_name}_controller_test.rb")
      end

      private

        def attributes_hash
          return if attributes.empty?

          attributes.map do |a|
            name = a.name
            name = "#{name}_id" if a.reference?
            "#{name}: @#{singular_table_name}.#{name}"
          end.sort.join(', ')
        end
    end
  end
end