Skip to content

Commit

Permalink
MONGOID-4833 MONGOID-4849 Ruby 3.0 compatibility for 7.0 branch (#4771)
Browse files Browse the repository at this point in the history
* MONGOID-4833 Avoid delegate warning message on ruby MRI 2.7.x

`
..lib/mongoid.rb:104: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
../.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-5.2.4.2/lib/active_support/core_ext/module/delegation.rb:154: warning: The called method `delegate' is defined here
`

* MONGOID-4849 test ActiveSupport delegation (backported from #4739)

Co-authored-by: Oleg Pudeyev <oleg@bsdpower.com>

Co-authored-by: Alexander Oryol <eagle.alex@gmail.com>
Co-authored-by: Oleg Pudeyev <oleg@bsdpower.com>
  • Loading branch information
3 people committed May 20, 2020
1 parent 644c2a3 commit fb9f74c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
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

0 comments on commit fb9f74c

Please sign in to comment.