Permalink
Browse files

Return master if slaves don't exist and enslaving

  • Loading branch information...
1 parent 53431ca commit aba4366e9ac8f19463925f22f66ff2e95db5d8f3 @durran durran committed Feb 10, 2010
Showing with 8 additions and 1 deletion.
  1. +6 −1 lib/mongoid/collection.rb
  2. +2 −0 spec/unit/mongoid/collection_spec.rb
@@ -31,7 +31,7 @@ class Collection
# Either a +Master+ or +Slaves+ collection.
def directed(options = {})
enslave = options.delete(:enslave)
- enslave ? slaves : master
+ enslave ? master_or_slaves : master
end
# Find documents from the database given a selector and options.
@@ -109,5 +109,10 @@ def master
def slaves
@slaves ||= Collections::Slaves.new(Mongoid.slaves, @name)
end
+
+ protected
+ def master_or_slaves
+ slaves.empty? ? master : slaves
+ end
end
end
@@ -77,6 +77,7 @@
before do
@options = { :enslave => true }
+ slaves.expects(:empty?).returns(false)
slaves.expects(:find).with({ :test => "value" }, {}).returns(@mongo_cursor)
end
@@ -112,6 +113,7 @@
before do
@options = { :enslave => true }
+ slaves.expects(:empty?).returns(false)
slaves.expects(:find_one).with({ :test => "value" }, {}).returns(@person)
end

0 comments on commit aba4366

Please sign in to comment.