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.24.2 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.24.1 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.24.0 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.23.3 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.23.2 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.23.1.pre.beta6 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.23.1.pre.beta5 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.23.1.pre.beta4 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.23.1.pre.beta3 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.23.1.pre.beta2 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.23.1.pre.beta1 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.23.0 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.22.5 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.22.4 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.22.3 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.22.2 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.22.1 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.22 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.20.1 spec/generators/active_record_generator_spec.rb
deimos-ruby-1.20.0 spec/generators/active_record_generator_spec.rb