Permalink
Browse files

Merge pull request #1 from flyingmachine/master

Hey Justin - could you have a look at this?
  • Loading branch information...
2 parents 4e7c3cb + 0c1371b commit 762b1a7e699af55c5aa8eb4164ddf187e223af14 @justinko committed Jun 23, 2011
View
8 lib/sunspot/session_proxy/master_slave_with_failover_session_proxy.rb
@@ -10,9 +10,11 @@ def commit
end
def search(*types, &block)
- [slave_session, master_session].any? do |session|
- with_exception_handling { session.search(*types, &block) }
- end or raise(exception)
+ result = with_exception_handling { slave_session.search(*types, &block) }
+ result ||= with_exception_handling { master_session.search(*types, &block) }
+
+ raise(exception) unless result
+ result
end
private
View
8 spec/sunspot/session_proxy/master_slave_with_failover_session_proxy_spec.rb
@@ -34,6 +34,14 @@ module SessionProxy
master.should_not_receive(:search)
proxy.search
end
+
+ it "returns a Sunspot::Search::StandardSearch object" do
+ connection = double
+ connection.stub(:request)
+ Sunspot::Session.any_instance.stub(:connection).and_return(connection)
+ result = proxy.search(Searchable)
+ result.should be_a(Sunspot::Search::StandardSearch)
+ end
end
context 'with an error on the slave session' do
View
3 spec/support/my_exception_handler.rb
@@ -1,4 +1,5 @@
class MyExceptionHandler
- def handle
+ def self.handle(ex)
+ raise ex
end
end
View
7 spec/support/searchable.rb
@@ -0,0 +1,7 @@
+class Searchable
+ attr_accessor :title
+end
+
+Sunspot.setup(Searchable) do
+ text :title
+end

0 comments on commit 762b1a7

Please sign in to comment.