Skip to content

Instantly share code, notes, and snippets.

@phillipkoebbe
Created January 22, 2010 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillipkoebbe/283803 to your computer and use it in GitHub Desktop.
Save phillipkoebbe/283803 to your computer and use it in GitHub Desktop.
class Receipt < ActiveRecord::Base
private
def calculate_total
self.total = (self.sub_total || 0.0) + (self.tax_1 || 0.0) + (self.tax_2 || 0.0)
end
end
require 'spec_helper'
describe Receipt do
describe 'calculate_total' do
class Receipt
def test_calculate_total
calculate_total
end
end
it 'should add sub_total, tax_1, and tax_2, assigning the result to total' do
receipt = Receipt.new({
:payee_id => 1,
:category_id => 1,
:transacted_on => '2010-01-01',
:sub_total => 1,
:tax_1 => 1,
:tax_2 => 1
})
receipt.test_calculate_total
receipt.total.should == 3
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment