aboutsummaryrefslogblamecommitdiffstats
path: root/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
blob: e9de51ba72132b6c3730a08583d495d14833cd12 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                                    
                                           



                                  
                                                
 

                                                       

                                                                                               
                           
                                      
                                                                                                                   
         


             




                                                
                                                      





                                         


       
require 'rails/generators/test_unit'
require 'rails/generators/resource_helpers'

module TestUnit
  module Generators
    class ScaffoldGenerator < Base
      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 accessible_attributes.empty?

          accessible_attributes.map do |a|
            name = a.name
            "#{name}: @#{singular_table_name}.#{name}"
          end.sort.join(', ')
        end

        def accessible_attributes
          attributes.reject(&:reference?)
        end
    end
  end
end