Sha256: d196b8ad212e2618d9016e5abe62dd196c54600a44d0c04ad19432799bda3be7

Contents?: true

Size: 1.59 KB

Versions: 4

Compression:

Stored size: 1.59 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe "Spatially-enabled Schema Dumps" do
  before :all do
    mysql_connection
    @connection = ActiveRecord::Base.connection

    # Create a new table
    ActiveRecord::Schema.define do
      create_table :migrated_geometry_models, :options=> "ENGINE=MyISAM", :force => true do |t|
        t.integer :extra
        t.point   :geom, :null => false
      end
      add_index :migrated_geometry_models, :geom, :spatial => true, :name => 'test_spatial_index'
    end

    File.open('schema.rb', "w") do |file|
      ActiveRecord::SchemaDumper.dump(@connection, file)
    end
    
    # Drop the original table
    @connection.drop_table "migrated_geometry_models"
    
    # Load the dumped schema
    load('schema.rb')
  end
  
  after :all do
    # delete the schema file
    File.delete('schema.rb')

    # Drop the new table
    @connection.drop_table "migrated_geometry_models"
  end
  
  it "should preserve spatial attributes of tables" do
    columns = @connection.columns("migrated_geometry_models")
    
    columns.should have(3).items
    geom_column = columns.select{|c| c.name == 'geom'}.first
    geom_column.should be_a(SpatialAdapter::SpatialColumn)
    geom_column.geometry_type.should == :point
    geom_column.type.should == :geometry
  end
  
  it "should preserve spatial indexes" do
    indexes = @connection.indexes("migrated_geometry_models")
    
    indexes.should have(1).item
    
    indexes.first.name.should == 'test_spatial_index'
    indexes.first.columns.should == ["geom"]
    indexes.first.spatial.should == true
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spatial_adapter-0.3.1 spec/mysql/schema_dumper_spec.rb
spatial_adapter-0.3.0 spec/mysql/schema_dumper_spec.rb
spatial_adapter-0.2.1 spec/mysql/schema_dumper_spec.rb
spatial_adapter-0.2.0 spec/mysql/schema_dumper_spec.rb