Skip to content

Commit

Permalink
Merge pull request #483 from bdunne/to_miq_a
Browse files Browse the repository at this point in the history
Deprecate #to_miq_a
  • Loading branch information
jrafanie authored Jul 24, 2020
2 parents 71f5866 + 62070aa commit 05194ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
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

0 comments on commit 05194ac

Please sign in to comment.