Sha256: ab25ac40002df15213ccff313aa3f6af87663bbfc434ab759ef94724cf7fb368

Contents?: true

Size: 1.54 KB

Versions: 8

Compression:

Stored size: 1.54 KB

Contents

require 'spec_helper'
require 'stringio'

describe "Schema dump" do

  context 'with enum', :postgresql => :only do
    let(:connection) { ActiveRecord::Base.connection }

    it 'should include enum' do
      begin
        connection.execute "CREATE TYPE color AS ENUM ('red', 'green', 'blue')"
        expect(dump_schema).to match(%r{create_enum "color", "red", "green", "blue"})
      ensure
        connection.execute "DROP TYPE color"
      end
    end

    it 'should list enums alphabetically' do
      begin
        connection.execute "CREATE TYPE height AS ENUM ('tall', 'medium', 'short')"
        connection.execute "CREATE TYPE color AS ENUM ('red', 'green', 'blue')"
        expect(dump_schema).to match(%r{create_enum "color", "red", "green", "blue"\s+create_enum "height", "tall", "medium", "short"}m)
      ensure
        connection.execute "DROP TYPE color"
        connection.execute "DROP TYPE height"
      end
    end


    it 'should include enum with schema' do
      begin
        connection.execute "CREATE SCHEMA cmyk; CREATE TYPE cmyk.color AS ENUM ('cyan', 'magenta', 'yellow', 'black')"
        expect(dump_schema).to match(%r{create_enum "color", "cyan", "magenta", "yellow", "black", :schema => "cmyk"})
      ensure
        connection.execute "DROP SCHEMA cmyk CASCADE"
      end
    end
  end

  protected

  def dump_schema(opts={})
    stream = StringIO.new
    ActiveRecord::SchemaDumper.ignore_tables = Array.wrap(opts[:ignore]) || []
    ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
    stream.string
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
schema_plus_enums-0.1.8 spec/schema_dumper_spec.rb
schema_plus_enums-0.1.7 spec/schema_dumper_spec.rb
schema_plus_enums-0.1.6 spec/schema_dumper_spec.rb
schema_plus_enums-0.1.5 spec/schema_dumper_spec.rb
schema_plus_enums-0.1.4 spec/schema_dumper_spec.rb
schema_plus_enums-0.1.3 spec/schema_dumper_spec.rb
schema_plus_enums-0.1.2 spec/schema_dumper_spec.rb
schema_plus_enums-0.1.1 spec/schema_dumper_spec.rb