diff --git a/lib/active_record/connection_adapters/postgis/spatial_column.rb b/lib/active_record/connection_adapters/postgis/spatial_column.rb index 9457e390..c78cb18f 100644 --- a/lib/active_record/connection_adapters/postgis/spatial_column.rb +++ b/lib/active_record/connection_adapters/postgis/spatial_column.rb @@ -12,7 +12,9 @@ def initialize(name, default, sql_type_metadata = nil, null = true, serial: nil, generated: nil, spatial: nil, identity: nil) @sql_type_metadata = sql_type_metadata @geographic = !!(sql_type_metadata.sql_type =~ /geography\(/i) - if spatial + if sql_type_metadata.type == :enum + # noop - enum types are not spatial but their names may match against the regexes below + elsif spatial # This case comes from an entry in the geometry_columns table set_geometric_type_from_name(spatial[:type]) @srid = spatial[:srid].to_i diff --git a/test/cases/basic_test.rb b/test/cases/basic_test.rb index f8fe4bff..aee97115 100644 --- a/test/cases/basic_test.rb +++ b/test/cases/basic_test.rb @@ -210,6 +210,18 @@ def test_multi_polygon_column assert_equal wkt, rec.m_poly.to_s end + def test_spatial_column_matching_enum + SpatialModel.lease_connection.create_enum(:point_type, ["point", "line_string", "polygon"]) + SpatialModel.lease_connection.create_table(:spatial_models, force: true) do |t| + t.column "latlon", :st_point, srid: 3785 + t.column "latlon_geo", :st_point, srid: 4326, geographic: true + t.column "default_latlon", :st_point, srid: 0, default: "POINT(0.0 0.0)" + t.enum "point_type", enum_type: :point_type + end + SpatialModel.reset_column_information + point_type = SpatialModel.columns.find { |c| c.name == "point_type" } + assert_nil point_type.geometric_type + end private def create_model