Sha256: 80c725cebe6cb54051444e977b22432918c1b5c88c60b61981ab29583c3f4d1e

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

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

describe 'Session' do
  context 'using singleton session' do
    before :each do
      Sunspot.reset!
      connection.should_receive(:add).twice
      connection.should_receive(:commit).twice
      connection.should_receive(:query)
    end

    it 'should open connection with defaults if nothing specified' do
      Solr::Connection.stub!(:new).with('http://localhost:8983/solr').and_return(connection)
      Sunspot.index(Post.new)
      Sunspot.index!(Post.new)
      Sunspot.commit
      Sunspot.search(Post)
    end

    it 'should open a connection with custom host' do
      Solr::Connection.stub!(:new).with('http://127.0.0.1:8981/solr').and_return(connection)
      Sunspot.config.solr.url = 'http://127.0.0.1:8981/solr'
      Sunspot.index(Post.new)
      Sunspot.index!(Post.new)
      Sunspot.commit
      Sunspot.search(Post)
    end
  end

  context 'using custom session' do
    before :each do
      connection.should_receive(:add).twice
      connection.should_receive(:commit).twice
      connection.should_receive(:query)
    end

    it 'should open a connection with custom host' do
      Solr::Connection.stub!(:new).with('http://127.0.0.1:8982/solr').and_return(connection)
      session = Sunspot::Session.new do |config|
        config.solr.url = 'http://127.0.0.1:8982/solr'
      end
      session.index(Post.new)
      session.index!(Post.new)
      session.commit
      session.search(Post)
    end
  end

  def connection
    @connection ||= mock('Connection').as_null_object
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
outoftime-sunspot-0.7.0 spec/api/session_spec.rb
outoftime-sunspot-0.7.1 spec/api/session_spec.rb