Remove BigDecimal.new

Christopher Vollick created

It turns out in newer versions of Ruby this isn't cool anymore.
The new way is BigDecimal(value), which is dumb, but whatever...

Change summary

lib/btc_sell_prices.rb               | 2 +-
lib/customer.rb                      | 2 +-
lib/electrum.rb                      | 2 +-
lib/plan.rb                          | 2 +-
lib/transaction.rb                   | 4 ++--
test/test_btc_sell_prices.rb         | 4 ++--
test/test_buy_account_credit_form.rb | 2 +-
test/test_customer.rb                | 4 ++--
test/test_customer_repo.rb           | 2 +-
test/test_registration.rb            | 2 +-
10 files changed, 13 insertions(+), 13 deletions(-)

Detailed changes

lib/btc_sell_prices.rb 🔗

@@ -24,7 +24,7 @@ class BTCSellPrices
 			bitcoin_row = canadianbitcoins.at("#ticker > table > tbody > tr")
 			raise "Bitcoin row has moved" unless bitcoin_row.at("td").text == "Bitcoin"
 
-			BigDecimal.new(
+			BigDecimal(
 				bitcoin_row.at("td:nth-of-type(3)").text.match(/^\$(\d+\.\d+)/)[1]
 			)
 		end

lib/customer.rb 🔗

@@ -24,7 +24,7 @@ class Customer
 		customer_id,
 		jid,
 		plan: CustomerPlan.new(customer_id),
-		balance: BigDecimal.new(0),
+		balance: BigDecimal(0),
 		sgx: BackendSgx.new(customer_id)
 	)
 		@plan = plan

lib/electrum.rb 🔗

@@ -50,7 +50,7 @@ class Electrum
 		end
 
 		def amount_for(*addresses)
-			BigDecimal.new(
+			BigDecimal(
 				@tx["outputs"]
 					.select { |o| addresses.include?(o["address"]) }
 					.map { |o| o["value_sats"] }

lib/plan.rb 🔗

@@ -21,7 +21,7 @@ class Plan
 	end
 
 	def monthly_price
-		BigDecimal.new(@plan[:monthly_price]) / 10000
+		BigDecimal(@plan[:monthly_price]) / 10000
 	end
 
 	def merchant_account

lib/transaction.rb 🔗

@@ -45,7 +45,7 @@ class Transaction
 		@customer_id = braintree_transaction.customer_details.id
 		@transaction_id = braintree_transaction.id
 		@created_at = braintree_transaction.created_at
-		@amount = BigDecimal.new(braintree_transaction.amount, 4)
+		@amount = BigDecimal(braintree_transaction.amount, 4)
 	end
 
 	def insert
@@ -58,7 +58,7 @@ class Transaction
 	end
 
 	def bonus
-		return BigDecimal.new(0) if amount <= 15
+		return BigDecimal(0) if amount <= 15
 		amount *
 			case amount
 			when (15..29.99)

test/test_btc_sell_prices.rb 🔗

@@ -15,7 +15,7 @@ class BTCSellPricesTest < Minitest::Test
 			body: "<div id='ticker'><table><tbody><tr>" \
 			      "<td>Bitcoin</td><td></td><td>$123.00</td>"
 		)
-		assert_equal BigDecimal.new(123), @subject.cad.sync
+		assert_equal BigDecimal(123), @subject.cad.sync
 	end
 	em :test_cad
 
@@ -25,7 +25,7 @@ class BTCSellPricesTest < Minitest::Test
 			      "<td>Bitcoin<td></td><td>$123.00</td>"
 		)
 		@redis.expect(:get, EMPromise.resolve("0.5"), ["cad_to_usd"])
-		assert_equal BigDecimal.new(123) / 2, @subject.usd.sync
+		assert_equal BigDecimal(123) / 2, @subject.usd.sync
 	end
 	em :test_usd
 end

test/test_buy_account_credit_form.rb 🔗

@@ -10,7 +10,7 @@ class BuyAccountCreditFormTest < Minitest::Test
 	def setup
 		@payment_method = OpenStruct.new(card_type: "Test", last_4: "1234")
 		@form = BuyAccountCreditForm.new(
-			BigDecimal.new("15.1234"),
+			BigDecimal("15.1234"),
 			PaymentMethods.new([@payment_method])
 		)
 	end

test/test_customer.rb 🔗

@@ -34,7 +34,7 @@ class CustomerTest < Minitest::Test
 				Matching.new do |params|
 					params[0] == "test" &&
 					params[1].is_a?(String) &&
-					BigDecimal.new(-1) == params[2]
+					BigDecimal(-1) == params[2]
 				end
 			]
 		)
@@ -61,7 +61,7 @@ class CustomerTest < Minitest::Test
 				Matching.new do |params|
 					params[0] == "test" &&
 					params[1].is_a?(String) &&
-					BigDecimal.new(-1) == params[2]
+					BigDecimal(-1) == params[2]
 				end
 			]
 		)

test/test_customer_repo.rb 🔗

@@ -65,7 +65,7 @@ class CustomerRepoTest < Minitest::Test
 			[String, [7357]]
 		)
 		customer = repo.find(7357).sync
-		assert_equal BigDecimal.new(0), customer.balance
+		assert_equal BigDecimal(0), customer.balance
 		assert_mock db
 	end
 	em :test_find_db_empty

test/test_registration.rb 🔗

@@ -215,7 +215,7 @@ class RegistrationTest < Minitest::Test
 				)
 				Registration::Payment::Bitcoin::BTC_SELL_PRICES.expect(
 					:usd,
-					EMPromise.resolve(BigDecimal.new(1))
+					EMPromise.resolve(BigDecimal(1))
 				)
 				@bitcoin.stub(:save, EMPromise.resolve(nil)) do
 					execute_command(blather: blather) do