Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MONGOID-4833 MONGOID-4849 Ruby 3.0 compatibility for 7.0 branch #4771

Merged
merged 2 commits into from May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/mongoid.rb
Expand Up @@ -102,5 +102,5 @@ def client(name)
# Mongoid.database = Mongo::Connection.new.db("test")
#
# @since 1.0.0
delegate(*(Config.public_instance_methods(false) - [ :logger=, :logger ] << { to: Config }))
delegate(*(Config.public_instance_methods(false) - [ :logger=, :logger ]), to: Config)
end
16 changes: 16 additions & 0 deletions spec/app/models/delegating_patient.rb
@@ -0,0 +1,16 @@
# frozen_string_literal: true
# encoding: utf-8

class DelegatingPatient
include Mongoid::Document

embeds_one :email

# Instance level delegation
delegate :address, to: :email

class << self
# Class level delegation
delegate :default_client, to: ::Mongoid
end
end
22 changes: 22 additions & 0 deletions spec/integration/document_spec.rb
@@ -0,0 +1,22 @@
# frozen_string_literal: true
# encoding: utf-8

require 'spec_helper'

describe Mongoid::Document do
context 'when including class uses delegate' do
let(:patient) do
DelegatingPatient.new(
email: Email.new(address: 'test@example.com'),
)
end

it 'works for instance level delegation' do
patient.address.should == 'test@example.com'
end

it 'works for class level delegation' do
DelegatingPatient.default_client.should be Mongoid.default_client
end
end
end