Sha256: e61ab6010e7c863a8bca68bd631f7c1ea91aeba66ebde00e828e01a5c499d000

Contents?: true

Size: 1.62 KB

Versions: 51

Compression:

Stored size: 1.62 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_optional_int
            t.string :an_enum
            t.json :an_array
            t.json :a_map
            t.json :a_record

            t.timestamps

            # TODO add indexes as necessary
          end
        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

51 entries across 51 versions & 1 rubygems

Version Path
deimos-ruby-1.19.7 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.19.6 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.19.5 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.19.4 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.19.3 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.19.2 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.19.1 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.19.1.pre.beta1 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.19.0 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.19.beta2 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.19.beta1 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.18.2 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.18.1 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.18.0 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.17.1 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.17.0 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.16.5 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.16.4 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.16.3 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.16.2 spec/generators/active_record_generator_spec.rb