Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stacks- Kelly Souza Bank Account #38

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a48ccb3
Test 1 passed
kellysouza Feb 21, 2017
f7335b7
Working through spec line 34
kellysouza Feb 21, 2017
01232e2
withdrawal returns new balance
kellysouza Feb 21, 2017
a282d51
withdrawals working
kellysouza Feb 22, 2017
93ad9c6
Wave 1 working through
kellysouza Feb 22, 2017
fa8a55f
updates account methods
kellysouza Feb 22, 2017
2b8cd07
Creates account array
kellysouza Feb 22, 2017
219ee46
account id and balance match
kellysouza Feb 23, 2017
b2790ba
Begin self.find(id) method
kellysouza Feb 23, 2017
70999f7
Find method finds first and last
kellysouza Feb 23, 2017
2b6ea00
Find method: start raise error
kellysouza Feb 23, 2017
8871d02
Add error to .find class method
kellysouza Feb 23, 2017
6542824
add third paramater, timedate, to account initialization
kellysouza Feb 23, 2017
a3a4f68
Cleaning up based on Chris' exapmle
kellysouza Feb 23, 2017
d6c24ec
Cleanup finished
kellysouza Feb 23, 2017
cafbe5c
adds ownerclass #commented out
kellysouza Feb 23, 2017
fd9a233
Set up checking account class and initialize
kellysouza Feb 24, 2017
503a5d0
Add some feature to withraw from checking method
kellysouza Feb 24, 2017
37342d4
Add working withdarawal, begin reset_checks method
kellysouza Feb 24, 2017
cf429e2
reset checks called without error
kellysouza Feb 24, 2017
120e505
reset checks makes three checks free if less than 3 checks
kellysouza Feb 24, 2017
f755ef1
Begin Savings Account
kellysouza Feb 24, 2017
39684b1
Working initialize for savings account
kellysouza Feb 24, 2017
7e3c84a
applies fee with SA withdrawal
kellysouza Feb 24, 2017
af9631d
Adds low balance worning on SA
kellysouza Feb 24, 2017
5d4754d
add @fee to super
kellysouza Feb 25, 2017
2562480
refactoring into super: withdrawal
kellysouza Feb 25, 2017
4bc304a
good through all but last two SA tests
kellysouza Feb 25, 2017
1b474c5
Withdraw complete and passing
kellysouza Feb 25, 2017
d86b66a
Working interest method
kellysouza Feb 25, 2017
dd6ca22
All Workinggit add .
kellysouza Feb 25, 2017
7d255b5
DRYing up code
kellysouza Feb 25, 2017
9393cde
Drying up code
kellysouza Feb 25, 2017
111dcbc
Minor changes
kellysouza Feb 25, 2017
4af2a33
Final(should be)
kellysouza Feb 27, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Final(should be)
kellysouza committed Feb 27, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 4af2a335d22fe9b40b88474d9438181926f4019b
8 changes: 4 additions & 4 deletions lib/account.rb
Original file line number Diff line number Diff line change
@@ -3,11 +3,10 @@
# Learn how Ruby does error handling
# Verify code correctness by testing
require 'csv'
require 'awesome_print'

module Bank
class Account
attr_accessor :id, :balance, :timedate
attr_reader :id, :balance, :timedate

def initialize(id, balance, timedate = nil)
@min_opening_bal = 0
@@ -61,11 +60,12 @@ def adjust_if_no_low_balance(withdrawal_amount)
else
@balance -= (withdrawal_amount + @fee)
end
@balance
@balance
end

def check_for_negative(withdrawal_amount)
raise ArgumentError.new "You cannot withdraw a negative amount" if withdrawal_amount < 0
end
end

end #class account
end # module Bank
13 changes: 7 additions & 6 deletions lib/checking_account.rb
Original file line number Diff line number Diff line change
@@ -16,18 +16,19 @@ def withdraw_using_check(withdrawal_amount)
@fee = 0
check_for_negative(withdrawal_amount)
adjust_if_no_low_balance(withdrawal_amount)
add_checks
charge_fee_if_appropriate(3)
count_check
charge_fee_if_appropriate(3, withdrawal_amount)
end

def charge_fee_if_appropriate(check_limit)
if @number_of_checks > check_limit
def charge_fee_if_appropriate(check_limit, withdrawal_amount)
if @number_of_checks > check_limit && withdrawal_amount < (@balance - @min_bal)
@check_fee = 2
@balance -= @check_fee
end
return @balance - @check_fee
return @balance
end

def add_checks
def count_check
@number_of_checks += 1
end

13 changes: 7 additions & 6 deletions specs/account_spec.rb
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
account.must_respond_to :timedate
account.timedate.must_equal timedate


end

it "Raises an ArgumentError when created with a negative balance" do
@@ -137,10 +138,6 @@
}.must_raise ArgumentError
end
end




end


@@ -155,7 +152,7 @@


it "Returns an array of all accounts" do

@account_array.must_be_instance_of Array

end
# Useful checks might include:
@@ -220,7 +217,11 @@
proc {
Bank::Account.find("0000")
}.must_raise ArgumentError

end
end
describe "Account.find" do
before do @test_array = Bank::Account.all
end
end

end
9 changes: 8 additions & 1 deletion specs/checking_account_spec.rb
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@
# on Account, we effectively get all that testing for free!
# Here we'll only test things that are different.

# TODO: change 'xdescribe' to 'describe' to run these tests
describe "CheckingAccount" do
describe "#initialize" do
# Check that a CheckingAccount is in fact a kind of account
@@ -122,8 +121,16 @@
describe "#reset_checks" do
it "Can be called without error" do
start_balance = 100.0
withdrawal_amount = 10
account = Bank::CheckingAccount.new(1337, start_balance)
updated_balance = account.withdraw_using_check(withdrawal_amount)
updated_balance = account.withdraw_using_check(withdrawal_amount)
updated_balance = account.withdraw_using_check(withdrawal_amount)
updated_balance = account.withdraw_using_check(withdrawal_amount)
updated_balance = account.withdraw_using_check(withdrawal_amount)
account.reset_checks
updated_balance = account.withdraw_using_check(withdrawal_amount)
updated_balance.must_equal 36
end

it "Makes the next three checks free if less than 3 checks had been used" do
6 changes: 1 addition & 5 deletions specs/savings_account_spec.rb
Original file line number Diff line number Diff line change
@@ -57,16 +57,12 @@
describe "#add_interest" do
it "Returns the interest calculated" do
start_balance = 100.0
interest_rate = 2.5
time_in_months = 1
account = Bank::SavingsAccount.new(1337, start_balance)
account.add_interest(interest_rate, time_in_months).must_equal 2.5
account.add_interest(2.5, 1).must_equal 2.5
end

it "Updates the balance with calculated interest" do
start_balance = 100.0
interest_rate = 2.5
time_in_months = 1
account = Bank::SavingsAccount.new(1337, start_balance)
account.add_interest(2.5, 1)
account.balance.must_equal 102.5