Skip to content

Commit

Permalink
Added tests for transforming documents.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Apr 15, 2011
1 parent aacf0f5 commit d926698
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/plucky/query.rb
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions test/plucky/test_query.rb
Expand Up @@ -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.