Skip to content

Commit

Permalink
Merge pull request #655 from estolfo/RUBY-964-string-out
Browse files Browse the repository at this point in the history
RUBY-964 Support String collection name as :out option in #map_reduce
  • Loading branch information
estolfo committed Jul 10, 2015
2 parents dd490a5 + df355df commit 739ca39
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mongo/collection/view/map_reduce.rb
Expand Up @@ -194,7 +194,7 @@ def fetch_query_spec
{ :selector => {},
:options => {},
:db_name => database.name,
:coll_name => out.values.first }
:coll_name => out.respond_to?(:keys) ? out.values.first : out }
end

def fetch_query_op
Expand Down
44 changes: 44 additions & 0 deletions spec/mongo/collection/view/map_reduce_spec.rb
Expand Up @@ -66,6 +66,39 @@
end
end

context 'when out is in the options' do

after do
authorized_client['output_collection'].delete_many
end

context 'when out is a string' do

let(:options) do
{ :out => 'output_collection' }
end

it 'iterates over the documents in the result' do
map_reduce.each do |document|
expect(document[:value]).to_not be_nil
end
end
end

context 'when out is a document' do

let(:options) do
{ :out => { replace: 'output_collection' } }
end

it 'iterates over the documents in the result' do
map_reduce.each do |document|
expect(document[:value]).to_not be_nil
end
end
end
end

context 'when out is inline' do

let(:new_map_reduce) do
Expand Down Expand Up @@ -135,6 +168,17 @@
expect(new_map_reduce.count).to eq(2)
end
end

context 'when the option is a collection name' do

let(:new_map_reduce) do
map_reduce.out('output_collection')
end

it 'fetches the results from the collection' do
expect(new_map_reduce.count).to eq(2)
end
end
end

context 'when the view has a selector' do
Expand Down

0 comments on commit 739ca39

Please sign in to comment.