Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
644c2a3
commit fb9f74c
Showing
3 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |