Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding Criteria#enslave

  • Loading branch information...
commit f20257b681959b1676a337b70ed659bdec315ff3 1 parent 922eded
@durran durran authored
View
20 lib/mongoid/criterion/optional.rb
@@ -2,6 +2,26 @@
module Mongoid #:nodoc:
module Criterion #:nodoc:
module Optional
+ # Flags the criteria to execute against a read-only slave in the pool
+ # instead of master.
+ #
+ # Example:
+ #
+ # <tt>criteria.enslave</tt>
+ def enslave
+ @enslaved = true; self
+ end
+
+ # Returns whether or not the criteria is flagged to execute against a
+ # read-only slave in the pool.
+ #
+ # Example:
+ #
+ # <tt>criteria.enslaved?</tt>
+ def enslaved?
+ @enslaved == true
+ end
+
# Adds a criterion to the +Criteria+ that specifies additional options
# to be passed to the Ruby driver, in the exact format for the driver.
#
View
12 spec/unit/mongoid/criterion/optional_spec.rb
@@ -7,6 +7,18 @@
@canvas_criteria = Mongoid::Criteria.new(Canvas)
end
+ describe "#enslave" do
+
+ it "sets the enslaved option on the criteria" do
+ @criteria.enslave
+ @criteria.should be_enslaved
+ end
+
+ it "returns self" do
+ @criteria.enslave.should == @criteria
+ end
+ end
+
describe "#extras" do
context "filtering" do
Please sign in to comment.
Something went wrong with that request. Please try again.