Sha256: 7e3973e0803f1627c92df48fbbc5a78d1c13cab17a67ac81e381604a171d3bb4

Contents?: true

Size: 1.9 KB

Versions: 3

Compression:

Stored size: 1.9 KB

Contents

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
require 'supernova'
require "mysql2"
require "logger"
require "fileutils"
require "ruby-debug"
require "geokit"

if defined?(Debugger) && Debugger.respond_to?(:settings)
  Debugger.settings[:autolist] = 1
  Debugger.settings[:autoeval] = true
end

# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

RSpec.configure do |config|
  config.before(:each) do
    ActiveRecord::Base.connection.execute("TRUNCATE offers")
  end
end

ActiveRecord::Base.establish_connection(
  :adapter => "mysql2",
  :host => "localhost", 
  :database => "supernova_test", 
  :username => "root",
  :encoding => "utf8"
)

PROJECT_ROOT = Pathname.new(File.expand_path("..", File.dirname(__FILE__)))
FileUtils.mkdir_p(PROJECT_ROOT.join("db/sphinx/development"))
FileUtils.mkdir_p(PROJECT_ROOT.join("log"))
FileUtils.mkdir_p(PROJECT_ROOT.join("config"))

ThinkingSphinx::ActiveRecord::LogSubscriber.logger = Logger.new(
  open(File.expand_path("../log/active_record.log", File.dirname(__FILE__)), "a")
)

ActiveRecord::Base.send(:include, ThinkingSphinx::ActiveRecord)

ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS offers")
ActiveRecord::Base.connection.execute("CREATE TABLE offers (id SERIAL, text TEXT, user_id INTEGER, enabled BOOLEAN, popularity INTEGER, lat FLOAT, lng FLOAT)")

class Offer < ActiveRecord::Base
  include Supernova::ThinkingSphinx
  
  define_index do
    indexes text
    
    has :user_id
    has :enabled
    has :popularity, :sort => true
    
    has "RADIANS(lat)",  :as => :lat, :type => :float
    has "RADIANS(lng)", :as => :lng, :type => :float
  end
  
  named_search_scope :for_user_ids do |*ids|
    with(:user_id => ids.flatten)
  end
end

class Host
  attr_accessor :id
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
supernova-0.3.13 spec/spec_helper.rb
supernova-0.3.12 spec/spec_helper.rb
supernova-0.3.11 spec/spec_helper.rb