Skip to content

Commit

Permalink
Add method to calculate order total with tax.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelsey Langlois and LDevinMacKrell committed Dec 7, 2017
1 parent f41b2c4 commit 7dd7fc4
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/models/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ def remove_inventory
item.product.update(quantity: item.product.quantity - item.quantity)
end
end

def total_with_tax
tax_rate = TaxRate.get_tax_rate
(self.price_total * tax_rate) + self.price_total
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion spec/models/order_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

describe Order do
describe Order, vcr: true do
it { should belong_to :account }
it { should validate_presence_of :account }
it { should validate_presence_of :price_total }
Expand Down Expand Up @@ -68,4 +68,10 @@
end
end

describe '#total_with_tax' do
it "returns the total price of the order with Seattle sales tax added" do
order_item = FactoryBot.create(:order_item)
expect(order_item.order.total_with_tax).to eq(order_item.order.price_total * TaxRate.get_tax_rate + order_item.order.price_total)
end
end
end

0 comments on commit 7dd7fc4

Please sign in to comment.