Sha256: 6f23c122212ba31b8a602ec5dc49ad39762d3a6162001741da0592a25d4b29ce

Contents?: true

Size: 1.6 KB

Versions: 12

Compression:

Stored size: 1.6 KB

Contents

require 'active_record'
require 'active_record/connection_adapters/mysql2_adapter'
require 'active_record/connection_adapters/postgresql_adapter'
require 'yaml'

class SphinxHelper
  attr_accessor :host, :username, :password, :socket
  attr_reader   :path

  def initialize
    @host     = 'localhost'
    @username = 'root'
    @password = ''

    if File.exist?('spec/fixtures/database.yml')
      config    = YAML.load(File.open('spec/fixtures/database.yml'))
      @host     = config['host']
      @username = config['username']
      @password = config['password']
      @socket   = config['socket']
      @sslca    = config['sslca']
      @sslcert  = config['sslcert']
      @sslkey   = config['sslkey']
    end

    @path = File.expand_path(File.dirname(__FILE__))
  end

  def setup_mysql
    ActiveRecord::Base.establish_connection(
      :adapter  => mysql_adapter,
      :database => 'thinking_sphinx',
      :username => @username,
      :password => @password,
      :host     => @host,
      :socket   => @socket,
      :sslca    => @sslca,
      :sslcert  => @sslcert,
      :sslkey   => @sslkey
    )
    ActiveRecord::Base.logger = Logger.new(File.open('tmp/activerecord.log', 'a'))

    structure = File.open('spec/fixtures/structure.sql') { |f| f.read.chomp }
    structure.split(';').each { |table|
      ActiveRecord::Base.connection.execute table
    }

    File.open('spec/fixtures/data.sql') { |f|
      while line = f.gets
        ActiveRecord::Base.connection.execute line unless line.blank?
      end
    }
  end

  private

  def mysql_adapter
    defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql2'
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
friendlyfashion-thinking-sphinx-2.0.14.4 spec/sphinx_helper.rb
friendlyfashion-thinking-sphinx-2.0.14.3 spec/sphinx_helper.rb
thinking-sphinx-2.1.0 spec/sphinx_helper.rb
friendlyfashion-thinking-sphinx-2.0.14.2 spec/sphinx_helper.rb
friendlyfashion-thinking-sphinx-2.0.14.1 spec/sphinx_helper.rb
thinking-sphinx-2.0.14 spec/sphinx_helper.rb
friendlyfashion-thinking-sphinx-2.0.13.3 spec/sphinx_helper.rb
friendlyfashion-thinking-sphinx-2.0.13.2 spec/sphinx_helper.rb
friendlyfashion-thinking-sphinx-2.0.13.1 spec/sphinx_helper.rb
friendlyfashion-thinking-sphinx-2.0.13 spec/sphinx_helper.rb
thinking-sphinx-2.0.13 spec/sphinx_helper.rb
thinking-sphinx-2.0.12 spec/sphinx_helper.rb