Created
January 22, 2010 15:00
-
-
Save phillipkoebbe/283803 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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