Skip to content

Commit eb88df6

Browse files
committed
Merge pull request #691 from namusyaka/add-collections-to-client
Delegate collections to the current database
2 parents 39612be + 32ba84e commit eb88df6

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/mongo/client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class Client
3636
# @return [ Hash ] options The configuration options.
3737
attr_reader :options
3838

39-
# Delegate command execution to the current database.
40-
def_delegators :@database, :command
39+
# Delegate command and collections execution to the current database.
40+
def_delegators :@database, :command, :collections
4141

4242
# Delegate subscription to monitoring.
4343
def_delegators :@monitoring, :subscribe, :unsubscribe

spec/mongo/client_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,4 +742,24 @@
742742
expect(client.dup.options).to be_a(Mongo::Options::Redacted)
743743
end
744744
end
745+
746+
describe '#collections' do
747+
748+
before do
749+
authorized_client.database[:users].create
750+
end
751+
752+
after do
753+
authorized_client.database[:users].drop
754+
end
755+
756+
let(:collection) do
757+
Mongo::Collection.new(authorized_client.database, 'users')
758+
end
759+
760+
it 'refers the current database collections' do
761+
expect(authorized_client.collections).to include(collection)
762+
expect(authorized_client.collections).to all(be_a(Mongo::Collection))
763+
end
764+
end
745765
end

0 commit comments

Comments
 (0)