Sha256: 8b3316f9dfdafc0df71e257d400603bc03a9d3fa6f8306e9509dc0dee70fdae7

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

require 'active_model'
require 'tire'
require 'active_support/core_ext'
require 'elasticsearch_autocomplete'

Tire.configure do
  #logger 'tmp/elasticsearch.log'  # Commented out logger line here so that it doesn't break specs when tmp directory doesn't exist.
  url 'http://localhost:9200'
  pretty 1
end

I18n.available_locales = [:en, :ru]

class ActiveModelBase
  include ActiveModel::AttributeMethods
  include ActiveModel::Serialization
  include ActiveModel::Serializers::JSON
  include ActiveModel::Naming

  extend ActiveModel::Callbacks
  define_model_callbacks :save, :destroy

  include ElasticsearchAutocomplete::ModelAddition

  attr_reader :attributes
  attr_accessor :id, :created_at

  def initialize(attributes = {})
    @attributes = attributes
  end

  def method_missing(id, *args, &block)
    attributes[id.to_sym] || attributes[id.to_s] || super
  end

  def persisted?
    true
  end

  def save
    run_callbacks(:save) {}
  end

  def destroy
    run_callbacks(:destroy) { @destroyed = true }
  end

  def destroyed?
    !!@destroyed
  end

  def self.setup_index
    tire.index.delete
    tire.create_elasticsearch_index
    populate
    tire.index.refresh
  end
end

class StubModelBase < ActiveModelBase

  def self.test_data
    ['Joyce Flores', 'Rebecca Nelson', 'Larson Laura', 'Laura Larson']
  end

  def self.populate
    test_data.each_with_index do |name, id|
      u = new(full_name: name)
      u.id = id
      u.save
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
elasticsearch_autocomplete-0.1.5 spec/spec_helper.rb