Module: ActiveRecordPostgis::TestHelper
- Defined in:
- lib/activerecord-postgis/test_helper.rb
Instance Method Summary collapse
- #cartesian_factory(srid: 0) ⇒ Object
-
#create_spatial_table(table_name, connection = ActiveRecord::Base.connection) ⇒ Object
Create a test table with spatial columns.
-
#drop_spatial_table(table_name, connection = ActiveRecord::Base.connection) ⇒ Object
Clean up spatial tables after tests.
-
#factory(srid: 4326, geographic: false) ⇒ Object
Additional convenience methods for PostGIS testing.
- #geographic_factory(srid: 4326) ⇒ Object
- #reset_spatial_store ⇒ Object
- #spatial_factory_store ⇒ Object
Methods included from ActiveRecord::ConnectionAdapters::PostGIS::TestHelpers
#assert_contains, #assert_disjoint, #assert_geometry_type, #assert_has_m, #assert_has_z, #assert_intersects, #assert_spatial_column, #assert_spatial_equal, #assert_srid, #assert_within, #assert_within_distance, #create_point, #create_test_linestring, #create_test_polygon
Instance Method Details
#cartesian_factory(srid: 0) ⇒ Object
22 23 24 |
# File 'lib/activerecord-postgis/test_helper.rb', line 22 def cartesian_factory(srid: 0) RGeo::Cartesian.preferred_factory(srid: srid) end |
#create_spatial_table(table_name, connection = ActiveRecord::Base.connection) ⇒ Object
Create a test table with spatial columns
36 37 38 39 40 41 42 43 44 |
# File 'lib/activerecord-postgis/test_helper.rb', line 36 def create_spatial_table(table_name, connection = ActiveRecord::Base.connection) connection.create_table table_name, force: true do |t| t.st_point :coordinates, srid: 4326 t.st_point :location, srid: 4326, geographic: true t.st_polygon :boundary, srid: 4326 t.st_line_string :path, srid: 4326 t. end end |
#drop_spatial_table(table_name, connection = ActiveRecord::Base.connection) ⇒ Object
Clean up spatial tables after tests
47 48 49 |
# File 'lib/activerecord-postgis/test_helper.rb', line 47 def drop_spatial_table(table_name, connection = ActiveRecord::Base.connection) connection.drop_table table_name if connection.table_exists?(table_name) end |
#factory(srid: 4326, geographic: false) ⇒ Object
Additional convenience methods for PostGIS testing
10 11 12 13 14 15 16 |
# File 'lib/activerecord-postgis/test_helper.rb', line 10 def factory(srid: 4326, geographic: false) if geographic RGeo::Geographic.spherical_factory(srid: srid) else RGeo::Cartesian.preferred_factory(srid: srid) end end |
#geographic_factory(srid: 4326) ⇒ Object
18 19 20 |
# File 'lib/activerecord-postgis/test_helper.rb', line 18 def geographic_factory(srid: 4326) RGeo::Geographic.spherical_factory(srid: srid) end |
#reset_spatial_store ⇒ Object
30 31 32 33 |
# File 'lib/activerecord-postgis/test_helper.rb', line 30 def reset_spatial_store spatial_factory_store.clear spatial_factory_store.default = nil end |
#spatial_factory_store ⇒ Object
26 27 28 |
# File 'lib/activerecord-postgis/test_helper.rb', line 26 def spatial_factory_store RGeo::ActiveRecord::SpatialFactoryStore.instance end |