Sha256: bd80a9e499f3a91230b47204f3377f3470bd51687564cc8c1b5517b546c2c94e

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require 'seasyar'
require 'seasy'
require 'active_record'

describe Seasyar::ActiveRecordStorage do
  before :all do
    ActiveRecord::Base.configurations = YAML::load(IO.read('db/config.yml'))
    ActiveRecord::Base.establish_connection('development')
  end
  
  it "should save entries and make them searchable" do
    target = 1
    weights = Fragmentizer.new.fragmentize 'test'
    subject.save target, weights, :source => "1"
    subject.search( 'es' ).should == {"1" => 1}
  end
  
  it "should remove entries when saving new ones" do
    target = 1
    weights = Fragmentizer.new.fragmentize 'test'
    subject.save target, weights, :source => "1"
    
    weights = Fragmentizer.new.fragmentize 'different'
    subject.save target, weights, :source => "1"
    
    subject.search( 'es' ).should == {}    
  end
  
  it "should accept a source as basis for what to delete in between adding" do 
    Seasy.configure do |config|
      config.storage = Seasyar::ActiveRecordStorage
    end
    i = Seasy::Index.new 
    i.add 'ruben', 'landsnora', :source => 'veddesta'
    i.search( 'ruben' ).should == {'landsnora' => 1}
    
    i.add 'ruben', 'edsberg', :source => 'edsberg'
    i.search( 'ruben' ).should == {'landsnora' => 1, 'edsberg' => 1}
    
    i.add 'sten', 'landsnora', :source => 'veddesta'
    i.search( 'ruben' ).should == {'edsberg' => 1}
    
    i.add 'sten', 'edsberg', :source => 'edsberg'
    i.search( 'ruben' ).should == {}
  end
  
  it "should have two seperate indices" do
    Seasy.configure do |config|
      config.storage = Seasyar::ActiveRecordStorage
    end
    i1 = Seasy::Index.with_name 1
    i2 = Seasy::Index.with_name 2
    i1.add 'ruben', 'landsnora'#, :source => 'landsnora'
    i2.add 'ruben', 'edsberg'#, :source => 'edsberg'
    i1.search( 'ruben').should == {'landsnora' => 1}
    i2.search( 'ruben').should == {'edsberg' => 1}
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
seasyar-0.0.9 spec/storage_spec.rb