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

Brenna's BankAcccounts #20

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4f85a7a
added proj requirements in comments to account.rb
bcmdarroch Feb 21, 2017
b4984e8
created Bank module, Account class, instance vars @id and @balance, r…
bcmdarroch Feb 21, 2017
0ca3728
raises error if negative balance initialized, added withdrawal method
bcmdarroch Feb 21, 2017
eb692d1
prints warning if withdrawal causes balance to go negative
bcmdarroch Feb 21, 2017
b517f97
prevents user from entering a negative num to withdraw
bcmdarroch Feb 22, 2017
95e2c65
add deposit method
bcmdarroch Feb 22, 2017
809768a
deposit method only accepts positive nums, code meets wave1 requirements
bcmdarroch Feb 22, 2017
97ab4e9
option wave1: created owner class, added owner parameter to account_test
bcmdarroch Feb 22, 2017
add88f2
made tests for owner reader methods
bcmdarroch Feb 22, 2017
34c20f4
uncomment wave 2 requirements
bcmdarroch Feb 22, 2017
355a209
wrote .all method test and self.all stub
bcmdarroch Feb 22, 2017
25b017b
.self method returns an array, passes test 1
bcmdarroch Feb 22, 2017
e6f1b8b
wrote .find test and .find stub
bcmdarroch Feb 22, 2017
1c53fba
implemented csv importation, broke everything <:D
bcmdarroch Feb 22, 2017
6172874
passes wave 1 tests once more! on to wave 2 errors n failures
bcmdarroch Feb 23, 2017
3cfb02b
Merge branch 'master' of https://github.com/bcmdarroch/BankAccounts
bcmdarroch Feb 23, 2017
553ce6d
WIP self.find not working
bcmdarroch Feb 23, 2017
2538f41
passes all testsgit add lib/account.rb wave 2 complete
bcmdarroch Feb 23, 2017
b4b8827
ucommented wave 3 in README
bcmdarroch Feb 23, 2017
a7a4dbc
edited wave 2 code, created savings and checking account stub classes
bcmdarroch Feb 24, 2017
4eb1d95
savings acct cannot have a balance below 10 after initialization or w…
bcmdarroch Feb 24, 2017
c9f6a10
savings has interest method, passes all tests, checking acct has with…
bcmdarroch Feb 24, 2017
38bb277
created withdraw method with fee, withdraw_using_check, passed all te…
bcmdarroch Feb 24, 2017
745df10
added owner spec, tested initialize
bcmdarroch Feb 24, 2017
af4df8e
owners all and find method passed tests
bcmdarroch Feb 25, 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
Next Next commit
passes wave 1 tests once more! on to wave 2 errors n failures
bcmdarroch committed Feb 23, 2017
commit 61728740e5078f1eac297c43b1c8e450a0d48759
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ Make sure to write tests for any optionals you implement!
- Add an `owner` property to each Account to track information about who owns the account.
- The `Account` can be created with an `owner`, OR you can create a method that will add the `owner` after the `Account` has already been created.

<!--


## Wave 2

@@ -110,7 +110,7 @@ To create the relationship between the accounts and the owners use the `account_

This type of table, where records from other tables are associated with each other, is often called a _join table_. We'll talk about them as a class in a few weeks.

-->

<!--

## Wave 3
23 changes: 10 additions & 13 deletions lib/account.rb
Original file line number Diff line number Diff line change
@@ -3,28 +3,25 @@
module Bank

class Account
attr_reader :id, :balance, :date, :owner
attr_reader :id, :balance, :date
attr_accessor :owner

def self.all
all_accounts = []
CSV.open("accounts.csv").each do | line |
acct_data = {}
acct_data[:id] = line[0].to_i
acct_data[:balance] = line[1].to_f
acct_data[:date] = line[2]
all_accounts << Bank::Account.new(acct_data)
CSV.open("/Users/brenna/ada/week3/BankAccounts/support/accounts.csv").each do | line |
all_accounts << Bank::Account.new(line[0].to_i, line[1].to_f, line[2])
end
return all_accounts
all_accounts
end

def self.find(id)
end

def initialize(acct_data, owner = "Customer Name")
raise ArgumentError.new("You cannot create a bank account with a negative balance, you goober.") if acct_data[:balance] >= 0
@idea = acct_data[:id]
@date = acct_data[:date]
@balance = acct_data[:balance]
def initialize(id, balance, date, owner = "Customer Name")
raise ArgumentError.new("You cannot create a bank account with a 0 or negative balance, you goober.") if balance < 0
@id = id
@balance = balance
@date = date
@owner = owner
end

43 changes: 24 additions & 19 deletions specs/account_spec.rb
Original file line number Diff line number Diff line change
@@ -12,45 +12,49 @@
end # remember, end is garbage collector!

describe "Account#initialize" do
it "Takes an ID, an instance of Owner, and an initial balance" do
it "Takes an ID, an initial balance, an open date, and an instance of Owner" do
id = 1337
balance = 100.0
account = Bank::Account.new(id, @brenna, balance)
date = "Jan 1, 2001"
account = Bank::Account.new(id, balance, date, @brenna)

account.must_respond_to :id
account.id.must_equal id

account.must_respond_to :balance
account.balance.must_equal balance

account.must_respond_to :date
account.date.must_equal date

account.must_respond_to :owner
account.owner.must_equal @brenna

account.owner.name.must_equal "Brenna Darroch"
account.owner.address.must_equal "3426 Cotton Top Ct"
account.owner.birthday.must_equal "May 22, 1993"
account.owner.favefood.must_equal "chocolate"

account.must_respond_to :balance
account.balance.must_equal balance
end

it "Raises an ArgumentError when created with a negative balance" do
# Note: we haven't talked about procs yet. You can think of them like blocks that sit by themselves.
# This code checks that, when the proc is executed, it raises an ArgumentError.
proc {
Bank::Account.new(1337, @brenna, -100.0)
Bank::Account.new(1337, -100, "Jan 1, 2001", @brenna)
}.must_raise ArgumentError
end

it "Can be created with a balance of 0" do
# If this raises, the test will fail. No 'must's needed!
Bank::Account.new(1337, @brenna, 0)
Bank::Account.new(1337, 0, "Jan 1, 2001", @brenna)
end
end

describe "Account#withdraw" do
it "Reduces the balance" do
start_balance = 100.0
withdrawal_amount = 25.0
account = Bank::Account.new(1337, @brenna, start_balance)
account = Bank::Account.new(1337, start_balance, "Jan 1, 2001", @brenna)

account.withdraw(withdrawal_amount)

@@ -61,7 +65,7 @@
it "Returns the modified balance" do
start_balance = 100.0
withdrawal_amount = 25.0
account = Bank::Account.new(1337, @brenna, start_balance)
account = Bank::Account.new(1337, start_balance, "Jan 1, 2001", @brenna)

updated_balance = account.withdraw(withdrawal_amount)

@@ -72,7 +76,7 @@
it "Outputs a warning if the account would go negative" do
start_balance = 100.0
withdrawal_amount = 200.0
account = Bank::Account.new(1337, @brenna, start_balance)
account = Bank::Account.new(1337, start_balance, "Jan 1, 2001", @brenna)
# Another proc! This test expects something to be printed to the terminal, using 'must_output'. /.+/ is a regular expression matching one or more characters - as long as anything at all is printed out the test will pass.
proc {
account.withdraw(withdrawal_amount)
@@ -82,7 +86,7 @@
it "Doesn't modify the balance if the account would go negative" do
start_balance = 100.0
withdrawal_amount = 200.0
account = Bank::Account.new(1337, @brenna, start_balance)
account = Bank::Account.new(1337, start_balance, "Jan 1, 2001", @brenna)

updated_balance = account.withdraw(withdrawal_amount)

@@ -93,7 +97,8 @@
end

it "Allows the balance to go to 0" do
account = Bank::Account.new(1337, @brenna, 100.0)
start_balance = 100
account = Bank::Account.new(1337, start_balance, "Jan 1, 2001", @brenna)
updated_balance = account.withdraw(account.balance)
updated_balance.must_equal 0
account.balance.must_equal 0
@@ -102,7 +107,7 @@
it "Requires a positive withdrawal amount" do
start_balance = 100.0
withdrawal_amount = -25.0
account = Bank::Account.new(1337, @brenna, start_balance)
account = Bank::Account.new(1337, start_balance, "Jan 1, 2001", @brenna)

proc {
account.withdraw(withdrawal_amount)
@@ -114,7 +119,7 @@
it "Increases the balance" do
start_balance = 100.0
deposit_amount = 25.0
account = Bank::Account.new(1337, @brenna, start_balance)
account = Bank::Account.new(1337, start_balance, "Jan 1, 2001", @brenna)

account.deposit(deposit_amount)

@@ -125,7 +130,7 @@
it "Returns the modified balance" do
start_balance = 100.0
deposit_amount = 25.0
account = Bank::Account.new(1337, @brenna, start_balance)
account = Bank::Account.new(1337, start_balance, "Jan 1, 2001", @brenna)

updated_balance = account.deposit(deposit_amount)

@@ -136,7 +141,7 @@
it "Requires a positive deposit amount" do
start_balance = 100.0
deposit_amount = -25.0
account = Bank::Account.new(1337, @brenna, start_balance)
account = Bank::Account.new(1337, start_balance, "Jan 1, 2001", @brenna)

proc {
account.deposit(deposit_amount)
@@ -179,15 +184,15 @@

describe "Account.find" do
it "Returns an account that exists" do
Bank::Account.find(1216).must_equal Bank::Account.new(1216, 100022, "2000-07-07 15:07:55 -0800")
Bank::Account.find(1216).must_equal Bank::Account.new(1216, 100022, "2000-07-07 15:07:55 -0800", "Customer Name")
end

it "Can find the first account from the CSV" do
Bank::Account.find.all[0].must_equal Bank::Account.new(1212, 1235667, "1999-03-27 11:30:09 -0800")
Bank::Account.find.all[0].must_equal Bank::Account.new(1212, 1235667, "1999-03-27 11:30:09 -0800", "Customer Name")
end

it "Can find the last account from the CSV" do
Bank::Account.find.all[-1].must_equal Bank::Account.new(15156, 4356772, "1994-11-17 14:04:56 -0800")
Bank::Account.find.all[-1].must_equal Bank::Account.new(15156, 4356772, "1994-11-17 14:04:56 -0800", "Customer Name")
end

it "Raises an error for an account that doesn't exist" do