I spent some time trying to figure out why I was receiving:
GetProj4StringSPI: Cannot find SRID (4326) in spatial_ref_sysFrom my tests. Of course
SELECT * FROM spatial_ref_sysreturned 0 rows. What did I miss? I know I did a:
CREATE EXTENSION postgis;on both my development and test databases. Oh that's right, DatabaseCleaner.strategy = :truncation! I realized this after I went through the trouble of writing a migration to insert all of the data. To properly use DatabaseCleaner with PostGIS installed in a PostgreSQL database you'll want to:
DatabaseCleaner.strategy = :truncation, {:except => %w[spatial_ref_sys]}If you're wondering about the proper syntax for an IF NOT EXISTS in PostgreSQL, it looks like:
# ./db/migrations/TIMESTAMP_insert_some_rows.rb class InsertRowsIntoSpatialRefSys < ActiveRecord::Migration def up execute <<-SPATIAL_UP DO LANGUAGE plpgsql $$ BEGIN IF NOT EXISTS (SELECT * FROM spatial_ref_sys) THEN ⋮ ANALYZE spatial_ref_sys; END IF; END$$; SPATIAL_UP end def down execute <<-SPATIAL_DOWN DELETE FROM spatial_ref_sys SPATIAL_DOWN end end
I'm not 100% positive but I think the above syntax is only valid on a PostgreSQL 9.1 or later installation; I believe that in order to use plpgsql outside of a function or sproc 9.1+ is required.