Sha256: 0bccac1caac4ebf47fbb7aefc31358b4ab41046e4dc0fe8cfc4e0e0cd322c4a1

Contents?: true

Size: 921 Bytes

Versions: 2

Compression:

Stored size: 921 Bytes

Contents

require 'generators/rspec'

module Rspec
  module Generators
    # @private
    class ModelGenerator < Base
      argument :attributes,
               :type => :array,
               :default => [],
               :banner => "field:type field:type"
      class_option :fixture, :type => :boolean

      def create_model_spec
        template_file = File.join(
          'spec/models',
          class_path,
          "#{file_name}_spec.rb"
        )
        template 'model_spec.rb', template_file
      end

      hook_for :fixture_replacement

      def create_fixture_file
        return unless missing_fixture_replacement?

        template 'fixtures.yml', File.join('spec/fixtures', class_path, "#{(pluralize_table_names? ? plural_file_name : file_name)}.yml")
      end

    private

      def missing_fixture_replacement?
        options[:fixture] && options[:fixture_replacement].nil?
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspec-rails-4.0.0.beta3 lib/generators/rspec/model/model_generator.rb
rspec-rails-4.0.0.beta2 lib/generators/rspec/model/model_generator.rb