sunspot-rails-failover 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -15,9 +15,10 @@ Your config/sunspot.yml file should look something like this:
15
15
 
16
16
  development:
17
17
  master_solr:
18
- url: http://localhost:8984/solr
18
+ host: ...
19
+ port: ...
19
20
  solr:
20
- url: http://localhost:8985/solr
21
+ host: ...
21
22
 
22
23
  NOTE: You do *not* have to have a master session. If a master session is
23
24
  not detected, sunspot-rails-failover will default to what sunspot_rails
@@ -11,7 +11,8 @@ module Sunspot
11
11
  def setup
12
12
  Sunspot.session = if Sunspot::Rails.configuration.has_master?
13
13
  Sunspot::SessionProxy::MasterSlaveWithFailoverSessionProxy.new(
14
- Sunspot::Session.new(master_config), Sunspot::Session.new(slave_config)
14
+ SessionProxy::ThreadLocalSessionProxy.new(master_config),
15
+ SessionProxy::ThreadLocalSessionProxy.new(slave_config)
15
16
  )
16
17
  else
17
18
  Sunspot::SessionProxy::ThreadLocalSessionProxy.new(slave_config)
@@ -21,17 +22,11 @@ module Sunspot
21
22
  private
22
23
 
23
24
  def slave_config
24
- build_config('solr', 'url')
25
+ Sunspot::Rails.send :slave_config, Sunspot::Rails.configuration
25
26
  end
26
27
 
27
28
  def master_config
28
- build_config('master_solr', 'url')
29
- end
30
-
31
- def build_config(*keys)
32
- Sunspot::Configuration.build.tap do |config|
33
- config.solr.url = Sunspot::Rails.configuration.send :user_configuration_from_key, *keys
34
- end
29
+ Sunspot::Rails.send :master_config, Sunspot::Rails.configuration
35
30
  end
36
31
  end
37
32
  end
@@ -1,7 +1,7 @@
1
1
  module Sunspot
2
2
  module Rails
3
3
  module Failover
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.4"
5
5
  end
6
6
  end
7
7
  end
@@ -3,21 +3,34 @@ require 'spec_helper'
3
3
  describe Sunspot::Rails::Failover do
4
4
  describe '.setup' do
5
5
  let(:configuration) { double('configuration') }
6
+ let(:slave_config) { double('slave_config') }
7
+ let(:master_config) { double('master_config') }
6
8
 
7
9
  before do
8
10
  Sunspot::Rails.stub(:configuration).and_return(configuration)
9
- configuration.should_receive(:user_configuration_from_key).with('solr', 'url')
11
+ Sunspot::Rails.stub(:slave_config).and_return(slave_config)
12
+ Sunspot::Rails.stub(:master_config).and_return(master_config)
10
13
  end
11
14
 
12
15
  context 'with a master configuration' do
13
16
  before do
14
17
  configuration.should_receive(:has_master?).and_return(true)
15
- configuration.should_receive(:user_configuration_from_key).with('master_solr', 'url')
16
18
  end
17
19
 
18
- it 'sets the session to master/slave with failover support' do
20
+ let(:proxy) { double('master_slave_failover_proxy') }
21
+ let(:master_session) { double('master_session') }
22
+ let(:slave_session) { double('slave_session') }
23
+
24
+ it 'sets the session to master/slave with failover support' do
25
+ Sunspot::SessionProxy::ThreadLocalSessionProxy.should_receive(:new).with(master_config).and_return(master_session)
26
+ Sunspot::SessionProxy::ThreadLocalSessionProxy.should_receive(:new).with(slave_config).and_return(slave_session)
27
+
28
+ Sunspot::SessionProxy::MasterSlaveWithFailoverSessionProxy.should_receive(:new).with(
29
+ master_session, slave_session
30
+ ).and_return(proxy)
31
+
19
32
  described_class.setup
20
- Sunspot.session.should be_an_instance_of(Sunspot::SessionProxy::MasterSlaveWithFailoverSessionProxy)
33
+ Sunspot.session.should eq(proxy)
21
34
  end
22
35
  end
23
36
 
@@ -25,10 +38,14 @@ describe Sunspot::Rails::Failover do
25
38
  before do
26
39
  configuration.should_receive(:has_master?).and_return(false)
27
40
  end
41
+
42
+ let(:proxy) { double('thread_local_proxy') }
28
43
 
29
- it 'sets the session to the default' do
44
+ it 'sets the session to the default proxy' do
45
+ Sunspot::SessionProxy::ThreadLocalSessionProxy.should_receive(:new).with(slave_config).and_return(proxy)
46
+
30
47
  described_class.setup
31
- Sunspot.session.should be_an_instance_of(Sunspot::SessionProxy::ThreadLocalSessionProxy)
48
+ Sunspot.session.should eq(proxy)
32
49
  end
33
50
  end
34
51
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: sunspot-rails-failover
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Justin Ko
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-04 00:00:00 -05:00
13
+ date: 2011-05-05 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency