Sha256: 3487490c1505afe18360bdc5b8929c4865be63af3163c4a0f5801c9bced49fb8

Contents?: true

Size: 1.82 KB

Versions: 2

Compression:

Stored size: 1.82 KB

Contents

class MigratedGeometryModel < ActiveRecord::Base
end

shared_examples_for 'spatially enabled migrations' do
  let(:establish){ mysql_connection }

  let(:connection) do
    establish
    ActiveRecord::Base.connection
  end

  context "creating tables" do
    after :each do
      connection.drop_table "migrated_geometry_models"
    end

    SpatialAdapter.geometry_data_types.keys.each do |type|
      it "should create #{type.to_s} columns" do
        ActiveRecord::Schema.define do
          create_table :migrated_geometry_models, :force => true do |t|
            t.integer :extra
            t.send(type, :geom)
          end
        end

        geom_column = connection \
          .columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
        geom_column.should be_a(SpatialAdapter::SpatialColumn)
        geom_column.geometry_type.should == type
        geom_column.type.should == :string
      end
    end
  end

  context "adding columns" do
    before :each do
      ActiveRecord::Schema.define do
        create_table :migrated_geometry_models, :force => true do |t|
          t.integer :extra
        end
      end
    end

    after :each do
      connection.drop_table "migrated_geometry_models"
    end

    SpatialAdapter.geometry_data_types.keys.each do |type|
      it "should add #{type.to_s} columns" do
        ActiveRecord::Schema.define do
          add_column :migrated_geometry_models, :geom, type
        end

        geom_column = connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
        geom_column.should be_a(SpatialAdapter::SpatialColumn)
        geom_column.geometry_type.should == type
        geom_column.type.should == :string
        geom_column.with_z.should == false
        geom_column.with_m.should == false
        geom_column.srid.should == -1
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spatial_adapter-1.3.1 spec/shared/mysql_migration_spec.rb
spatial_adapter-1.3.0 spec/shared/mysql_migration_spec.rb