From b2ebaa1816914a6b17aaaa4e59a78857324cf159 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Thu, 16 Jul 2020 14:41:57 -0400 Subject: [PATCH 1/3] Deprecate #to_miq_a --- lib/gems/pending/util/extensions/miq-array.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/gems/pending/util/extensions/miq-array.rb b/lib/gems/pending/util/extensions/miq-array.rb index 044d7ff56..531970c50 100644 --- a/lib/gems/pending/util/extensions/miq-array.rb +++ b/lib/gems/pending/util/extensions/miq-array.rb @@ -1,14 +1,17 @@ require 'more_core_extensions/core_ext/array' require 'active_support/core_ext/array/wrap' +require 'active_support/deprecation' class Object #:nodoc: def to_miq_a + ActiveSupport::Deprecation.warn("Object#to_miq_a should be replaced by Array.wrap", caller.drop(0)) Array.wrap(self) end end class String def to_miq_a + ActiveSupport::Deprecation.warn("String#to_miq_a should be replaced by String#lines.to_a", caller.drop(0)) lines.to_a end end From 75c4e6198d41a3f50916f120ee4a4f71b91fcea8 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Wed, 22 Jul 2020 09:39:52 -0400 Subject: [PATCH 2/3] Silence ActiveSupport::Deprecation warnings to reduce noise These tests are still valid until the code is removed. --- spec/util/extensions/miq-array_spec.rb | 28 ++++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/spec/util/extensions/miq-array_spec.rb b/spec/util/extensions/miq-array_spec.rb index 9f4f2744f..c2c887fb6 100644 --- a/spec/util/extensions/miq-array_spec.rb +++ b/spec/util/extensions/miq-array_spec.rb @@ -2,15 +2,19 @@ describe NilClass do it '#to_miq_a' do - expect(nil.to_miq_a).to eq([]) - expect(nil.to_miq_a).to eq(Array.wrap(nil)) + ActiveSupport::Deprecation.silence do + expect(nil.to_miq_a).to eq([]) + expect(nil.to_miq_a).to eq(Array.wrap(nil)) + end end end describe Hash do it '#to_miq_a' do - expect({}.to_miq_a).to eq([{}]) - expect({}.to_miq_a).to eq(Array.wrap({})) + ActiveSupport::Deprecation.silence do + expect({}.to_miq_a).to eq([{}]) + expect({}.to_miq_a).to eq(Array.wrap({})) + end end end @@ -18,26 +22,28 @@ context "#to_miq_a" do it 'normal' do # NOTE: this differs from Array.wrap - expect("onetwo".to_miq_a).to eq(["onetwo"]) + ActiveSupport::Deprecation.silence { expect("onetwo".to_miq_a).to eq(["onetwo"]) } end it 'with an empty string' do # NOTE: this differs from Array.wrap - expect("".to_miq_a).to eq([]) + ActiveSupport::Deprecation.silence { expect("".to_miq_a).to eq([]) } end it 'with newlines' do # NOTE: this differs from Array.wrap - expect("one\ntwo".to_miq_a).to eq(["one\n", "two"]) + ActiveSupport::Deprecation.silence { expect("one\ntwo".to_miq_a).to eq(["one\n", "two"]) } end end end describe Array do it "#to_miq_a" do - expect([].to_miq_a).to eq([]) - expect([[]].to_miq_a).to eq([[]]) - expect([].to_miq_a).to eq(Array.wrap([])) - expect([[]].to_miq_a).to eq(Array.wrap([[]])) + ActiveSupport::Deprecation.silence do + expect([].to_miq_a).to eq([]) + expect([[]].to_miq_a).to eq([[]]) + expect([].to_miq_a).to eq(Array.wrap([])) + expect([[]].to_miq_a).to eq(Array.wrap([[]])) + end end end From 62070aa7eb1b368b137a4989cac9a03cf1e45cb2 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Fri, 24 Jul 2020 16:18:09 -0400 Subject: [PATCH 3/3] String#lines is already an Array, no need for the #to_a --- lib/gems/pending/util/extensions/miq-array.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/gems/pending/util/extensions/miq-array.rb b/lib/gems/pending/util/extensions/miq-array.rb index 531970c50..4e3eccb30 100644 --- a/lib/gems/pending/util/extensions/miq-array.rb +++ b/lib/gems/pending/util/extensions/miq-array.rb @@ -11,8 +11,8 @@ def to_miq_a class String def to_miq_a - ActiveSupport::Deprecation.warn("String#to_miq_a should be replaced by String#lines.to_a", caller.drop(0)) - lines.to_a + ActiveSupport::Deprecation.warn("String#to_miq_a should be replaced by String#lines", caller.drop(0)) + lines end end