Sha256: a5c2906f37c87accc38c34a5b632de2a23d6c7f141a1fc32ea2c501e46b458a9

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

RSpec.describe ActiveRecord::SchemaDumper, :unit do
  let(:connection) { ActiveRecord::Base.connection }
  let(:stream)     { StringIO.new }

  subject do
    options = {
      table_name_prefix: ActiveRecord::Base.table_name_prefix,
      table_name_suffix: ActiveRecord::Base.table_name_suffix
    }

    described_class.send(:new, connection, options)
  end

  describe '#enums' do
    let(:result) do
      subject.enums(stream)
      stream.rewind
      stream.read
    end

    context 'when the database has enums' do
      before do
        expect(connection).to receive(:enums).and_return(color: %w[red green blue], size: %w[small medium large])
      end

      it 'generates matching `create_enum` statements' do
        expect(result).to include('create_enum :color, ["red", "green", "blue"]')
        expect(result).to include('create_enum :size, ["small", "medium", "large"]')
      end
    end

    context 'when the database has no enums' do
      before do
        expect(connection).to receive(:enums).and_return({})
      end

      it 'generates nothing' do
        expect(result).to be_empty
      end
    end
  end

  describe '#tables' do
    it 'invokes #enums' do
      expect(subject).to receive(:enums).with(stream).once
      subject.tables(stream)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
enum_kit-0.3.1 spec/active_record/schema_dumper_spec.rb
enum_kit-0.3.0 spec/active_record/schema_dumper_spec.rb
enum_kit-0.2.3 spec/active_record/schema_dumper_spec.rb
enum_kit-0.2.2 spec/active_record/schema_dumper_spec.rb
enum_kit-0.2.1 spec/active_record/schema_dumper_spec.rb