diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7026f0344c5..f3c7de01568 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -231,6 +231,17 @@ module Helpers end end +# Make sure extensions will work with dynamically created shards +if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' && + ActiveRecord::Base.connection.schema_search_path == 'public' + %w{pg_trgm pg_collkey}.each do |extension| + current_schema = ActiveRecord::Base.connection.select_value("SELECT nspname FROM pg_extension INNER JOIN pg_namespace ON extnamespace=pg_namespace.oid WHERE extname='#{extension}'") + if current_schema && current_schema == 'public' + ActiveRecord::Base.connection.execute("ALTER EXTENSION #{extension} SET SCHEMA pg_catalog") rescue nil + end + end +end + (CANVAS_RAILS2 ? Spec::Runner : RSpec).configure do |config| # If you're not using ActiveRecord you should remove these # lines, delete config/database.yml and disable :active_record