Sha256: c371d2f3ca23bc813956b5fa60d8ab19286af923f8845b281f09299879058a06

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))

describe 'Client' do
  before(:all) do
    @index = Algolia::Index.new("friends")
    @index.delete rescue "not fatal"
  end

  it "should add a simple object" do
    @index.add_object!({ :name => "John Doe", :email => "john@doe.org" })
    res = @index.search("john")
    res["hits"].length.should eq(1)
  end

  it "should add a set of objects" do
    @index.add_objects!([
      { :name => "Another", :email => "another1@example.org" },
      { :name => "Another", :email => "another2@example.org" }
    ])
    res = @index.search("another")
    res["hits"].length.should eq(2)
  end

  it "should throw an exception if invalid argument" do
    expect { @index.add_object!([ {:name => "test"} ]) }.to raise_error(ArgumentError)
    expect { @index.add_objects!([ [ {:name => "test"} ] ]) }.to raise_error(ArgumentError)
  end

  it "should be thread safe" do
    threads = []
    64.times do
      t = Thread.new do
        10.times do
          res = @index.search("john")
          res["hits"].length.should eq(1)
        end
      end
      threads << t
    end
    threads.each { |t| t.join }
  end

  it "should clear the index" do
    @index.clear!
    @index.search("")["hits"].length.should eq(0)
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
algoliasearch-1.1.6 spec/client_spec.rb