Skip to content

Commit

Permalink
Replace deprecated BigDecimal.new() calls with BigDecimal()
Browse files Browse the repository at this point in the history
After upgrading to ruby 2.6.1, our application started logging this
warning:
```
warning: BigDecimal.new is deprecated; use BigDecimal() method instead.
```
which was being emitted from roxml-4.0.0/lib/roxml/definition.rb:179

So, in this commit I've replaced the deprecated `BigDecimal.new`
invocations with invoking the `BigDecimal` method as recommended.
  • Loading branch information
rmacklin committed Feb 11, 2019
1 parent 848f1a1 commit 7fceacc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/roxml/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def self.block_shorthands
CORE_BLOCK_SHORTHANDS.tap do |blocks|
blocks.reverse_merge!(BigDecimal => lambda do |val|
all(val) do |v|
BigDecimal.new(v) unless v.blank?
BigDecimal(v) unless v.blank?
end
end) if defined?(BigDecimal)

Expand Down
8 changes: 4 additions & 4 deletions spec/definition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ def self.from_xml(val)
it_should_behave_like "block shorthand type declaration"

it "should translate text to decimal numbers" do
expect(@definition.blocks.first['3']).to eq(BigDecimal.new("3.0"))
expect(@definition.blocks.first['0.3']).to eq(BigDecimal.new("0.3"))
expect(@definition.blocks.first['3']).to eq(BigDecimal("3.0"))
expect(@definition.blocks.first['0.3']).to eq(BigDecimal("0.3"))
end

# Ruby behavior of BigDecimal changed in 2.4, this test is not valid on older rubies
Expand All @@ -293,12 +293,12 @@ def self.from_xml(val)
end

it "should extract what it can" do
expect(@definition.blocks.first['11sttf']).to eql(BigDecimal.new("11.0"))
expect(@definition.blocks.first['11sttf']).to eql(BigDecimal("11.0"))
end

context "when passed an array" do
it "should translate the array elements to integer" do
expect(@definition.blocks.first.call(["12.1", "328.2"])).to eq([BigDecimal.new("12.1"), BigDecimal.new("328.2")])
expect(@definition.blocks.first.call(["12.1", "328.2"])).to eq([BigDecimal("12.1"), BigDecimal("328.2")])
end
end
end
Expand Down

0 comments on commit 7fceacc

Please sign in to comment.