Sha256: 3812b30df8cffaa51ff60e85360e806992fe1d7fe0e2499c676bcb5789e6546d

Contents?: true

Size: 1009 Bytes

Versions: 35

Compression:

Stored size: 1009 Bytes

Contents

require 'rails/generators/test_unit'

module TestUnit # :nodoc:
  module Generators # :nodoc:
    class ModelGenerator < Base # :nodoc:

      RESERVED_YAML_KEYWORDS = %w(y yes n no true false on off null)

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

      check_class_collision suffix: "Test"

      def create_test_file
        template 'unit_test.rb', File.join('test/models', class_path, "#{file_name}_test.rb")
      end

      hook_for :fixture_replacement

      def create_fixture_file
        if options[:fixture] && options[:fixture_replacement].nil?
          template 'fixtures.yml', File.join('test/fixtures', class_path, "#{fixture_file_name}.yml")
        end
      end

      private
        def yaml_key_value(key, value)
          if RESERVED_YAML_KEYWORDS.include?(key.downcase)
            "'#{key}': #{value}"
          else
            "#{key}: #{value}"
          end
        end
    end
  end
end

Version data entries

35 entries across 35 versions & 4 rubygems

Version Path
railties-5.0.7.2 lib/rails/generators/test_unit/model/model_generator.rb
railties-5.0.7.1 lib/rails/generators/test_unit/model/model_generator.rb
railties-5.0.7 lib/rails/generators/test_unit/model/model_generator.rb
railties-5.0.6 lib/rails/generators/test_unit/model/model_generator.rb
railties-5.0.6.rc1 lib/rails/generators/test_unit/model/model_generator.rb
railties-5.0.5 lib/rails/generators/test_unit/model/model_generator.rb
railties-5.0.5.rc2 lib/rails/generators/test_unit/model/model_generator.rb
railties-5.0.5.rc1 lib/rails/generators/test_unit/model/model_generator.rb
railties-5.0.4 lib/rails/generators/test_unit/model/model_generator.rb
railties-5.0.4.rc1 lib/rails/generators/test_unit/model/model_generator.rb
railties-5.0.3 lib/rails/generators/test_unit/model/model_generator.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/railties-5.0.2/lib/rails/generators/test_unit/model/model_generator.rb
railties-5.0.2 lib/rails/generators/test_unit/model/model_generator.rb
railties-5.0.2.rc1 lib/rails/generators/test_unit/model/model_generator.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/generators/test_unit/model/model_generator.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/generators/test_unit/model/model_generator.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/generators/test_unit/model/model_generator.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/generators/test_unit/model/model_generator.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/generators/test_unit/model/model_generator.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/generators/test_unit/model/model_generator.rb