Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ AR_VERSION=7.0.1 bundle exec rake test

To run a specific test, use the `POSTGIS_TEST_FILES` environment variable:

`POSTGIS_TEST_FILES=test/cases/ddl_test.rb bundle exec rake`
`POSTGIS_TEST_FILES=test/cases/ddl_test.rb bundle exec rake test:postgis`

If you are testing a feature against the ActiveRecord test suite run:

Expand Down
4 changes: 3 additions & 1 deletion lib/active_record/connection_adapters/postgis/quoting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ module Quoting
def type_cast(value)
case value
when RGeo::Feature::Instance
value.to_s
RGeo::WKRep::WKBGenerator
.new(hex_format: true, type_format: :ewkb, emit_ewkb_srid: true)
.generate(value)
else
super
end
Expand Down
9 changes: 9 additions & 0 deletions test/cases/spatial_queries_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ def test_geo_safe_where
assert_equal 1, SpatialModel.where("ST_DWITHIN(latlon_geo, ?, 500)", geographic_factory.point(-72.099, 42.099)).count
end

def test_geo_safe_where_with_srids
create_model
center = RGeo::Geos.factory(srid: 4326).point(3.833, 43.698)
polygon = RGeo::Geos.factory(srid: 4326).parse_wkt("POLYGON ((3.9 43.68, 3.8 43.62, 3.77 43.75, 3.9 43.68))")
SpatialModel.create!(polygon: polygon)
assert_equal 1, SpatialModel.where("ST_Within(?, polygon)", center).count
end

private

def create_model
Expand All @@ -130,6 +138,7 @@ def create_model
t.column "latlon_geo", :st_point, srid: 4326, geographic: true
t.column "points", :multi_point, srid: 3785
t.column "path", :line_string, srid: 3785
t.column "polygon", :st_polygon, srid: 4326
end
SpatialModel.reset_column_information
end
Expand Down
Loading