Sha256: 0898c5fea26ae71c9d095337d4a2a35761ffc47a5c41d8af168167538dc00f51

Contents?: true

Size: 1.56 KB

Versions: 19

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

require 'generators/deimos/active_record_generator'

RSpec.describe Deimos::Generators::ActiveRecordGenerator do

  after(:each) do
    FileUtils.rm_rf('db') if File.exist?('db')
    FileUtils.rm_rf('app') if File.exist?('app')
  end

  it 'should generate a migration' do
    expect(Dir['db/migrate/*.rb']).to be_empty
    expect(Dir['app/models/*.rb']).to be_empty
    described_class.start(['generated_table', 'com.my-namespace.Generated'])
    files = Dir['db/migrate/*.rb']
    expect(files.length).to eq(1)
    results = <<~MIGRATION
      class CreateGeneratedTable < ActiveRecord::Migration[6.1]
        def up
          if table_exists?(:generated_table)
            warn "generated_table already exists, exiting"
            return
          end
          create_table :generated_table do |t|
            t.string :a_string
            t.integer :a_int
            t.bigint :a_long
            t.float :a_float
            t.float :a_double
            t.string :an_enum
            t.json :an_array
            t.json :a_map
            t.json :a_record
          end
      
          # TODO add indexes as necessary
        end
      
        def down
          return unless table_exists?(:generated_table)
          drop_table :generated_table
        end
      
      end
    MIGRATION
    expect(File.read(files[0])).to eq(results)
    model = <<~MODEL
      class GeneratedTable < ApplicationRecord
        enum an_enum: {sym1: 'sym1', sym2: 'sym2'}
      end
    MODEL
    expect(File.read('app/models/generated_table.rb')).to eq(model)
  end

end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
deimos-temp-fork-0.0.7 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.11.2 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.11.1 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.11.0 spec/generators/active_record_generator_spec.rb
deimos-temp-fork-0.0.6 spec/generators/active_record_generator_spec.rb
deimos-temp-fork-0.0.5 spec/generators/active_record_generator_spec.rb
deimos-temp-fork-0.0.4 spec/generators/active_record_generator_spec.rb
deimos-temp-fork-0.0.3 spec/generators/active_record_generator_spec.rb
deimos-temp-fork-0.0.2 spec/generators/active_record_generator_spec.rb
deimos-temp-fork-0.0.1 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.10.2 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.10.1 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.10.0 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.9.2 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.9.1 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.9.0 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.8.7 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.8.6 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.8.5 spec/generators/active_record_generator_spec.rb