Sha256: d340366463778bcf2adbe899e307011c97e9fbc4ef22c0c2a1f27a4afa796d36

Contents?: true

Size: 1.33 KB

Versions: 21

Compression:

Stored size: 1.33 KB

Contents

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"

      class_option :api, type: :boolean,
                         desc: "Generates API functional tests"

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

      def create_test_files
        template_file = options.api? ? "api_functional_test.rb" : "functional_test.rb"
        template template_file,
                 File.join("test/controllers", controller_class_path, "#{controller_file_name}_controller_test.rb")
      end

      def fixture_name
        @fixture_name ||=
          if mountable_engine?
            "%s_%s" % [namespaced_path, table_name]
          else
            table_name
          end
      end

      private

        def attributes_hash
          return if attributes_names.empty?

          attributes_names.map do |name|
            if %w(password password_confirmation).include?(name) && attributes.any?(&:password_digest?)
              "#{name}: 'secret'"
            else
              "#{name}: @#{singular_table_name}.#{name}"
            end
          end.sort.join(', ')
        end
    end
  end
end

Version data entries

21 entries across 21 versions & 3 rubygems

Version Path
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
autocompl-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
abaci-0.3.0 vendor/bundle/gems/railties-5.0.0/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
railties-5.0.1 lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
railties-5.0.1.rc2 lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
railties-5.0.1.rc1 lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
railties-5.0.0.1 lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
railties-5.0.0 lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
railties-5.0.0.rc2 lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
railties-5.0.0.racecar1 lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
railties-5.0.0.rc1 lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
railties-5.0.0.beta4 lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
railties-5.0.0.beta3 lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
railties-5.0.0.beta2 lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
railties-5.0.0.beta1.1 lib/rails/generators/test_unit/scaffold/scaffold_generator.rb