Running Unit Tests With SphinxSE

Several of my unit tests run queries against SphinxSE. Since Rails
creates the test DB by dumping the dev DB schema, my SphinxSE queries
aren’t run against the test DB.

There seems to be no way to hook into the test:clone_structure task,
so I thought that I’ll just have the appropriate unit tests include

module SphinxTest
@@index = ‘ct_test_index’
mattr_accessor :index, :host, :port

self << class
def included(klass)
alter_test_table unless

#MySQL specific
def alter_test_table
  return unless ActiveRecord::Base.connection.table_exists?


  create = ActiveRecord::Base.connection.select_value "show create

table #{Query::TABLE_SPHINX}"
if @@index && md = create.match %r|sphinx://([-.\w]+):(\d+)?/[-
host = @@host || md[0]
port = @@port || md[1]

    alter = %|alter table #{Query::TABLE_SPHINX}

ActiveRecord::Base.connection.execute alter

does anyone know of way to do this from outside my unit tests?

On a side note, assuming portability was an issue, there seems to be
know way to get the TableDefinition from the connection. Is this
really the case?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs