@@ -122,6 +122,23 @@ def test_geo_safe_where
122122 assert_equal 1 , SpatialModel . where ( "ST_DWITHIN(latlon_geo, ?, 500)" , geographic_factory . point ( -72.099 , 42.099 ) ) . count
123123 end
124124
125+ def test_geo_query_matches_sql
126+ value = geographic_factory . point ( -72.099 , 42.099 )
127+
128+ assert_match (
129+ RGeo ::WKRep ::WKBGenerator . new ( hex_format : true , type_format : :ewkb , emit_ewkb_srid : true ) . generate ( value ) ,
130+ SpatialModel . where ( "ST_DWITHIN(latlon_geo, ?, 500)" , value ) . explain . inspect
131+ )
132+ end
133+
134+ def test_srid_aware_query
135+ center = RGeo ::Geos . factory ( srid : 4326 ) . point ( 3.808591 , 43.606092 )
136+ polygon = center . buffer ( 10_000 )
137+ model = SpatialModel . create! ( geometry : polygon )
138+
139+ assert_equal [ model ] , SpatialModel . where ( "ST_Within(?, geometry)" , center )
140+ end
141+
125142 private
126143
127144 def create_model
@@ -130,6 +147,7 @@ def create_model
130147 t . column "latlon_geo" , :st_point , srid : 4326 , geographic : true
131148 t . column "points" , :multi_point , srid : 3785
132149 t . column "path" , :line_string , srid : 3785
150+ t . column "geometry" , :geometry , srid : 4326
133151 end
134152 SpatialModel . reset_column_information
135153 end
0 commit comments