Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added #update method.

  • Loading branch information...
commit 92e9210fac87a49028f4b7afb8d9ae094cd8d61c 1 parent f1c2f52
@jnunemaker jnunemaker authored
Showing with 24 additions and 0 deletions.
  1. +5 −0 lib/plucky/query.rb
  2. +19 −0 test/plucky/test_query.rb
View
5 lib/plucky/query.rb
@@ -90,6 +90,11 @@ def remove(opts={}, driver_opts={})
query.collection.remove(query.criteria.to_hash, driver_opts)
end
+ def update(document, driver_opts={})
+ query = clone
+ query.collection.update(query.criteria.to_hash, document, driver_opts)
+ end
+
def count(opts={})
find_each(opts).count
end
View
19 test/plucky/test_query.rb
@@ -311,6 +311,25 @@ class QueryTest < Test::Unit::TestCase
end
end
+ context "#update" do
+ setup do
+ @query = Query.new(@collection).where('_id' => 'john')
+ end
+
+ should "work with document" do
+ @query.update('$set' => {'age' => 29})
+ doc = @query.first('_id' => 'john')
+ doc['age'].should be(29)
+ end
+
+ should "work with document and driver options" do
+ @query.update({'$set' => {'age' => 30}}, :multi => true)
+ @query.each do |doc|
+ doc['age'].should be(30)
+ end
+ end
+ end
+
context "#[]" do
should "return value if key in criteria (symbol)" do
Query.new(@collection, :count => 1)[:count].should == 1
Please sign in to comment.
Something went wrong with that request. Please try again.