From d047e993746f8ad336f903c9fa29a30bd5daed72 Mon Sep 17 00:00:00 2001 From: namusyaka Date: Fri, 11 Sep 2015 11:40:05 +0900 Subject: [PATCH 1/2] Delegate collections to the current database --- lib/mongo/client.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mongo/client.rb b/lib/mongo/client.rb index 3c0fcb4543..326451fa4d 100644 --- a/lib/mongo/client.rb +++ b/lib/mongo/client.rb @@ -36,8 +36,8 @@ class Client # @return [ Hash ] options The configuration options. attr_reader :options - # Delegate command execution to the current database. - def_delegators :@database, :command + # Delegate command and collections execution to the current database. + def_delegators :@database, :command, :collections # Delegate subscription to monitoring. def_delegators :@monitoring, :subscribe, :unsubscribe From 32ba84e79e2d84eb2b3b88c1eba22a3232bd00cf Mon Sep 17 00:00:00 2001 From: namusyaka Date: Sat, 12 Sep 2015 01:13:44 +0900 Subject: [PATCH 2/2] Add Mongo::Client#collections spec Use authorized_client --- spec/mongo/client_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spec/mongo/client_spec.rb b/spec/mongo/client_spec.rb index 405af9e464..05b496f97d 100644 --- a/spec/mongo/client_spec.rb +++ b/spec/mongo/client_spec.rb @@ -742,4 +742,24 @@ expect(client.dup.options).to be_a(Mongo::Options::Redacted) end end + + describe '#collections' do + + before do + authorized_client.database[:users].create + end + + after do + authorized_client.database[:users].drop + end + + let(:collection) do + Mongo::Collection.new(authorized_client.database, 'users') + end + + it 'refers the current database collections' do + expect(authorized_client.collections).to include(collection) + expect(authorized_client.collections).to all(be_a(Mongo::Collection)) + end + end end