Sha256: fc6ed926e26384226ce917cd0fb6c4b049643c5f0f3482b59fc3a3ee60ae9c6c

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

require 'seasyar'


class Dummy 
  include Seasyar
  
  def initialize id, static
    @id = id
    @static = static
  end

  INDEX_NAME = "test_index_name" 

  def save
    index INDEX_NAME, :static
  end
  
  def save_with_block
    index( INDEX_NAME, :static ) {|unused| 666}
  end
  
  def removal
    unindex INDEX_NAME
  end
  
  def id
    @id
  end
  
  def static 
    @static
  end
end

describe Seasyar do
  before :all do
    ActiveRecord::Base.configurations = YAML::load(IO.read('db/config.yml'))
    ActiveRecord::Base.establish_connection('development')
    
    Seasy.configure do |config|
      config.storage = Seasyar::ActiveRecordStorage
    end
  end

  before :each do
    Seasyar::SeasyData.all.each { |data| data.delete }
  end
  
  it "should save to index" do
    d = Dummy.new 42, 'static'
    d.save
    Seasyar.search( Dummy::INDEX_NAME, 'static' ).should == {42.to_s => 1}
  end
  
  it "should save source" do
    d = Dummy.new 144, 'diff'
    d.save_with_block
    Seasyar.search( Dummy::INDEX_NAME, 'diff' ).should == {666.to_s => 1}
    
    d.save # the 666 entry should be removed and 42 be there instead
    Seasyar.search( Dummy::INDEX_NAME, 'diff' ).should == {144.to_s => 1}
  end
  
  it "should remove from index" do
    d = Dummy.new 43, 'static'
    d.save
    d.removal
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
seasyar-0.0.11 spec/seasyar_spec.rb
seasyar-0.0.10 spec/seasyar_spec.rb
seasyar-0.0.9 spec/seasyar_spec.rb
seasyar-0.0.8 spec/seasyar_spec.rb