Skip to content

Commit

Permalink
Prepare for newer rubies
Browse files Browse the repository at this point in the history
  • Loading branch information
mhenrixon committed Aug 24, 2020
1 parent 4fe7f4a commit 702a551
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.5
2.6.6
4 changes: 2 additions & 2 deletions lib/payday/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def initialize(options = {})

# The tax rate that we're applying, as a BigDecimal
def tax_rate=(value)
@tax_rate = BigDecimal.new(value.to_s)
@tax_rate = BigDecimal((value || 0).to_s)
end

# Shipping rate
def shipping_rate=(value)
@shipping_rate = BigDecimal.new(value.to_s)
@shipping_rate = BigDecimal((value || 0).to_s)
end
end
end
2 changes: 1 addition & 1 deletion lib/payday/invoiceable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def bill_to

# Calculates the subtotal of this invoice by adding up all of the line items
def subtotal
line_items.reduce(BigDecimal.new("0")) { |result, item| result += item.amount }
line_items.reduce(BigDecimal("0")) { |result, item| result += item.amount }
end

# The tax for this invoice, as a BigDecimal
Expand Down
4 changes: 2 additions & 2 deletions lib/payday/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def initialize(options = {})

# Sets the quantity of this {LineItem}
def quantity=(value)
@quantity = BigDecimal.new(value.to_s)
@quantity = BigDecimal((value || 0).to_s)
end

# Sets the price for this {LineItem}
def price=(value)
@price = BigDecimal.new(value.to_s)
@price = BigDecimal((value || 0).to_s)
end
end
end
1 change: 1 addition & 0 deletions lib/payday/money.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Money.locale_backend = :i18n
Money.rounding_mode = BigDecimal::ROUND_HALF_UP
2 changes: 1 addition & 1 deletion lib/payday/pdf_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def self.line_items_table(invoice, pdf)
invoice.line_items.each do |line|
table_data << [line.description,
(line.display_price || number_to_currency(line.price, invoice)),
(line.display_quantity || BigDecimal.new(line.quantity.to_s).to_s("F")),
(line.display_quantity || BigDecimal(line.quantity.to_s).to_s("F")),
number_to_currency(line.amount, invoice)]
end

Expand Down
12 changes: 6 additions & 6 deletions spec/invoice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ module Payday
expect(i.ship_to).to eq("There")
expect(i.notes).to eq("These are some notes.")
expect(i.line_items[0].description).to eq("Shirts")
expect(i.shipping_rate).to eq(BigDecimal.new("15.00"))
expect(i.shipping_rate).to eq(BigDecimal("15.00"))
expect(i.shipping_description).to eq("USPS Priority Mail:")
expect(i.tax_rate).to eq(BigDecimal.new("0.125"))
expect(i.tax_rate).to eq(BigDecimal("0.125"))
expect(i.tax_description).to eq("Local Sales Tax, 12.5%")
expect(i.invoice_date).to eq(Date.civil(1993, 4, 12))
end
Expand All @@ -37,22 +37,22 @@ module Payday
# $1000 in Hats
i.line_items << LineItem.new(price: 5, quantity: 200, description: "Hats")

expect(i.subtotal).to eq(BigDecimal.new("1130"))
expect(i.subtotal).to eq(BigDecimal("1130"))
end

it "should calculate the correct tax rounded to two decimal places" do
i = Invoice.new(tax_rate: 0.1)
i.line_items << LineItem.new(price: 20, quantity: 5, description: "Pants")

expect(i.tax).to eq(BigDecimal.new("10"))
expect(i.tax).to eq(BigDecimal("10"))
end

it "shouldn't apply taxes to invoices with subtotal <= 0" do
i = Invoice.new(tax_rate: 0.1)
i.line_items << LineItem.new(price: -1, quantity: 100,
description: "Negative Priced Pants")

expect(i.tax).to eq(BigDecimal.new("0"))
expect(i.tax).to eq(BigDecimal("0"))
end

it "should calculate the total for an invoice correctly" do
Expand All @@ -68,7 +68,7 @@ module Payday
# $1000 in Hats
i.line_items << LineItem.new(price: 5, quantity: 200, description: "Hats")

expect(i.total).to eq(BigDecimal.new("1243"))
expect(i.total).to eq(BigDecimal("1243"))
end

it "is overdue when it's past date and unpaid" do
Expand Down
8 changes: 4 additions & 4 deletions spec/line_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
module Payday
describe LineItem do
it "should be able to be initilized with a price" do
li = LineItem.new(price: BigDecimal.new("20"))
expect(li.price).to eq(BigDecimal.new("20"))
li = LineItem.new(price: BigDecimal("20"))
expect(li.price).to eq(BigDecimal("20"))
end

it "should be able to be initialized with a quantity" do
li = LineItem.new(quantity: 30)
expect(li.quantity).to eq(BigDecimal.new("30"))
expect(li.quantity).to eq(BigDecimal("30"))
end

it "should be able to be initlialized with a description" do
Expand All @@ -19,7 +19,7 @@ module Payday

it "should return the correct amount" do
li = LineItem.new(price: 10, quantity: 12)
expect(li.amount).to eq(BigDecimal.new("120"))
expect(li.amount).to eq(BigDecimal("120"))
end
end
end

0 comments on commit 702a551

Please sign in to comment.