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

Deprecate #to_miq_a #483

Merged
merged 3 commits into from
Jul 24, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/gems/pending/util/extensions/miq-array.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
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
lines.to_a
ActiveSupport::Deprecation.warn("String#to_miq_a should be replaced by String#lines", caller.drop(0))
lines
end
end

Expand Down
28 changes: 17 additions & 11 deletions spec/util/extensions/miq-array_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,48 @@

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

describe String do
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