Permalink
Browse files

Added tests for transforming documents.

  • Loading branch information...
1 parent aacf0f5 commit d926698ac33c663709539511badb6b18c069b210 @jnunemaker jnunemaker committed Apr 15, 2011
Showing with 23 additions and 2 deletions.
  1. +3 −2 lib/plucky/query.rb
  2. +20 −0 test/plucky/test_query.rb
View
5 lib/plucky/query.rb
@@ -6,8 +6,9 @@ class Query
extend Forwardable
OptionKeys = [
- :select, :offset, :order, # MM
- :fields, :skip, :limit, :sort, :hint, :snapshot, :batch_size, :timeout # Ruby Driver
+ :select, :offset, :order, # MM
+ :fields, :skip, :limit, :sort, :hint, :snapshot, # Ruby Driver
+ :batch_size, :timeout, :transformer # Ruby Driver
]
attr_reader :criteria, :options, :collection
View
20 test/plucky/test_query.rb
@@ -763,5 +763,25 @@ class QueryTest < Test::Unit::TestCase
explain['nscanned'].should == 3
end
end
+
+ context "Transforming documents" do
+ setup do
+ transformer = lambda { |doc| @user_class.new(doc['_id'], doc['name'], doc['age']) }
+ @user_class = Struct.new(:id, :name, :age)
+ @query = Query.new(@collection, :transformer => transformer)
+ end
+
+ should "work with find_one" do
+ result = @query.find_one('_id' => 'john')
+ result.should be_instance_of(@user_class)
+ end
+
+ should "work with find_each" do
+ results = @query.find_each
+ results.each do |result|
+ result.should be_instance_of(@user_class)
+ end
+ end
+ end
end
end

0 comments on commit d926698

Please sign in to comment.