Sha256: 5b0cae6f33b4f10aadcd720949684f18da3d33a6e09c6440bfe3ce1f1045fb3d

Contents?: true

Size: 1.86 KB

Versions: 2

Compression:

Stored size: 1.86 KB

Contents

require 'spec_helper'

describe Sunspot::SessionProxy::MasterSlaveWithFailoverSessionProxy do
  let(:master) { Sunspot::Session.new }
  let(:slave) { Sunspot::Session.new }
  let(:proxy) { Sunspot::SessionProxy::MasterSlaveWithFailoverSessionProxy.new(master, slave) }
  
  let(:exception_handler_adapter) { Sunspot::Rails::Failover::ExceptionHandlerAdapter }
  
  describe '#commit' do
    context 'with no error' do
      it 'calls on the master session' do
        master.should_receive(:commit)
        proxy.commit
      end
    end
    
    context 'with an error' do
      it 'passes the exception to the exception handler adapter' do
        exception = Exception.new
        exception_handler_adapter.should_receive(:handle).with(exception)
        master.should_receive(:commit).and_raise(exception)
        proxy.commit
      end
    end
  end
  
  describe '#search' do
    context 'with no error' do
      it 'calls on the slave session' do
        slave.should_receive(:search).and_return(true)
        master.should_not_receive(:search)
        proxy.search
      end
    end
    
    context 'with an error on the slave session' do
      it 'calls on the master session' do
        exception = Exception.new
        slave.should_receive(:search).and_raise(exception)
        exception_handler_adapter.should_receive(:handle).with(exception)
        master.should_receive(:search).and_return(true)
        proxy.search
      end
    end
    
    context 'with an error on the slave and master sessions' do
      it 'raises the error with no handling' do
        exception = Exception.new
        slave.should_receive(:search).and_raise(exception)
        master.should_receive(:search).and_raise(exception)
        exception_handler_adapter.should_receive(:handle).with(exception).twice
        proxy.should_receive(:raise).with(exception)
        proxy.search
      end
    end
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sunspot-rails-failover-0.0.4 spec/sunspot-rails-failover/master_slave_with_failover_session_proxy_spec.rb
sunspot-rails-failover-0.0.3 spec/sunspot-rails-failover/master_slave_with_failover_session_proxy_spec.rb