From fc98ff0f31f3f6c5a62ae9268f81ec0db2f656ff Mon Sep 17 00:00:00 2001 From: Johnny Shields <27655+johnnyshields@users.noreply.github.com> Date: Wed, 8 Nov 2023 03:09:01 +0900 Subject: [PATCH] MONGOID-5668 [Monkey Patch Removal] Remove String/Symbol#mongoid_id? (#5703) * Remove String#mongoid_id? and Symbol#mongoid_id? * deprecate instead of remove --------- Co-authored-by: Jamis Buck --- lib/mongoid/extensions/string.rb | 2 ++ lib/mongoid/extensions/symbol.rb | 2 ++ spec/mongoid/extensions/string_spec.rb | 31 -------------------------- spec/mongoid/extensions/symbol_spec.rb | 31 -------------------------- 4 files changed, 4 insertions(+), 62 deletions(-) diff --git a/lib/mongoid/extensions/string.rb b/lib/mongoid/extensions/string.rb index 5e31d84ef8..df210f945e 100644 --- a/lib/mongoid/extensions/string.rb +++ b/lib/mongoid/extensions/string.rb @@ -71,9 +71,11 @@ def collectionize # "_id".mongoid_id? # # @return [ true | false ] If the string is id or _id. + # @deprecated def mongoid_id? self =~ /\A(|_)id\z/ end + Mongoid.deprecate(self, :mongoid_id?) # Is the string a number? The literals "NaN", "Infinity", and "-Infinity" # are counted as numbers. diff --git a/lib/mongoid/extensions/symbol.rb b/lib/mongoid/extensions/symbol.rb index 65c9b519a5..c37536e965 100644 --- a/lib/mongoid/extensions/symbol.rb +++ b/lib/mongoid/extensions/symbol.rb @@ -13,9 +13,11 @@ module Symbol # :_id.mongoid_id? # # @return [ true | false ] If the symbol is :id or :_id. + # @deprecated def mongoid_id? to_s.mongoid_id? end + Mongoid.deprecate(self, :mongoid_id?) module ClassMethods diff --git a/spec/mongoid/extensions/string_spec.rb b/spec/mongoid/extensions/string_spec.rb index adc9cd49bd..e7d27c7aa3 100644 --- a/spec/mongoid/extensions/string_spec.rb +++ b/spec/mongoid/extensions/string_spec.rb @@ -172,37 +172,6 @@ class Patient end end - describe "#mongoid_id?" do - - context "when the string is id" do - - it "returns true" do - expect("id").to be_mongoid_id - end - end - - context "when the string is _id" do - - it "returns true" do - expect("_id").to be_mongoid_id - end - end - - context "when the string contains id" do - - it "returns false" do - expect("identity").to_not be_mongoid_id - end - end - - context "when the string contains _id" do - - it "returns false" do - expect("something_id").to_not be_mongoid_id - end - end - end - [ :mongoize, :demongoize ].each do |method| describe ".#{method}" do diff --git a/spec/mongoid/extensions/symbol_spec.rb b/spec/mongoid/extensions/symbol_spec.rb index 2bd4d7b6a5..6ec6bd0e75 100644 --- a/spec/mongoid/extensions/symbol_spec.rb +++ b/spec/mongoid/extensions/symbol_spec.rb @@ -5,37 +5,6 @@ describe Mongoid::Extensions::Symbol do - describe "#mongoid_id?" do - - context "when the string is id" do - - it "returns true" do - expect(:id).to be_mongoid_id - end - end - - context "when the string is _id" do - - it "returns true" do - expect(:_id).to be_mongoid_id - end - end - - context "when the string contains id" do - - it "returns false" do - expect(:identity).to_not be_mongoid_id - end - end - - context "when the string contains _id" do - - it "returns false" do - expect(:something_id).to_not be_mongoid_id - end - end - end - [ :mongoize, :demongoize ].each do |method| describe ".mongoize" do