Skip to content

Commit

Permalink
passes wave 1 tests once more! on to wave 2 errors n failures
Browse files Browse the repository at this point in the history
  • Loading branch information
bcmdarroch committed Feb 23, 2017
1 parent 1c53fba commit 6172874
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 34 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
23 changes: 10 additions & 13 deletions lib/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
43 changes: 24 additions & 19 deletions specs/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6172874

Please sign in to comment.