From d7417a87767dadf1d23ef1ae484a43fa70045a96 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 14:58:58 -0800 Subject: [PATCH 01/74] Created module of Bank, class Account --- lib/account.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/account.rb b/lib/account.rb index e69de29b..76a6127b 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -0,0 +1,4 @@ +module Bank + class Account + end +end From 41b83adb4e5df3613609ee425c4a828830d4aa42 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 15:09:29 -0800 Subject: [PATCH 02/74] Initialize Bank::Account with Id & Balance --- lib/account.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/account.rb b/lib/account.rb index 76a6127b..c087df25 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,4 +1,13 @@ module Bank + class Account + attr_accessor :id, :balance + + def initialize(id, balance) + @id = id + @balance = balance + end + end + end From 196a3ffdd5cce0381e3c6e1613b7eb9ca1804bbf Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 15:20:01 -0800 Subject: [PATCH 03/74] Cannot initialize with Negative Bal --- lib/account.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/account.rb b/lib/account.rb index c087df25..8175c1ac 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -5,7 +5,12 @@ class Account def initialize(id, balance) @id = id - @balance = balance + + if balance >= 0 + @balance = balance + else + raise ArgumentError.new "You cannot initialize a new account with a negative balance." + end end end From 5dfdf17669e7738bc322392895c350b94ac3745d Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 15:21:56 -0800 Subject: [PATCH 04/74] Creating method withdraw for class Account --- lib/account.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/account.rb b/lib/account.rb index 8175c1ac..6bee8ca5 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -11,6 +11,11 @@ def initialize(id, balance) else raise ArgumentError.new "You cannot initialize a new account with a negative balance." end + + def withdraw + + end + end end From 038cea735bdc44f20ae27b1185b23ea3250ffe9c Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 15:25:33 -0800 Subject: [PATCH 05/74] withdrawl returns updated balance --- lib/account.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 6bee8ca5..afce9224 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -12,8 +12,8 @@ def initialize(id, balance) raise ArgumentError.new "You cannot initialize a new account with a negative balance." end - def withdraw - + def withdraw(withdrawal_amount) + @balance -= withdrawal_amount end end From 6fbb0bec609856070bf74297b207f6167b40b0be Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 15:34:25 -0800 Subject: [PATCH 06/74] Outputs an error if balance is going negative. --- lib/account.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/account.rb b/lib/account.rb index afce9224..bc467198 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -13,9 +13,13 @@ def initialize(id, balance) end def withdraw(withdrawal_amount) + if withdrawal_amount > @balance + puts "You are going negative." + end @balance -= withdrawal_amount end + end end From ecb4b4e284aebab78d91bada8f6262bd26397eff Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 15:38:29 -0800 Subject: [PATCH 07/74] Doesn't modify balance if withdrawl would make it go negative. --- lib/account.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index bc467198..030702b5 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -13,10 +13,12 @@ def initialize(id, balance) end def withdraw(withdrawal_amount) - if withdrawal_amount > @balance + if withdrawal_amount < @balance + @balance -= withdrawal_amount + else puts "You are going negative." + @balance = balance end - @balance -= withdrawal_amount end From 2a47fc2c8661ac3cdba43e71183a493142324854 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 15:39:43 -0800 Subject: [PATCH 08/74] Allows withdrawal ammount to = balance, taking balance to 0. --- lib/account.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/account.rb b/lib/account.rb index 030702b5..1e7b8be0 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -13,7 +13,7 @@ def initialize(id, balance) end def withdraw(withdrawal_amount) - if withdrawal_amount < @balance + if withdrawal_amount <= @balance @balance -= withdrawal_amount else puts "You are going negative." From f2a4678f07c20b89fcdda890bf06ad37d161e191 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 15:43:33 -0800 Subject: [PATCH 09/74] withdrawal must be > 0 --- lib/account.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 1e7b8be0..13d64b43 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -13,11 +13,15 @@ def initialize(id, balance) end def withdraw(withdrawal_amount) - if withdrawal_amount <= @balance - @balance -= withdrawal_amount + if withdrawal_amount >= 0 + if withdrawal_amount <= @balance + @balance -= withdrawal_amount + else + puts "You are going negative." + @balance = balance + end else - puts "You are going negative." - @balance = balance + raise ArgumentError.new "Your withdrawal amount must be positive." end end From a8c0232cd8b1114e651bd4a0439eb38d4cc37a50 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 15:45:00 -0800 Subject: [PATCH 10/74] Add deposit method --- lib/account.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/account.rb b/lib/account.rb index 13d64b43..f2b7214b 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -13,7 +13,7 @@ def initialize(id, balance) end def withdraw(withdrawal_amount) - if withdrawal_amount >= 0 + if withdrawal_amount > 0 if withdrawal_amount <= @balance @balance -= withdrawal_amount else @@ -25,6 +25,9 @@ def withdraw(withdrawal_amount) end end + def deposit(deposit_amount) + + end end From 24340628a99d0b8752029bf04492ff6ea44e27a9 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 15:46:03 -0800 Subject: [PATCH 11/74] deposit adds to balance --- lib/account.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/account.rb b/lib/account.rb index f2b7214b..0b2df864 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -26,7 +26,7 @@ def withdraw(withdrawal_amount) end def deposit(deposit_amount) - + @balance += deposit_amount end end From c8807a37d23d194a0085df51fe6c1ca8c42c719b Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 15:52:07 -0800 Subject: [PATCH 12/74] Raise argument if deposit is not positive --- lib/account.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/account.rb b/lib/account.rb index 0b2df864..2ca8fe14 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -26,7 +26,11 @@ def withdraw(withdrawal_amount) end def deposit(deposit_amount) - @balance += deposit_amount + if deposit_amount > 0 + @balance += deposit_amount + else + raise ArgumentError.new "Your deposit must be greater than zero." + end end end From c40d49bd143f6ffc6f1c2947d8247f27b57d2f62 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 15:57:52 -0800 Subject: [PATCH 13/74] Add Owner class --- lib/account.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/account.rb b/lib/account.rb index 2ca8fe14..cd18cadf 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -37,4 +37,7 @@ def deposit(deposit_amount) end + class Owner + end + end From 8cc445031ab1c81479b191db38e976280bdd88de Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 16:04:08 -0800 Subject: [PATCH 14/74] Adding test to make sure Owner can be initialized --- specs/account_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 6c399139..c9eeec91 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -4,6 +4,14 @@ require_relative '../lib/account' describe "Wave 1" do + #writing my own test + describe "Owner initialize" do + it "Takes Name and Phone # to initialize Owner" do + name = "Lynn Trickey" + phone = "206-240-1029" + new_owner = Bank::Owner.new(name, phone) + end + end describe "Account#initialize" do it "Takes an ID and an initial balance" do id = 1337 From 7d7aec98716f56ac01fe862afe7bc19dae38a134 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 16:06:08 -0800 Subject: [PATCH 15/74] initialize class Owner with Name and Phone Number --- lib/account.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/account.rb b/lib/account.rb index cd18cadf..3f2e2eda 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -38,6 +38,12 @@ def deposit(deposit_amount) end class Owner + + def initialize(name, phone) + name = name + phone = phone + end + end - + end From fe8c680bae9713919938e8e16f4ac67cede5f10e Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 16:10:01 -0800 Subject: [PATCH 16/74] Updated test and account to make sure Owner responded to name and phone methods --- lib/account.rb | 3 ++- specs/account_spec.rb | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/account.rb b/lib/account.rb index 3f2e2eda..3e40ee0d 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -38,7 +38,8 @@ def deposit(deposit_amount) end class Owner - + attr_reader :name, :phone + def initialize(name, phone) name = name phone = phone diff --git a/specs/account_spec.rb b/specs/account_spec.rb index c9eeec91..c4568fc0 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -10,6 +10,10 @@ name = "Lynn Trickey" phone = "206-240-1029" new_owner = Bank::Owner.new(name, phone) + + new_owner.must_respond_to :name + new_owner.must_respond_to :phone + end end describe "Account#initialize" do From a871c201865ebceea828795b81d57c41dfa9066f Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 16:24:36 -0800 Subject: [PATCH 17/74] Starting a test to check if a new Owner can be assigned to an Account --- lib/account.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/account.rb b/lib/account.rb index 3e40ee0d..d49756e7 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -18,7 +18,7 @@ def withdraw(withdrawal_amount) @balance -= withdrawal_amount else puts "You are going negative." - @balance = balance + @balance end else raise ArgumentError.new "Your withdrawal amount must be positive." From d6ea6ef184d91bf413ea4afd00da3bfb5d4b747b Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 16:31:52 -0800 Subject: [PATCH 18/74] Added @owner attribute to Account class. Tested that it is accessible --- lib/account.rb | 6 +++++- specs/account_spec.rb | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index d49756e7..c331ba53 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,7 +1,7 @@ module Bank class Account - attr_accessor :id, :balance + attr_accessor :id, :balance, :owner def initialize(id, balance) @id = id @@ -12,6 +12,10 @@ def initialize(id, balance) raise ArgumentError.new "You cannot initialize a new account with a negative balance." end + def add_owner(owner) + @owner = owner + end + def withdraw(withdrawal_amount) if withdrawal_amount > 0 if withdrawal_amount <= @balance diff --git a/specs/account_spec.rb b/specs/account_spec.rb index c4568fc0..d617c929 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -5,7 +5,7 @@ describe "Wave 1" do #writing my own test - describe "Owner initialize" do + describe "Owner#initialize" do it "Takes Name and Phone # to initialize Owner" do name = "Lynn Trickey" phone = "206-240-1029" @@ -13,8 +13,7 @@ new_owner.must_respond_to :name new_owner.must_respond_to :phone - - end + end end describe "Account#initialize" do it "Takes an ID and an initial balance" do @@ -45,6 +44,16 @@ end end + describe "Account#add_owner" do + it "Adds an Owner instance and saves it as an instance variable" do + account = Bank::Account.new(1337, 10) + + name = "Lynn" + account.add_owner(name) + account.owner.must_equal name + end + end + describe "Account#withdraw" do it "Reduces the balance" do start_balance = 100.0 From 0de7ef11676236c9f4fefd57d0ae16bc57b91e3d Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 16:38:31 -0800 Subject: [PATCH 19/74] Adding owner of object Owner, modifying test to reflect --- specs/account_spec.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index d617c929..b35dcbd1 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -48,9 +48,14 @@ it "Adds an Owner instance and saves it as an instance variable" do account = Bank::Account.new(1337, 10) - name = "Lynn" - account.add_owner(name) - account.owner.must_equal name + lynn = Bank::Owner.new("Lynn Trickey", "555-555-5555") + + account.add_owner(lynn) + account.owner.must_equal lynn + end + + it "Owner must be class Owner" do + end end From 5a31f077a2501eb1c788439ff52882fdd619eb73 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 16:54:44 -0800 Subject: [PATCH 20/74] Create test to check that owner parameter when calling add_owner on an Account must be type Owner. --- specs/account_spec.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index b35dcbd1..fbf68545 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -45,17 +45,18 @@ end describe "Account#add_owner" do + before do + @account = Bank::Account.new(1337, 10) + @lynn = Bank::Owner.new("Lynn Trickey", "555-555-5555") + end it "Adds an Owner instance and saves it as an instance variable" do - account = Bank::Account.new(1337, 10) - - lynn = Bank::Owner.new("Lynn Trickey", "555-555-5555") - - account.add_owner(lynn) - account.owner.must_equal lynn + @account.add_owner(@lynn) + @account.owner.must_equal @lynn end - it "Owner must be class Owner" do - + it "Raises an Argument when add_owner is called and the owner argument is not class Owner" do + #Shoulr raise error + proc { @account.add_owner("not class Owner") }.must_raise ArgumentError end end From ce6f236a1d0346e49e356f408f9fda27fdb4f66e Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Tue, 21 Feb 2017 16:57:35 -0800 Subject: [PATCH 21/74] owner parameter must be class Owner when calling add_owner on Account class --- lib/account.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index c331ba53..f46d6a50 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,7 +1,8 @@ module Bank class Account - attr_accessor :id, :balance, :owner + attr_accessor :balance, :owner + attr_reader :id def initialize(id, balance) @id = id @@ -13,7 +14,11 @@ def initialize(id, balance) end def add_owner(owner) - @owner = owner + if owner.class == Owner + @owner = owner + else + raise ArgumentError.new "You must add a class type of Owner." + end end def withdraw(withdrawal_amount) From d8b8b00bd42bfd737f4ef4b917bd6a240b70109b Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Wed, 22 Feb 2017 14:16:27 -0800 Subject: [PATCH 22/74] Adding stubs of .all class method for Account --- lib/account.rb | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index f46d6a50..1d32d058 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -4,42 +4,51 @@ class Account attr_accessor :balance, :owner attr_reader :id + def self.all + + end + def initialize(id, balance) + @id = id - if balance >= 0 - @balance = balance - else + if balance < 0 raise ArgumentError.new "You cannot initialize a new account with a negative balance." + else + @balance = balance end def add_owner(owner) + if owner.class == Owner @owner = owner else raise ArgumentError.new "You must add a class type of Owner." end + end def withdraw(withdrawal_amount) - if withdrawal_amount > 0 - if withdrawal_amount <= @balance - @balance -= withdrawal_amount - else - puts "You are going negative." - @balance - end - else - raise ArgumentError.new "Your withdrawal amount must be positive." - end + + raise ArgumentError.new("Withdrawal must be >=0") if withdrawal_amount < 0 + + if @balance - withdrawal_amount < 0 + puts "You are going negative." + return @balance + else + @balance -= withdrawal_amount + end + end def deposit(deposit_amount) - if deposit_amount > 0 - @balance += deposit_amount - else - raise ArgumentError.new "Your deposit must be greater than zero." - end + + if deposit_amount > 0 + @balance += deposit_amount + else + raise ArgumentError.new "Your deposit must be greater than zero." + end + end end From cdc812f74bcaf194044744ed68b60ae41077095f Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Wed, 22 Feb 2017 14:21:22 -0800 Subject: [PATCH 23/74] change account.initialize to take in third parameter of opendate --- lib/account.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 1d32d058..9a9aafba 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -5,12 +5,13 @@ class Account attr_reader :id def self.all - + end - def initialize(id, balance) + def initialize(id, balance, opendate) @id = id + @opendate = opendate if balance < 0 raise ArgumentError.new "You cannot initialize a new account with a negative balance." @@ -66,3 +67,7 @@ def initialize(name, phone) end end + +my_account = Bank::Account.new(1212,1235667,"1999-03-27 11:30:09 -0800") + +puts my_account.balance From b4037b32d20367ec597edb73560ed5f67eff9879 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Wed, 22 Feb 2017 14:45:19 -0800 Subject: [PATCH 24/74] Modifying specs to work with new three parameters required to initialize instance of Account --- specs/account_spec.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index fbf68545..09207a83 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -40,7 +40,7 @@ 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, 0) + Bank::Account.new(1337, 0, "opendate") end end @@ -55,7 +55,7 @@ end it "Raises an Argument when add_owner is called and the owner argument is not class Owner" do - #Shoulr raise error + #Should raise error proc { @account.add_owner("not class Owner") }.must_raise ArgumentError end end @@ -64,7 +64,7 @@ it "Reduces the balance" do start_balance = 100.0 withdrawal_amount = 25.0 - account = Bank::Account.new(1337, start_balance) + account = Bank::Account.new(1337, start_balance,) account.withdraw(withdrawal_amount) @@ -163,11 +163,13 @@ end end -# TODO: change 'xdescribe' to 'describe' to run these tests -xdescribe "Wave 2" do +# todo: change 'xdescribe' to 'describe' to run these tests +describe "Wave 2" do describe "Account.all" do it "Returns an array of all accounts" do - # TODO: Your test code here! + + Account.all.class.must_be (Array) + # Useful checks might include: # - Account.all returns an array # - Everything in the array is an Account From 5010f43df74abe7ba7736b501be196e8eff4722a Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Wed, 22 Feb 2017 14:46:02 -0800 Subject: [PATCH 25/74] Change default initial value of datetime to nodate so tests still work --- lib/account.rb | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 9a9aafba..cf2bb2a0 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,15 +1,12 @@ +require 'csv' + module Bank class Account attr_accessor :balance, :owner attr_reader :id - def self.all - - end - - def initialize(id, balance, opendate) - + def initialize(id, balance, opendate = "nodate") @id = id @opendate = opendate @@ -18,19 +15,25 @@ def initialize(id, balance, opendate) else @balance = balance end + end - def add_owner(owner) - - if owner.class == Owner - @owner = owner - else - raise ArgumentError.new "You must add a class type of Owner." - end - + def self.all + accounts = [] + CSV.open("support/accounts.csv").each do |account| + accounts << Bank::Account.new(account[0].to_i, account[1].to_i, account[2].to_s) end + accounts + end - def withdraw(withdrawal_amount) + def add_owner(owner) + if owner.class == Owner + @owner = owner + else + raise ArgumentError.new "You must add a class type of Owner." + end + end + def withdraw(withdrawal_amount) raise ArgumentError.new("Withdrawal must be >=0") if withdrawal_amount < 0 if @balance - withdrawal_amount < 0 @@ -39,19 +42,14 @@ def withdraw(withdrawal_amount) else @balance -= withdrawal_amount end + end - end - - def deposit(deposit_amount) - + def deposit(deposit_amount) if deposit_amount > 0 @balance += deposit_amount else raise ArgumentError.new "Your deposit must be greater than zero." end - - end - end end @@ -68,6 +66,8 @@ def initialize(name, phone) end -my_account = Bank::Account.new(1212,1235667,"1999-03-27 11:30:09 -0800") +# my_account = Bank::Account.new(1212,1235667,"1999-03-27 11:30:09 -0800") +# +# puts my_account.balance -puts my_account.balance +puts Bank::Account.all From 5d11fbe5900fc52ab29e462d2840658faad8d54c Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Wed, 22 Feb 2017 14:56:14 -0800 Subject: [PATCH 26/74] wrote test to verify .add returns array --- lib/account.rb | 4 ++-- specs/account_spec.rb | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index cf2bb2a0..204f3f7a 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -22,7 +22,7 @@ def self.all CSV.open("support/accounts.csv").each do |account| accounts << Bank::Account.new(account[0].to_i, account[1].to_i, account[2].to_s) end - accounts + return accounts end def add_owner(owner) @@ -70,4 +70,4 @@ def initialize(name, phone) # # puts my_account.balance -puts Bank::Account.all +puts " #{ Bank::Account.all.class } " diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 09207a83..61038ad6 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -168,8 +168,10 @@ describe "Account.all" do it "Returns an array of all accounts" do - Account.all.class.must_be (Array) + new_bank = Bank::Account.all + new_bank.class.must_equal(Array) + end # Useful checks might include: # - Account.all returns an array # - Everything in the array is an Account @@ -177,7 +179,7 @@ # - The ID and balance of the first and last # accounts match what's in the CSV file # Feel free to split this into multiple tests if needed - end + end describe "Account.find" do From 912cf0db06fe6d8854da58cd58340445cc791264 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Wed, 22 Feb 2017 15:01:45 -0800 Subject: [PATCH 27/74] adding before do block to Account.all test portion --- specs/account_spec.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 61038ad6..5950af97 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -166,10 +166,15 @@ # todo: change 'xdescribe' to 'describe' to run these tests describe "Wave 2" do describe "Account.all" do - it "Returns an array of all accounts" do - + before do new_bank = Bank::Account.all + end + + it "Returns an array of all accounts" do new_bank.class.must_equal(Array) + end + + it "Verifies everything in array is an Account" end # Useful checks might include: From 38abc1b63f778b5eeaaca514b26769e9ff50e7e2 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Wed, 22 Feb 2017 15:05:52 -0800 Subject: [PATCH 28/74] created test to verify that every item in array returned with .all method is a class Bank::Account --- lib/account.rb | 2 +- specs/account_spec.rb | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 204f3f7a..35e278c4 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -20,7 +20,7 @@ def initialize(id, balance, opendate = "nodate") def self.all accounts = [] CSV.open("support/accounts.csv").each do |account| - accounts << Bank::Account.new(account[0].to_i, account[1].to_i, account[2].to_s) + accounts << Bank::Account.new(account[0].to_i, account[1].to_i, account[2]) end return accounts end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 5950af97..afa15a16 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -94,7 +94,7 @@ # anything at all is printed out the test will pass. proc { account.withdraw(withdrawal_amount) - }.must_output /.+/ + }.must_output(/.+/) end it "Doesn't modify the balance if the account would go negative" do @@ -166,16 +166,19 @@ # todo: change 'xdescribe' to 'describe' to run these tests describe "Wave 2" do describe "Account.all" do + before do - new_bank = Bank::Account.all + @new_bank = Bank::Account.all end it "Returns an array of all accounts" do - new_bank.class.must_equal(Array) + @new_bank.class.must_equal(Array) end - it "Verifies everything in array is an Account" - + it "Verifies every item in array is an Account" do + @new_bank.each do |item| + item.class.must_equal(Bank::Account) + end end # Useful checks might include: # - Account.all returns an array @@ -204,4 +207,5 @@ # TODO: Your test code here! end end + end From b9c04aaf31effdf5f459af08bd8d1421e20bd0e6 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Wed, 22 Feb 2017 15:33:00 -0800 Subject: [PATCH 29/74] completed test that made sure first id in CSV matched first id in .all method --- specs/account_spec.rb | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index afa15a16..e852b152 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -179,11 +179,33 @@ @new_bank.each do |item| item.class.must_equal(Bank::Account) end + end + + it "The number of accounts matches lines in CSV file, so number of accounts is correct" do + + csv_lines = 0 + #iterating through CSV & counting the number of lines + CSV.open("support/accounts.csv").each do |line| + csv_lines += 1 + end + + @new_bank.length.must_equal(csv_lines) + end + + it "ID and balance of first & last account matches ID and balance in CSV" do + + ids = [] + balances = [] + CSV.open("support/accounts.csv").each do |line| + ids << line[0].to_i + balances << line[1].to_i + end + + @new_bank[0].id.must_equal(ids[0]) + @new_bank[-1].id.must_equal(ids[-1]) + end # Useful checks might include: - # - Account.all returns an array - # - Everything in the array is an Account - # - The number of accounts is correct # - The ID and balance of the first and last # accounts match what's in the CSV file # Feel free to split this into multiple tests if needed From efe448e0caea1da3a4c212b2ada1558850f65812 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Wed, 22 Feb 2017 15:35:36 -0800 Subject: [PATCH 30/74] added check balance to last spec --- specs/account_spec.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index e852b152..211b1930 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -193,7 +193,6 @@ end it "ID and balance of first & last account matches ID and balance in CSV" do - ids = [] balances = [] CSV.open("support/accounts.csv").each do |line| @@ -201,14 +200,14 @@ balances << line[1].to_i end + #checks first and last ids @new_bank[0].id.must_equal(ids[0]) @new_bank[-1].id.must_equal(ids[-1]) + #checks first and last balances + @new_bank[0].balance.must_equal(balances[0]) + @new_bank[-1].balance.must_equal(balances[-1]) end - # Useful checks might include: - # - The ID and balance of the first and last - # accounts match what's in the CSV file - # Feel free to split this into multiple tests if needed end From aeaa3a2eb0fdebadcd26fe6ef16efa84f7629891 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Wed, 22 Feb 2017 15:43:25 -0800 Subject: [PATCH 31/74] created test to return an existing account class account --- lib/account.rb | 4 ++++ specs/account_spec.rb | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/account.rb b/lib/account.rb index 35e278c4..2e5a9cdd 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -25,6 +25,10 @@ def self.all return accounts end + def self.find() + + end + def add_owner(owner) if owner.class == Owner @owner = owner diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 211b1930..7c22dc5d 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -15,6 +15,7 @@ new_owner.must_respond_to :phone end end + describe "Account#initialize" do it "Takes an ID and an initial balance" do id = 1337 @@ -213,7 +214,8 @@ describe "Account.find" do it "Returns an account that exists" do - # TODO: Your test code here! + first_account = Bank::Account.find(1212) + first_account.class.must_equal(Account) end it "Can find the first account from the CSV" do From 393e1f6590f5ffb08577787f4dd896dd5bcccb14 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Wed, 22 Feb 2017 16:01:05 -0800 Subject: [PATCH 32/74] Create Self method to return object of account when specific id is called. --- lib/account.rb | 10 ++++++++-- specs/account_spec.rb | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 2e5a9cdd..b30f4506 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -25,8 +25,14 @@ def self.all return accounts end - def self.find() - + def self.find(id) + @account = nil + CSV.open("support/accounts.csv").each do |line| + if line[0].to_i == id + @account = Bank::Account.new(line[0].to_i, line[1].to_i, line[2]) + end + end + return @account end def add_owner(owner) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 7c22dc5d..80e460f4 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -215,7 +215,7 @@ describe "Account.find" do it "Returns an account that exists" do first_account = Bank::Account.find(1212) - first_account.class.must_equal(Account) + first_account.class.must_equal(Bank::Account) end it "Can find the first account from the CSV" do From 216b8ca2e5d9014ffbdf32f3732a012d6b38669d Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Wed, 22 Feb 2017 16:07:45 -0800 Subject: [PATCH 33/74] created and passed tests for finding first and last account from CSV --- lib/account.rb | 3 +-- specs/account_spec.rb | 14 +++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index b30f4506..74e5764b 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -19,6 +19,7 @@ def initialize(id, balance, opendate = "nodate") def self.all accounts = [] + CSV.open("support/accounts.csv").each do |account| accounts << Bank::Account.new(account[0].to_i, account[1].to_i, account[2]) end @@ -66,12 +67,10 @@ def deposit(deposit_amount) class Owner attr_reader :name, :phone - def initialize(name, phone) name = name phone = phone end - end end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 80e460f4..cfb76c81 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -214,20 +214,20 @@ describe "Account.find" do it "Returns an account that exists" do - first_account = Bank::Account.find(1212) - first_account.class.must_equal(Bank::Account) + account = Bank::Account.find(15151) + account.class.must_equal(Bank::Account) end it "Can find the first account from the CSV" do - # TODO: Your test code here! + Bank::Account.find(1212) end it "Can find the last account from the CSV" do - # TODO: Your test code here! + Bank::Account.find(15156) end - - it "Raises an error for an account that doesn't exist" do - # TODO: Your test code here! + # not yet working + # it "Raises an error for an account that doesn't exist" do + # Bank::Account.find(0000000) end end From 0aa8c6701f1777a06d31df875f6c8ff28891ac06 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Wed, 22 Feb 2017 16:13:14 -0800 Subject: [PATCH 34/74] edited .find class method to raise error if searching for id that does not exist. created & passed test. --- lib/account.rb | 7 ++++++- specs/account_spec.rb | 9 ++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 74e5764b..a16a8a14 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -33,7 +33,12 @@ def self.find(id) @account = Bank::Account.new(line[0].to_i, line[1].to_i, line[2]) end end - return @account + + if @account == nil + raise ArgumentError.new "This account doee not exist!" + else + return @account + end end def add_owner(owner) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index cfb76c81..3c0240ec 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -225,9 +225,12 @@ it "Can find the last account from the CSV" do Bank::Account.find(15156) end - # not yet working - # it "Raises an error for an account that doesn't exist" do - # Bank::Account.find(0000000) + + it "Raises an error for an account that doesn't exist" do + #should raise an error when I try to find this + proc { + Bank::Account.find(0000000) + }.must_raise ArgumentError end end From 55ab30c87aa91d67d495901082ec70632e90bad1 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Wed, 22 Feb 2017 16:27:36 -0800 Subject: [PATCH 35/74] updating Owner class to take inputs available in CSV file --- lib/account.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index a16a8a14..370b2520 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -71,11 +71,17 @@ def deposit(deposit_amount) end class Owner - attr_reader :name, :phone - def initialize(name, phone) - name = name - phone = phone + attr_reader :last_name, :first_name + + def initialize(id, last_name, first_name, street_address, city, state) + id = id + @last_name = last_name + @first_name = first_name + street_address = street_address + city = city + state = state end + end end From 7aedbd88117b101b532f469fc8a03a01c2a3eb5e Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Wed, 22 Feb 2017 16:47:09 -0800 Subject: [PATCH 36/74] Updated Owner class to have default values of nil, wrote test for Owner class --- lib/account.rb | 2 +- specs/account_spec.rb | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 370b2520..2ecb1db0 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -73,7 +73,7 @@ def deposit(deposit_amount) class Owner attr_reader :last_name, :first_name - def initialize(id, last_name, first_name, street_address, city, state) + def initialize(id = nil, last_name = nil, first_name = nil, street_address = nil, city = nil, state = nil) id = id @last_name = last_name @first_name = first_name diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 3c0240ec..844d5c47 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -7,12 +7,13 @@ #writing my own test describe "Owner#initialize" do it "Takes Name and Phone # to initialize Owner" do - name = "Lynn Trickey" - phone = "206-240-1029" - new_owner = Bank::Owner.new(name, phone) + last_name = "Trickey" + first_name = "lynn" - new_owner.must_respond_to :name - new_owner.must_respond_to :phone + new_owner = Bank::Owner.new(last_name, first_name) + + new_owner.must_respond_to :last_name + new_owner.must_respond_to :first_name end end @@ -166,6 +167,16 @@ # todo: change 'xdescribe' to 'describe' to run these tests describe "Wave 2" do + + describe "Testing Owner class methods" do + + it "Returns an array of Owner instances" do + all_owners = Bank::Owner.all + all_owners.must_be_instance_of(Bank::Owner) + end + + end + describe "Account.all" do before do @@ -215,7 +226,7 @@ describe "Account.find" do it "Returns an account that exists" do account = Bank::Account.find(15151) - account.class.must_equal(Bank::Account) + account.must_be_instance_of(Bank::Account) end it "Can find the first account from the CSV" do @@ -232,6 +243,7 @@ Bank::Account.find(0000000) }.must_raise ArgumentError end + end end From e567bd6fb06d434c3428377362ea8816faaf3240 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Wed, 22 Feb 2017 16:55:02 -0800 Subject: [PATCH 37/74] Created and passed test to verify Owner class method .all returns array. --- lib/account.rb | 8 ++++++++ specs/account_spec.rb | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 2ecb1db0..bb6a4071 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -82,6 +82,14 @@ def initialize(id = nil, last_name = nil, first_name = nil, street_address = nil state = state end + def self.all + owners = [] + CSV.open("support/owners.csv").each do |owner| + owners << Bank::Owner.new(owner[0].to_i, owner[1], owner[2], owner[3], owner[4], owner[5]) + end + return owners + end + end end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 844d5c47..0b13800e 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -169,10 +169,16 @@ describe "Wave 2" do describe "Testing Owner class methods" do + before do + @all_owners = Bank::Owner.all + end it "Returns an array of Owner instances" do - all_owners = Bank::Owner.all - all_owners.must_be_instance_of(Bank::Owner) + @all_owners.must_be_instance_of(Array) + end + + it "Verifies every item in array is an Owner" do + end end From d1ed52a8235fe39b10f05ce2b383cd4774208d1a Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Wed, 22 Feb 2017 16:56:40 -0800 Subject: [PATCH 38/74] Added stumps for further .all tests --- specs/account_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 0b13800e..b4740541 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -178,6 +178,14 @@ end it "Verifies every item in array is an Owner" do + + end + + it "Number of Owners match lines in CSV file" do + + end + + it "Name and address of first and last match CSV file" do end From 3638954399a257a2c08a3dbc273599990deefa40 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Wed, 22 Feb 2017 17:12:03 -0800 Subject: [PATCH 39/74] updating Owner tests. Working through line 208 which is commented out. All else working. --- lib/account.rb | 4 ++-- specs/account_spec.rb | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index bb6a4071..fa0396b9 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -71,13 +71,13 @@ def deposit(deposit_amount) end class Owner - attr_reader :last_name, :first_name + attr_reader :last_name, :first_name, :street_address def initialize(id = nil, last_name = nil, first_name = nil, street_address = nil, city = nil, state = nil) id = id @last_name = last_name @first_name = first_name - street_address = street_address + @street_address = street_address city = city state = state end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index b4740541..fb6f3c2c 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -178,15 +178,37 @@ end it "Verifies every item in array is an Owner" do - + @all_owners.each do |item| + item.class.must_equal(Bank::Owner) + end end it "Number of Owners match lines in CSV file" do + csv_lines = 0 + #iterating through CSV & counting the number of lines + CSV.open("support/owners.csv").each do |line| + csv_lines += 1 + end + @all_owners.length.must_equal(csv_lines) end it "Name and address of first and last match CSV file" do - + first_names = [] + street_addresses = [] + CSV.open("support/owners.csv").each do |line| + first_names << line[2] + street_addresses << line[3] + end + + #checks first and last first_names + @all_owners[0].first_name.must_equal(first_names[0]) + @all_owners[-1].first_name.must_equal(first_names[-1]) + + # #checks first and last balances + # @new_bank[0].balance.must_equal(balances[0]) + # @new_bank[-1].balance.must_equal(balances[-1]) + end end From fc909b2cd2c8e5147ceaa5e37a252c7de3fe5134 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Wed, 22 Feb 2017 21:09:59 -0800 Subject: [PATCH 40/74] add test to check first and last street_address & pass --- specs/account_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index fb6f3c2c..1920daeb 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -205,9 +205,9 @@ @all_owners[0].first_name.must_equal(first_names[0]) @all_owners[-1].first_name.must_equal(first_names[-1]) - # #checks first and last balances - # @new_bank[0].balance.must_equal(balances[0]) - # @new_bank[-1].balance.must_equal(balances[-1]) + #checks first and last street_addresses + @all_owners[0].first_name.must_equal(first_names[0]) + @all_owners[-1].first_name.must_equal(first_names[-1]) end From 31adb29830a33061c4a61ef2e9f542d967487fa7 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 08:34:23 -0800 Subject: [PATCH 41/74] added .find(id) class method for Owner & test --- lib/account.rb | 10 +++++++++- specs/account_spec.rb | 9 ++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index fa0396b9..2217d621 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -90,8 +90,16 @@ def self.all return owners end + def self.find(id) + @owner = nil + CSV.open("support/owners.csv").each do |owner| + if owner[0].to_i == id + @owner = Bank::Owner.new(owner[0].to_i, owner[1], owner[2], owner[3], owner[4], owner[5]) + end + end + return @owner + end end - end # my_account = Bank::Account.new(1212,1235667,"1999-03-27 11:30:09 -0800") diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 1920daeb..6737f888 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -165,7 +165,7 @@ end end -# todo: change 'xdescribe' to 'describe' to run these tests +#Wave 2 describe "Wave 2" do describe "Testing Owner class methods" do @@ -213,6 +213,13 @@ end + describe "Testing Owner.find" do + it "Returns an account that exists" do + account = Bank::Owner.find(14) + account.must_be_instance_of(Bank::Owner) + end + end + describe "Account.all" do before do From 158f63286a3375d727ca5fcf305bf0de609a8b3c Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 08:41:38 -0800 Subject: [PATCH 42/74] Adding argument error if Owner ID does not exist for Owner.find. Created & passed test --- lib/account.rb | 9 ++++++++- specs/account_spec.rb | 19 +++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 2217d621..92ea6645 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -97,9 +97,16 @@ def self.find(id) @owner = Bank::Owner.new(owner[0].to_i, owner[1], owner[2], owner[3], owner[4], owner[5]) end end - return @owner + + if @owner == nil + raise ArgumentError.new "This owner does not exist!" + else + return @owner + end end + end + end # my_account = Bank::Account.new(1212,1235667,"1999-03-27 11:30:09 -0800") diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 6737f888..ef6438b5 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -214,10 +214,25 @@ end describe "Testing Owner.find" do + it "Returns an account that exists" do - account = Bank::Owner.find(14) - account.must_be_instance_of(Bank::Owner) + owner = Bank::Owner.find(14) + owner.must_be_instance_of(Bank::Owner) + end + + it "Can find the first account from the CSV" do + Bank::Owner.find(14) end + + it "Can find the last account from the CSV" do + Bank::Owner.find(25) + end + + it "Raises an error for an Owner that doesn't exist" do + #should raise an error when I try to find this + proc { Bank::Owner.find(0000000) }.must_raise ArgumentError + end + end describe "Account.all" do From f311fbfceb90de687042055cc8983a0819f37581 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 10:38:35 -0800 Subject: [PATCH 43/74] Calling .length on CSV read file instead of creating variable to count the length - clean up --- specs/account_spec.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index ef6438b5..fdfce70c 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -184,11 +184,7 @@ end it "Number of Owners match lines in CSV file" do - csv_lines = 0 - #iterating through CSV & counting the number of lines - CSV.open("support/owners.csv").each do |line| - csv_lines += 1 - end + csv_lines = CSV.read("support/owners.csv").length @all_owners.length.must_equal(csv_lines) end @@ -253,11 +249,7 @@ it "The number of accounts matches lines in CSV file, so number of accounts is correct" do - csv_lines = 0 - #iterating through CSV & counting the number of lines - CSV.open("support/accounts.csv").each do |line| - csv_lines += 1 - end + csv_lines = CSV.read("support/accounts.csv").length @new_bank.length.must_equal(csv_lines) end From 23ab6cc6eb4b3217b662e7ac677a3f3ea3fe9448 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 13:58:46 -0800 Subject: [PATCH 44/74] set up stubs for CheckingAccount and SavingsAccount classes --- lib/account.rb | 6 ------ lib/checking_account.rb | 8 ++++++++ lib/savings_account.rb | 8 ++++++++ specs/checking_account_spec.rb | 4 ++-- specs/savings_account_spec.rb | 4 ++-- 5 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 lib/checking_account.rb create mode 100644 lib/savings_account.rb diff --git a/lib/account.rb b/lib/account.rb index 92ea6645..d5bb2df5 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -108,9 +108,3 @@ def self.find(id) end end - -# my_account = Bank::Account.new(1212,1235667,"1999-03-27 11:30:09 -0800") -# -# puts my_account.balance - -puts " #{ Bank::Account.all.class } " diff --git a/lib/checking_account.rb b/lib/checking_account.rb new file mode 100644 index 00000000..9e709990 --- /dev/null +++ b/lib/checking_account.rb @@ -0,0 +1,8 @@ +require_relative 'account' + +module Bank + + class CheckingAccount < Account + end + +end diff --git a/lib/savings_account.rb b/lib/savings_account.rb new file mode 100644 index 00000000..9594b1b3 --- /dev/null +++ b/lib/savings_account.rb @@ -0,0 +1,8 @@ +require_relative 'account' + +module Bank + + class SavingsAccount < Account + end + +end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 7f95339e..f51261cb 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -3,7 +3,7 @@ require 'minitest/skip_dsl' # TODO: uncomment the next line once you start wave 3 and add lib/checking_account.rb -# require_relative '../lib/checking_account' +require_relative '../lib/checking_account' # Because a CheckingAccount is a kind # of Account, and we've already tested a bunch of functionality @@ -11,7 +11,7 @@ # Here we'll only test things that are different. # TODO: change 'xdescribe' to 'describe' to run these tests -xdescribe "CheckingAccount" do +describe "CheckingAccount" do describe "#initialize" do # Check that a CheckingAccount is in fact a kind of account it "Is a kind of Account" do diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 3f4d1e4a..2fc77c73 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -3,7 +3,7 @@ require 'minitest/skip_dsl' # TODO: uncomment the next line once you start wave 3 and add lib/savings_account.rb -# require_relative '../lib/savings_account' +require_relative '../lib/savings_account' # Because a SavingsAccount is a kind # of Account, and we've already tested a bunch of functionality @@ -11,7 +11,7 @@ # Here we'll only test things that are different. # TODO: change 'xdescribe' to 'describe' to run these tests -xdescribe "SavingsAccount" do +describe "SavingsAccount" do describe "#initialize" do it "Is a kind of Account" do # Check that a SavingsAccount is in fact a kind of account From abb53f19dc1661cbb53e0193b4ac5f37f53dcdc3 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 14:23:33 -0800 Subject: [PATCH 45/74] Add Savings account functionality that intial balance must be > 10 --- lib/savings_account.rb | 10 ++++++++-- specs/savings_account_spec.rb | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 9594b1b3..a2881b6f 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -1,8 +1,14 @@ -require_relative 'account' - module Bank class SavingsAccount < Account + + def initialize(id, balance, opendate = "nodate") + super + if balance < 10 + raise ArgumentError.new "You must initially deposit at least $10.00" + end + end + end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 2fc77c73..e73b759c 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -12,6 +12,7 @@ # TODO: change 'xdescribe' to 'describe' to run these tests describe "SavingsAccount" do + describe "#initialize" do it "Is a kind of Account" do # Check that a SavingsAccount is in fact a kind of account @@ -20,8 +21,11 @@ end it "Requires an initial balance of at least $10" do - # TODO: Your test code here! + proc { + Bank::SavingsAccount.new(1337, 1.00) + }.must_raise ArgumentError end + end describe "#withdraw" do From fb8fa1bf2ddf1597128d72d7c0ea7f695d306057 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 14:32:35 -0800 Subject: [PATCH 46/74] Add fee for each withdrawal --- lib/savings_account.rb | 5 +++++ specs/savings_account_spec.rb | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index a2881b6f..1e6eb9c4 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -9,6 +9,11 @@ def initialize(id, balance, opendate = "nodate") end end + def withdraw(withdrawal_amount) + super + @balance -= 2 + end + end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index e73b759c..c9f40346 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -30,7 +30,11 @@ describe "#withdraw" do it "Applies a $2 fee each time" do - # TODO: Your test code here! + my_savings = Bank::SavingsAccount.new(1234, 500.00) + my_savings.withdraw(10) + my_savings.balance.must_equal(488.00) + my_savings.withdraw(10) + my_savings.balance.must_equal(476.00) end it "Outputs a warning if the balance would go below $10" do From e062ad20c4183c194ca071932c810a521f0f3514 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 14:50:39 -0800 Subject: [PATCH 47/74] Outputs warning if withdrawal will take Savings Account balance below 0 & does not affect balance --- lib/savings_account.rb | 9 ++++++++- specs/savings_account_spec.rb | 24 +++++++++++++++++------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 1e6eb9c4..108f4714 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -11,7 +11,14 @@ def initialize(id, balance, opendate = "nodate") def withdraw(withdrawal_amount) super - @balance -= 2 + + if @balance - (withdrawal_amount - 2) < 10 + puts "You cannot go below $10." + @balance + else + @balance -= 2 + end + end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index c9f40346..1dd2803e 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -29,20 +29,30 @@ end describe "#withdraw" do + before do + @my_savings = Bank::SavingsAccount.new(1234, 500.00) + end + it "Applies a $2 fee each time" do - my_savings = Bank::SavingsAccount.new(1234, 500.00) - my_savings.withdraw(10) - my_savings.balance.must_equal(488.00) - my_savings.withdraw(10) - my_savings.balance.must_equal(476.00) + @my_savings.withdraw(10) + @my_savings.balance.must_equal(488.00) + + @my_savings.withdraw(10) + @my_savings.balance.must_equal(476.00) end it "Outputs a warning if the balance would go below $10" do - # TODO: Your test code here! + proc { @my_savings.withdraw(600) }.must_output(/.+/) end it "Doesn't modify the balance if it would go below $10" do - # TODO: Your test code here! + withdrawal_amount = 600.0 + updated_balance = @my_savings.withdraw(withdrawal_amount) + + # Both the value returned and the balance in the account + # must be un-modified. + updated_balance.must_equal 500 + @my_savings.balance.must_equal 500 end it "Doesn't modify the balance if the fee would put it below $10" do From 9c207c526a68afe7c2c38ebab78910c0f7972f78 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 15:57:18 -0800 Subject: [PATCH 48/74] create withdrawal for savings that does not withdraw if fee will take it below 10 --- lib/savings_account.rb | 11 +++++++---- specs/savings_account_spec.rb | 10 +++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 108f4714..1a3c43d2 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -10,15 +10,18 @@ def initialize(id, balance, opendate = "nodate") end def withdraw(withdrawal_amount) - super + original_balance = @balance + super(withdrawal_amount) - if @balance - (withdrawal_amount - 2) < 10 - puts "You cannot go below $10." + if @balance == original_balance @balance + elsif @balance - 2 <= 10 + puts "This withdrawal and fee will take your balance below $10." + return @balance = original_balance else @balance -= 2 end - + end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 1dd2803e..31312c0d 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -46,8 +46,7 @@ end it "Doesn't modify the balance if it would go below $10" do - withdrawal_amount = 600.0 - updated_balance = @my_savings.withdraw(withdrawal_amount) + updated_balance = @my_savings.withdraw(600.00) # Both the value returned and the balance in the account # must be un-modified. @@ -56,7 +55,12 @@ end it "Doesn't modify the balance if the fee would put it below $10" do - # TODO: Your test code here! + updated_balance = @my_savings.withdraw(490.00) + + #Both the value returned and balance in account + #must be un-modified + updated_balance.must_equal 500 + @my_savings.balance.must_equal 500 end end From f72b5f20a02cc67c2517e4b529514f2187d9792c Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 16:08:50 -0800 Subject: [PATCH 49/74] define add interest method --- lib/savings_account.rb | 5 +++++ specs/savings_account_spec.rb | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 1a3c43d2..c8f48f6b 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -21,7 +21,12 @@ def withdraw(withdrawal_amount) else @balance -= 2 end + end + def add_interest + interest = @balance * 0.25/100 + @balance += interest + return interest end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 31312c0d..c7fea41a 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -65,8 +65,12 @@ end describe "#add_interest" do + before do + @my_savings = Bank::SavingsAccount.new(1234, 500.00) + end + it "Returns the interest calculated" do - # TODO: Your test code here! + @my_savings.add_interest.must_equal(1.25) end it "Updates the balance with calculated interest" do From cf30c41d09192384e181f357bff7c9cd54577b0e Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 16:13:16 -0800 Subject: [PATCH 50/74] Updated method of add_interest to take parameter of interest rate --- lib/savings_account.rb | 4 ++-- specs/savings_account_spec.rb | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index c8f48f6b..075cecdd 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -23,8 +23,8 @@ def withdraw(withdrawal_amount) end end - def add_interest - interest = @balance * 0.25/100 + def add_interest(rate) + interest = @balance * (rate/100) @balance += interest return interest end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index c7fea41a..c9fb8c6f 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -67,14 +67,16 @@ describe "#add_interest" do before do @my_savings = Bank::SavingsAccount.new(1234, 500.00) + @my_interest = @my_savings.add_interest(0.25) end it "Returns the interest calculated" do - @my_savings.add_interest.must_equal(1.25) + @my_interest.must_equal(1.25) end it "Updates the balance with calculated interest" do - # TODO: Your test code here! + @my_savings.balance.must_equal(501.25) + end it "Requires a positive rate" do From 5fbc907fa13026053ea40cab4c619020cd80bca1 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 16:17:03 -0800 Subject: [PATCH 51/74] Interest rate must be positive.made all required edits --- lib/savings_account.rb | 2 ++ specs/savings_account_spec.rb | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 075cecdd..a77704b4 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -24,6 +24,8 @@ def withdraw(withdrawal_amount) end def add_interest(rate) + raise ArgumentError.new("Interest rate >=0") if rate < 0 + interest = @balance * (rate/100) @balance += interest return interest diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index c9fb8c6f..603fa2a3 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -76,11 +76,10 @@ it "Updates the balance with calculated interest" do @my_savings.balance.must_equal(501.25) - end it "Requires a positive rate" do - # TODO: Your test code here! + proc { @my_savings.add_interest(-0.25) }.must_raise ArgumentError end end end From 5fea8277ff7109e5651a319a59540a32194dc5c2 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 18:27:09 -0800 Subject: [PATCH 52/74] Add dollar fee for withdrawals from checking account --- lib/checking_account.rb | 15 +++++++++++++-- specs/checking_account_spec.rb | 7 ++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 9e709990..48835d70 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -1,8 +1,19 @@ -require_relative 'account' - module Bank class CheckingAccount < Account + + def withdraw(withdrawal_amount) + original_balance = @balance + super(withdrawal_amount) + + if @balance == original_balance + @balance + else + @balance -= 1 + end + + end + end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index f51261cb..a8d76f23 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -21,8 +21,13 @@ end describe "#withdraw" do + before do + @my_checking = Bank::CheckingAccount.new(1234, 500.00) + end + it "Applies a $1 fee each time" do - # TODO: Your test code here! + @my_checking.withdraw(10) + @my_checking.balance.must_equal(489) end it "Doesn't modify the balance if the fee would put it negative" do From c78c82758b6b099d002d020b63c8cda2227f66d9 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 18:48:10 -0800 Subject: [PATCH 53/74] Doesn't modify balance if fee would take it under 0, test works --- lib/checking_account.rb | 8 ++++++-- specs/checking_account_spec.rb | 8 +++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 48835d70..adc55599 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -3,15 +3,19 @@ module Bank class CheckingAccount < Account def withdraw(withdrawal_amount) + original_balance = @balance - super(withdrawal_amount) + puts original_balance + super if @balance == original_balance @balance + elsif @balance - 1 < 0 + puts "This withdrawal and fee will take your balance 0." + return @balance = original_balance else @balance -= 1 end - end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index a8d76f23..da470529 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -31,8 +31,14 @@ end it "Doesn't modify the balance if the fee would put it negative" do - # TODO: Your test code here! + updated_balance = @my_checking.withdraw(500.00) + + #Both the value returned and balance in account + #must be un-modified + updated_balance.must_equal 500 + @my_checking.balance.must_equal 500 end + end describe "#withdraw_using_check" do From 3c0614b84de6d5f4b4ede306ab9a9c368a4a41bb Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 18:52:24 -0800 Subject: [PATCH 54/74] Created basic check_withdrawal method --- lib/checking_account.rb | 4 ++++ specs/checking_account_spec.rb | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index adc55599..88a35b78 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -18,6 +18,10 @@ def withdraw(withdrawal_amount) end end + def withdraw_using_check(withdrawal_amount) + @balance -= withdrawal_amount + end + end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index da470529..55a1b2a4 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -42,8 +42,13 @@ end describe "#withdraw_using_check" do + before do + @my_checking = Bank::CheckingAccount.new(1234, 500.00) + end + it "Reduces the balance" do - # TODO: Your test code here! + @my_checking.withdraw_using_check(20) + @my_checking.balance.must_equal(480) end it "Returns the modified balance" do From c4371ffbbcc11ba7e3fe6305259c9a92c58b83c6 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 18:59:32 -0800 Subject: [PATCH 55/74] Make sure withdraw_with_check returns balance --- lib/checking_account.rb | 2 +- specs/checking_account_spec.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 88a35b78..bf4c8d7a 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -19,7 +19,7 @@ def withdraw(withdrawal_amount) end def withdraw_using_check(withdrawal_amount) - @balance -= withdrawal_amount + return @balance -= withdrawal_amount end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 55a1b2a4..2219ea7a 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -52,7 +52,9 @@ end it "Returns the modified balance" do - # TODO: Your test code here! + modified_balance = @my_checking.withdraw_using_check(20) + + modified_balance.must_equal(480) end it "Allows the balance to go down to -$10" do From 99db3d40f57a55676262edcdb19d58bee2999af7 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 19:06:23 -0800 Subject: [PATCH 56/74] allows check withdrawals to go up to -10 --- lib/checking_account.rb | 8 +++++++- specs/checking_account_spec.rb | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index bf4c8d7a..f49bd7ae 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -19,7 +19,13 @@ def withdraw(withdrawal_amount) end def withdraw_using_check(withdrawal_amount) - return @balance -= withdrawal_amount + if @balance - withdrawal_amount < -10 + puts "You can only go negative up to -$10" + return @balance + else + @balance -= withdrawal_amount + end + end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 2219ea7a..330bfd32 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -58,7 +58,7 @@ end it "Allows the balance to go down to -$10" do - # TODO: Your test code here! + @my_checking.withdraw_using_check(510) end it "Outputs a warning if the account would go below -$10" do From b01fad303b2c1e8deb198d54fbb77ad4ae538dcc Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 19:09:21 -0800 Subject: [PATCH 57/74] Won't allow more than -10 balance, outputs message for check withdrawals --- specs/checking_account_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 330bfd32..a66396a8 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -62,11 +62,12 @@ end it "Outputs a warning if the account would go below -$10" do - # TODO: Your test code here! + proc { @my_checking.withdraw_using_check(520) }.must_output(/.+/) end it "Doesn't modify the balance if the account would go below -$10" do - # TODO: Your test code here! + @my_checking.withdraw_using_check(520) + @my_checking.balance.must_equal(500) end it "Requires a positive withdrawal amount" do From 5419107db8dc2a9804eb11860e16d6f4eaec835e Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 19:11:51 -0800 Subject: [PATCH 58/74] check withdrawals must be positive --- lib/checking_account.rb | 4 +++- specs/checking_account_spec.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index f49bd7ae..8f2142ac 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -19,13 +19,15 @@ def withdraw(withdrawal_amount) end def withdraw_using_check(withdrawal_amount) + raise ArgumentError.new("Withdrawal must be >=0") if withdrawal_amount < 0 + if @balance - withdrawal_amount < -10 puts "You can only go negative up to -$10" return @balance else @balance -= withdrawal_amount end - + end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index a66396a8..3359b41a 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -71,7 +71,7 @@ end it "Requires a positive withdrawal amount" do - # TODO: Your test code here! + proc { @my_checking.withdraw_using_check(-25) }.must_raise ArgumentError end it "Allows 3 free uses" do From aa8601f55fa8dbbc914f2b81936ceeef1d1fea8c Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 19:23:06 -0800 Subject: [PATCH 59/74] WIP - working on adding the class var @@check_withdrawals. Code currently broken :( --- lib/checking_account.rb | 9 ++++++++- specs/checking_account_spec.rb | 12 ++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 8f2142ac..8f323f14 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -1,6 +1,7 @@ module Bank class CheckingAccount < Account + @@check_withdrawals = 0 def withdraw(withdrawal_amount) @@ -25,7 +26,13 @@ def withdraw_using_check(withdrawal_amount) puts "You can only go negative up to -$10" return @balance else - @balance -= withdrawal_amount + #THIS IS FUCKED UP! + @@check_withdrawals += 1 + if @@check_withdrawals > 3 + return @balance -= 2 + else + return @balance -= withdrawal_amount + end end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 3359b41a..69461e6d 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -75,11 +75,19 @@ end it "Allows 3 free uses" do - # TODO: Your test code here! + 3.times do + @my_checking.withdraw_using_check(10) + end + + @my_checking.balance.must_equal(470) end it "Applies a $2 fee after the third use" do - # TODO: Your test code here! + 4.times do + @my_checking.withdraw_using_check(10) + end + + @my_checking.balance.must_equal(458) end end From 1e56388de77650ab74c71d31b49b6f6956be9dc3 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 19:23:59 -0800 Subject: [PATCH 60/74] Just adding everything so I'm up to date. Still WIP --- Rakefile | 2 +- lib/savings_account.rb | 2 +- specs/savings_account_spec.rb | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index deb52f2c..f4f704fc 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,7 @@ require 'rake/testtask' Rake::TestTask.new do |t| t.libs = ["lib"] - t.warning = true + t.warning = false t.test_files = FileList['specs/*_spec.rb'] end diff --git a/lib/savings_account.rb b/lib/savings_account.rb index a77704b4..3fb69c88 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -11,7 +11,7 @@ def initialize(id, balance, opendate = "nodate") def withdraw(withdrawal_amount) original_balance = @balance - super(withdrawal_amount) + super if @balance == original_balance @balance diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 603fa2a3..9ea3056a 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -81,5 +81,7 @@ it "Requires a positive rate" do proc { @my_savings.add_interest(-0.25) }.must_raise ArgumentError end + end + end From 649ec52a78249620f30ea37ec84bb5d58226b98a Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Thu, 23 Feb 2017 21:44:15 -0800 Subject: [PATCH 61/74] fixed var check_withdrawals to be instance variable NOT class v. --- lib/account.rb | 7 +++---- lib/checking_account.rb | 22 +++++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index d5bb2df5..7fc9115c 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -71,15 +71,15 @@ def deposit(deposit_amount) end class Owner - attr_reader :last_name, :first_name, :street_address + attr_reader :last_name, :first_name, :street_address, :city, :state def initialize(id = nil, last_name = nil, first_name = nil, street_address = nil, city = nil, state = nil) id = id @last_name = last_name @first_name = first_name @street_address = street_address - city = city - state = state + @city = city + @state = state end def self.all @@ -97,7 +97,6 @@ def self.find(id) @owner = Bank::Owner.new(owner[0].to_i, owner[1], owner[2], owner[3], owner[4], owner[5]) end end - if @owner == nil raise ArgumentError.new "This owner does not exist!" else diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 8f323f14..bf2b627c 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -1,7 +1,11 @@ module Bank class CheckingAccount < Account - @@check_withdrawals = 0 + + def initialize(id, balance, opendate = "nodate") + super + @check_withdrawals = 0 + end def withdraw(withdrawal_amount) @@ -20,19 +24,19 @@ def withdraw(withdrawal_amount) end def withdraw_using_check(withdrawal_amount) - raise ArgumentError.new("Withdrawal must be >=0") if withdrawal_amount < 0 + raise ArgumentError.new("Withdrawal must be >= 0") if withdrawal_amount < 0 if @balance - withdrawal_amount < -10 puts "You can only go negative up to -$10" return @balance + end + + @check_withdrawals += 1 + + if @check_withdrawals <= 3 + @balance -= withdrawal_amount else - #THIS IS FUCKED UP! - @@check_withdrawals += 1 - if @@check_withdrawals > 3 - return @balance -= 2 - else - return @balance -= withdrawal_amount - end + @balance = (@balance - withdrawal_amount - 2) end end From af30766cbc3a4c0b4a51132a6f03a2da573f035c Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Fri, 24 Feb 2017 10:27:59 -0800 Subject: [PATCH 62/74] created and tested reset-checks method --- lib/account.rb | 10 +++++++++- lib/checking_account.rb | 10 +++++++--- specs/checking_account_spec.rb | 31 ++++++++++++++++++++++++++++--- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 7fc9115c..ae7bf869 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -50,7 +50,7 @@ def add_owner(owner) end def withdraw(withdrawal_amount) - raise ArgumentError.new("Withdrawal must be >=0") if withdrawal_amount < 0 + withdraw_positive(withdrawal_amount) if @balance - withdrawal_amount < 0 puts "You are going negative." @@ -60,6 +60,14 @@ def withdraw(withdrawal_amount) end end + #Should this be private?? + #creating this as a method b/c + #used in check_withdrawal as well + def withdraw_positive(withdrawal_amount) + #makes sure the withdrawal amount is pos. + raise ArgumentError.new("Withdrawal must be >=0") if withdrawal_amount < 0 + end + def deposit(deposit_amount) if deposit_amount > 0 @balance += deposit_amount diff --git a/lib/checking_account.rb b/lib/checking_account.rb index bf2b627c..5bf023ce 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -10,13 +10,13 @@ def initialize(id, balance, opendate = "nodate") def withdraw(withdrawal_amount) original_balance = @balance - puts original_balance + # puts original_balance super if @balance == original_balance @balance elsif @balance - 1 < 0 - puts "This withdrawal and fee will take your balance 0." + puts "This withdrawal and fee will take your balance below 0." return @balance = original_balance else @balance -= 1 @@ -24,7 +24,7 @@ def withdraw(withdrawal_amount) end def withdraw_using_check(withdrawal_amount) - raise ArgumentError.new("Withdrawal must be >= 0") if withdrawal_amount < 0 + withdraw_positive(withdrawal_amount) if @balance - withdrawal_amount < -10 puts "You can only go negative up to -$10" @@ -33,12 +33,16 @@ def withdraw_using_check(withdrawal_amount) @check_withdrawals += 1 + #separate method? if @check_withdrawals <= 3 @balance -= withdrawal_amount else @balance = (@balance - withdrawal_amount - 2) end + end + def reset_checks + @check_withdrawals = 0 end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 69461e6d..3ed4c7a6 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -92,16 +92,41 @@ end describe "#reset_checks" do + before do + @my_checking = Bank::CheckingAccount.new(1234, 500.00) + end + it "Can be called without error" do - # TODO: Your test code here! + @my_checking.reset_checks end it "Makes the next three checks free if less than 3 checks had been used" do - # TODO: Your test code here! + 2.times do + @my_checking.withdraw_using_check(10) + end + + @my_checking.reset_checks + + 3.times do + @my_checking.withdraw_using_check(10) + end + + @my_checking.balance.must_equal(450) end it "Makes the next three checks free if more than 3 checks had been used" do - # TODO: Your test code here! + 4.times do + @my_checking.withdraw_using_check(10) + end + + @my_checking.reset_checks + + 3.times do + @my_checking.withdraw_using_check(10) + end + + @my_checking.balance.must_equal(428) + end end end From 8ef02b9fd78641542399050f66a6ab80f464027c Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Fri, 24 Feb 2017 11:38:26 -0800 Subject: [PATCH 63/74] Added set_balance method to start. Trying to turn instance vars of @balance into calling the method throughout code. WIP --- lib/account.rb | 19 +++++++++++-------- lib/checking_account.rb | 20 ++++++++++++-------- lib/savings_account.rb | 11 +++++++++-- specs/checking_account_spec.rb | 2 +- specs/savings_account_spec.rb | 2 +- 5 files changed, 34 insertions(+), 20 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index ae7bf869..b20f1bab 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -3,17 +3,20 @@ module Bank class Account - attr_accessor :balance, :owner - attr_reader :id + # attr_accessor :balance + attr_reader :id, :owner, :balance - def initialize(id, balance, opendate = "nodate") + def initialize(id, start_balance, opendate = "nodate") @id = id @opendate = opendate + @balance = set_balance(start_balance) + end - if balance < 0 + def set_balance(start_balance) + if start_balance < 0 raise ArgumentError.new "You cannot initialize a new account with a negative balance." else - @balance = balance + start_balance end end @@ -52,9 +55,9 @@ def add_owner(owner) def withdraw(withdrawal_amount) withdraw_positive(withdrawal_amount) - if @balance - withdrawal_amount < 0 + if balance - withdrawal_amount < 0 puts "You are going negative." - return @balance + return balance else @balance -= withdrawal_amount end @@ -62,7 +65,7 @@ def withdraw(withdrawal_amount) #Should this be private?? #creating this as a method b/c - #used in check_withdrawal as well + #used in check_withdrawals def withdraw_positive(withdrawal_amount) #makes sure the withdrawal amount is pos. raise ArgumentError.new("Withdrawal must be >=0") if withdrawal_amount < 0 diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 5bf023ce..96f1c622 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -3,42 +3,46 @@ module Bank class CheckingAccount < Account def initialize(id, balance, opendate = "nodate") + super @check_withdrawals = 0 + end def withdraw(withdrawal_amount) - original_balance = @balance - # puts original_balance + original_balance = balance + super - if @balance == original_balance - @balance - elsif @balance - 1 < 0 + if balance == original_balance + balance + elsif balance - 1 < 0 puts "This withdrawal and fee will take your balance below 0." - return @balance = original_balance + @balance = original_balance else @balance -= 1 end + end def withdraw_using_check(withdrawal_amount) + withdraw_positive(withdrawal_amount) if @balance - withdrawal_amount < -10 puts "You can only go negative up to -$10" - return @balance + return balance end @check_withdrawals += 1 - #separate method? if @check_withdrawals <= 3 @balance -= withdrawal_amount else @balance = (@balance - withdrawal_amount - 2) end + end def reset_checks diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 3fb69c88..67edb507 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -3,18 +3,22 @@ module Bank class SavingsAccount < Account def initialize(id, balance, opendate = "nodate") + super - if balance < 10 + + if @balance < 10 raise ArgumentError.new "You must initially deposit at least $10.00" end + end def withdraw(withdrawal_amount) + original_balance = @balance super if @balance == original_balance - @balance + balance elsif @balance - 2 <= 10 puts "This withdrawal and fee will take your balance below $10." return @balance = original_balance @@ -24,11 +28,14 @@ def withdraw(withdrawal_amount) end def add_interest(rate) + raise ArgumentError.new("Interest rate >=0") if rate < 0 interest = @balance * (rate/100) @balance += interest + return interest + end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 3ed4c7a6..cd99929c 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -126,7 +126,7 @@ end @my_checking.balance.must_equal(428) - + end end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 9ea3056a..342dfb08 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -83,5 +83,5 @@ end end - + end From d7b50610be92dd2577e55d59d10a2bd19fc4c008 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Fri, 24 Feb 2017 12:20:13 -0800 Subject: [PATCH 64/74] Adding files and stumps of Money Market account & spec files --- lib/account.rb | 2 ++ lib/money_market_account.rb | 7 +++++++ specs/money_market_account_spec.rb | 0 3 files changed, 9 insertions(+) create mode 100644 lib/money_market_account.rb create mode 100644 specs/money_market_account_spec.rb diff --git a/lib/account.rb b/lib/account.rb index b20f1bab..7a0ba800 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -108,11 +108,13 @@ def self.find(id) @owner = Bank::Owner.new(owner[0].to_i, owner[1], owner[2], owner[3], owner[4], owner[5]) end end + if @owner == nil raise ArgumentError.new "This owner does not exist!" else return @owner end + end end diff --git a/lib/money_market_account.rb b/lib/money_market_account.rb new file mode 100644 index 00000000..1fb8c133 --- /dev/null +++ b/lib/money_market_account.rb @@ -0,0 +1,7 @@ +module Bank + + class MoneyMarketAccount < Account + + end + +end diff --git a/specs/money_market_account_spec.rb b/specs/money_market_account_spec.rb new file mode 100644 index 00000000..e69de29b From b4a13e30f1054631fc78e967d575f0ce746336a2 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Fri, 24 Feb 2017 14:08:45 -0800 Subject: [PATCH 65/74] Money Market account initialize & set balance methods done --- lib/account.rb | 6 +-- lib/checking_account.rb | 2 +- lib/money_market_account.rb | 17 ++++++- lib/savings_account.rb | 2 +- specs/money_market_account_spec.rb | 73 ++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 7 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 7a0ba800..d1157c12 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -3,10 +3,10 @@ module Bank class Account - # attr_accessor :balance - attr_reader :id, :owner, :balance + attr_accessor :balance + attr_reader :id, :owner - def initialize(id, start_balance, opendate = "nodate") + def initialize(id, start_balance, opendate = nil) @id = id @opendate = opendate @balance = set_balance(start_balance) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 96f1c622..5d6e3210 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -2,7 +2,7 @@ module Bank class CheckingAccount < Account - def initialize(id, balance, opendate = "nodate") + def initialize(id, balance, opendate = nil) super @check_withdrawals = 0 diff --git a/lib/money_market_account.rb b/lib/money_market_account.rb index 1fb8c133..2a28ab86 100644 --- a/lib/money_market_account.rb +++ b/lib/money_market_account.rb @@ -1,7 +1,20 @@ +require_relative 'account' + module Bank - class MoneyMarketAccount < Account - + class MoneyMarketAccount < Bank::Account + + def set_balance(start_balance) + # IF the initial balance is < 10,000 + #raise an argument error. + if start_balance < 10000 + raise ArgumentError.new "You cannot initialize a new Money Market account with less than 10k." + else + start_balance + end + + end + end end diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 67edb507..c594be52 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -2,7 +2,7 @@ module Bank class SavingsAccount < Account - def initialize(id, balance, opendate = "nodate") + def initialize(id, balance, opendate = nil) super diff --git a/specs/money_market_account_spec.rb b/specs/money_market_account_spec.rb index e69de29b..0288ac7d 100644 --- a/specs/money_market_account_spec.rb +++ b/specs/money_market_account_spec.rb @@ -0,0 +1,73 @@ +require 'minitest/autorun' +require 'minitest/reporters' +require 'minitest/skip_dsl' + +require_relative '../lib/money_market_account' + +describe "Bank::MoneyMarketAccount" do + + describe "#initialize" do + #Check that MoneyMarketAccount is a kind of account + it "Check Initialize" do + account = Bank::MoneyMarketAccount.new(123, 10000.00, "5/5/5") + account.must_be_kind_of Bank::Account + end + + it "Initial balance must be > 10k" do + #initial balance cannot be less than 10,000. This will raise an ArgumentError + proc { Bank::MoneyMarketAccount.new(1337, 9999) }.must_raise ArgumentError + end + + end + + describe "transactions" do + before do + @my_money_market = Bank::MoneyMarketAccount.new(1234, 100000.00) + end + + it "Does not allow more than six transactions" do + #Maximum of 6 transactions allowed per month + 6.times do + @my_money_market.withdraw(10) + end + + #7th transaction should raise error + proc { @my_money_market.withdraw(10) }.must_raise ArgumentError + + end + + end + +end + + + +#Maximum of 6 transactions allowed per month +# inputs - transaction numbers. +# outputs - argument error if number of transactions goes over 6 + +#Withdrawal logic + +#If a withdrawal goes below 10k a fee of $100 is imposed and no more transactions are allowed until the balance is increased using a deposit transaction. +# inputs are withdrawals, withdrawawl_ammount +# Outputs are updated balance, a fee to charge against updated balance, a warning. A stop on withdrawals until a deposit is made that brings the balance over 10k, updated transaction number + +#Each transaction will be counted against the maximum number of transactions. +# inputs are withdrawals and ammount. +# Outputs are updated balance and updated number of total transactions. + +#Deposit logic +# Each transaction will be counted against the maximum number of transactions. +# inputs are withdrawal or deposit and ammount. +# output is updated total transactions +# Exception to the above: A deposit performed to reach or exceed the minimum balance of $10,000 is not counted as part of the 6 transactions. +# input are whether or not balance is below 10k, withdrawal or deposit, amount. +# outputs are updated balance, number of transactions NOT updated. + +# Reset transactions - same as with check withdrawal. +# inputs are just calling the method. +# Output is the transaction total being reset to zero. + +# Add interest same as to SavingsAccount +# Inputs are interest rate, balance +# Outputs are updated balance, returning interest earned. From 4f4d00ea9c6edb82d27fb1b5283187fe9720e51a Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Fri, 24 Feb 2017 14:25:41 -0800 Subject: [PATCH 66/74] got total transactions for Money Market to stop after 6 --- lib/money_market_account.rb | 29 +++++++++++++++++++++++++++++ specs/money_market_account_spec.rb | 15 ++++++++++++--- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/lib/money_market_account.rb b/lib/money_market_account.rb index 2a28ab86..fb4818b1 100644 --- a/lib/money_market_account.rb +++ b/lib/money_market_account.rb @@ -3,6 +3,12 @@ module Bank class MoneyMarketAccount < Bank::Account + attr_reader :total_transactions + + def initialize(id, balance, opendate = nil) + super + @total_transactions = 0 + end def set_balance(start_balance) # IF the initial balance is < 10,000 @@ -12,9 +18,32 @@ def set_balance(start_balance) else start_balance end + end + def withdraw(withdrawal_amount) + @total_transactions += 1 + if @total_transactions > 6 + raise ArgumentError.new "You cannot make more than six transactions per month." + end + super + end + + def deposit(deposit_amount) + @total_transactions += 1 + if @total_transactions > 6 + raise ArgumentError.new "You cannot make more than six transactions per month." + end + super end end end + +@my_money_market = Bank::MoneyMarketAccount.new(1234, 100000.00) + +6.times do + @my_money_market.withdraw(10) +end + +print @total_transactions diff --git a/specs/money_market_account_spec.rb b/specs/money_market_account_spec.rb index 0288ac7d..434d664a 100644 --- a/specs/money_market_account_spec.rb +++ b/specs/money_market_account_spec.rb @@ -22,10 +22,10 @@ describe "transactions" do before do - @my_money_market = Bank::MoneyMarketAccount.new(1234, 100000.00) + @my_money_market = Bank::MoneyMarketAccount.new(1234, 1000000.00) end - it "Does not allow more than six transactions" do + it "Does not allow more than six withdrawals" do #Maximum of 6 transactions allowed per month 6.times do @my_money_market.withdraw(10) @@ -33,9 +33,18 @@ #7th transaction should raise error proc { @my_money_market.withdraw(10) }.must_raise ArgumentError + end + it "Does not allow more than six deposits" do + #Maximum of 6 transactions allowed per month + 6.times do + @my_money_market.deposit(10) + end + + #7th transaction should raise error + proc { @my_money_market.deposit(10) }.must_raise ArgumentError end - + end end From 92f50fba4116f4982a5efe2c7988426f2824f67a Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Fri, 24 Feb 2017 14:40:50 -0800 Subject: [PATCH 67/74] edited withdraw method for MMarket, preventing any withdrawals if balance is less than 10k --- lib/money_market_account.rb | 9 ++++++++ specs/money_market_account_spec.rb | 36 +++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/lib/money_market_account.rb b/lib/money_market_account.rb index fb4818b1..f6915f7d 100644 --- a/lib/money_market_account.rb +++ b/lib/money_market_account.rb @@ -25,7 +25,16 @@ def withdraw(withdrawal_amount) if @total_transactions > 6 raise ArgumentError.new "You cannot make more than six transactions per month." end + + if @balance < 10000 + raise ArgumentError.new "You cannot make another withdrawal until you make a deposit" + end + super + if @balance < 10000 + @balance -= 100 + end + end def deposit(deposit_amount) diff --git a/specs/money_market_account_spec.rb b/specs/money_market_account_spec.rb index 434d664a..b244aea4 100644 --- a/specs/money_market_account_spec.rb +++ b/specs/money_market_account_spec.rb @@ -45,15 +45,45 @@ proc { @my_money_market.deposit(10) }.must_raise ArgumentError end + it "Does not allow more than six mixed deposits and withdrawals together" do + #Maximum of 6 transactions allowed per month + 3.times do + @my_money_market.deposit(10) + end + + 3.times do + @my_money_market.withdraw(10) + end + + #7th transaction should raise error + proc { @my_money_market.deposit(10) }.must_raise ArgumentError + end + + end + + describe "transactions" do + before do + @my_money_market = Bank::MoneyMarketAccount.new(1234, 10000.00) + end + + it "if withdrawal takes balance below 10k, charges a fee of $100" do + @my_money_market.withdraw(500) + + @my_money_market.balance.must_equal(9400) + end + + it "if withdrawal goes below 10k, no more transactions are allowed" do + @my_money_market.withdraw(500) + + proc { @my_money_market.withdraw(500) }.must_raise ArgumentError + end + end end -#Maximum of 6 transactions allowed per month -# inputs - transaction numbers. -# outputs - argument error if number of transactions goes over 6 #Withdrawal logic From 88221b9d9d110b2e70be1adc4b8c764bf4169a8c Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Fri, 24 Feb 2017 14:47:53 -0800 Subject: [PATCH 68/74] Added test for counting total transactions. Failing --- specs/money_market_account_spec.rb | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/specs/money_market_account_spec.rb b/specs/money_market_account_spec.rb index b244aea4..fbe435ac 100644 --- a/specs/money_market_account_spec.rb +++ b/specs/money_market_account_spec.rb @@ -78,6 +78,21 @@ proc { @my_money_market.withdraw(500) }.must_raise ArgumentError end + it "if withdrawal goes below 10k, then deposit goes above 10k, should be allow to withdraw again" do + @my_money_market.withdraw(500) + @my_money_market.deposit(1000) + #should not raise an issue. + @my_money_market.withdraw(10) + end + + it "all transactions count towards 6 transactions, except for deposit to bring balance back up to 10k" do + @my_money_market.withdraw(500) + @my_money_market.deposit(1000) + #should not raise an issue. + @my_money_market.withdraw(10) + @my_money_market.total_transactions.must_equal(2) + end + end end @@ -87,18 +102,9 @@ #Withdrawal logic -#If a withdrawal goes below 10k a fee of $100 is imposed and no more transactions are allowed until the balance is increased using a deposit transaction. -# inputs are withdrawals, withdrawawl_ammount -# Outputs are updated balance, a fee to charge against updated balance, a warning. A stop on withdrawals until a deposit is made that brings the balance over 10k, updated transaction number - -#Each transaction will be counted against the maximum number of transactions. -# inputs are withdrawals and ammount. -# Outputs are updated balance and updated number of total transactions. #Deposit logic -# Each transaction will be counted against the maximum number of transactions. -# inputs are withdrawal or deposit and ammount. -# output is updated total transactions + # Exception to the above: A deposit performed to reach or exceed the minimum balance of $10,000 is not counted as part of the 6 transactions. # input are whether or not balance is below 10k, withdrawal or deposit, amount. # outputs are updated balance, number of transactions NOT updated. From 11a61ed6813828065fedff590e4fcd72afc5ccf1 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Fri, 24 Feb 2017 14:50:45 -0800 Subject: [PATCH 69/74] Passing total transactions test --- lib/money_market_account.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/money_market_account.rb b/lib/money_market_account.rb index f6915f7d..8e6d6d64 100644 --- a/lib/money_market_account.rb +++ b/lib/money_market_account.rb @@ -38,7 +38,10 @@ def withdraw(withdrawal_amount) end def deposit(deposit_amount) - @total_transactions += 1 + if @balance > 10000 + @total_transactions += 1 + end + if @total_transactions > 6 raise ArgumentError.new "You cannot make more than six transactions per month." end From a2ddadfa060c7a2b70605b2453536f102d501d46 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Fri, 24 Feb 2017 15:16:06 -0800 Subject: [PATCH 70/74] created reset transactions method & tested --- lib/money_market_account.rb | 17 +++++++++-------- specs/money_market_account_spec.rb | 20 ++++++++++++++------ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/lib/money_market_account.rb b/lib/money_market_account.rb index 8e6d6d64..d8479e2c 100644 --- a/lib/money_market_account.rb +++ b/lib/money_market_account.rb @@ -22,6 +22,7 @@ def set_balance(start_balance) def withdraw(withdrawal_amount) @total_transactions += 1 + if @total_transactions > 6 raise ArgumentError.new "You cannot make more than six transactions per month." end @@ -31,6 +32,7 @@ def withdraw(withdrawal_amount) end super + if @balance < 10000 @balance -= 100 end @@ -38,6 +40,7 @@ def withdraw(withdrawal_amount) end def deposit(deposit_amount) + if @balance > 10000 @total_transactions += 1 end @@ -45,17 +48,15 @@ def deposit(deposit_amount) if @total_transactions > 6 raise ArgumentError.new "You cannot make more than six transactions per month." end + super - end - end + end -end + def reset_transactions + @total_transactions = 0 + end -@my_money_market = Bank::MoneyMarketAccount.new(1234, 100000.00) + end -6.times do - @my_money_market.withdraw(10) end - -print @total_transactions diff --git a/specs/money_market_account_spec.rb b/specs/money_market_account_spec.rb index fbe435ac..6bb846ce 100644 --- a/specs/money_market_account_spec.rb +++ b/specs/money_market_account_spec.rb @@ -95,19 +95,27 @@ end -end + describe "#reset_transactions" do + before do + @my_money_market = Bank::MoneyMarketAccount.new(1234, 100000.00) + end + it "resets total_transactions to 0" do + 3.times do + @my_money_market.withdraw(10) + end + @my_money_market.reset_transactions -#Withdrawal logic + @my_money_market.total_transactions.must_equal(0) + end + + end +end -#Deposit logic -# Exception to the above: A deposit performed to reach or exceed the minimum balance of $10,000 is not counted as part of the 6 transactions. -# input are whether or not balance is below 10k, withdrawal or deposit, amount. -# outputs are updated balance, number of transactions NOT updated. # Reset transactions - same as with check withdrawal. # inputs are just calling the method. From 12b55a5d07b76b027d109a6ee619bb4f734c82b4 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Fri, 24 Feb 2017 15:21:03 -0800 Subject: [PATCH 71/74] created add interest for money market account --- lib/money_market_account.rb | 11 +++++++++++ specs/money_market_account_spec.rb | 26 +++++++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lib/money_market_account.rb b/lib/money_market_account.rb index d8479e2c..9c529404 100644 --- a/lib/money_market_account.rb +++ b/lib/money_market_account.rb @@ -57,6 +57,17 @@ def reset_transactions @total_transactions = 0 end + def add_interest(rate) + + raise ArgumentError.new("Interest rate >=0") if rate < 0 + + interest = @balance * (rate/100) + @balance += interest + + return interest + + end + end end diff --git a/specs/money_market_account_spec.rb b/specs/money_market_account_spec.rb index 6bb846ce..83efb6b2 100644 --- a/specs/money_market_account_spec.rb +++ b/specs/money_market_account_spec.rb @@ -8,7 +8,7 @@ describe "#initialize" do #Check that MoneyMarketAccount is a kind of account - it "Check Initialize" do + it "Check#Initialize" do account = Bank::MoneyMarketAccount.new(123, 10000.00, "5/5/5") account.must_be_kind_of Bank::Account end @@ -112,15 +112,31 @@ end + describe "#add_interest" do + before do + @my_money_market = Bank::MoneyMarketAccount.new(1234, 10000.00) + @my_interest = @my_money_market.add_interest(0.25) + end + + it "Returns the interest calculated" do + @my_interest.must_equal(25) + end + + it "Updates the balance with calculated interest" do + @my_money_market.balance.must_equal(10025.00) + end + + it "Requires a positive rate" do + proc { @my_money_market.add_interest(-0.25) }.must_raise ArgumentError + end + + end + end end -# Reset transactions - same as with check withdrawal. -# inputs are just calling the method. -# Output is the transaction total being reset to zero. - # Add interest same as to SavingsAccount # Inputs are interest rate, balance # Outputs are updated balance, returning interest earned. From 78e4fe2176a84c7eea5e1ad0e961791f282f1f06 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Fri, 24 Feb 2017 15:31:40 -0800 Subject: [PATCH 72/74] trying to dry up code w/ argument method --- lib/account.rb | 18 +++++++++++------- lib/money_market_account.rb | 2 +- lib/savings_account.rb | 4 ++-- specs/money_market_account_spec.rb | 6 ------ 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index d1157c12..3edc06f7 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -14,7 +14,7 @@ def initialize(id, start_balance, opendate = nil) def set_balance(start_balance) if start_balance < 0 - raise ArgumentError.new "You cannot initialize a new account with a negative balance." + argument("You cannot initialize a new account with a negative balance.") else start_balance end @@ -38,7 +38,7 @@ def self.find(id) end if @account == nil - raise ArgumentError.new "This account doee not exist!" + raise ArgumentError.new "This account does not exist!" else return @account end @@ -48,7 +48,7 @@ def add_owner(owner) if owner.class == Owner @owner = owner else - raise ArgumentError.new "You must add a class type of Owner." + argument("You must add a class type of Owner.") end end @@ -68,24 +68,28 @@ def withdraw(withdrawal_amount) #used in check_withdrawals def withdraw_positive(withdrawal_amount) #makes sure the withdrawal amount is pos. - raise ArgumentError.new("Withdrawal must be >=0") if withdrawal_amount < 0 + argument("Withdrawal must be >= 0") if withdrawal_amount < 0 end def deposit(deposit_amount) if deposit_amount > 0 @balance += deposit_amount else - raise ArgumentError.new "Your deposit must be greater than zero." + argument("Your deposit must be greater than zero.") end end + def argument(output) + raise ArgumentError.new "#{ output }" + end + end class Owner attr_reader :last_name, :first_name, :street_address, :city, :state def initialize(id = nil, last_name = nil, first_name = nil, street_address = nil, city = nil, state = nil) - id = id + @id = id @last_name = last_name @first_name = first_name @street_address = street_address @@ -110,7 +114,7 @@ def self.find(id) end if @owner == nil - raise ArgumentError.new "This owner does not exist!" + argument("This owner does not exist!") else return @owner end diff --git a/lib/money_market_account.rb b/lib/money_market_account.rb index 9c529404..dfe2fec5 100644 --- a/lib/money_market_account.rb +++ b/lib/money_market_account.rb @@ -14,7 +14,7 @@ def set_balance(start_balance) # IF the initial balance is < 10,000 #raise an argument error. if start_balance < 10000 - raise ArgumentError.new "You cannot initialize a new Money Market account with less than 10k." + argument("You cannot initialize a new Money Market account with less than 10k.") else start_balance end diff --git a/lib/savings_account.rb b/lib/savings_account.rb index c594be52..3d902c98 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -7,7 +7,7 @@ def initialize(id, balance, opendate = nil) super if @balance < 10 - raise ArgumentError.new "You must initially deposit at least $10.00" + argument("You must initially deposit at least $10.00") end end @@ -29,7 +29,7 @@ def withdraw(withdrawal_amount) def add_interest(rate) - raise ArgumentError.new("Interest rate >=0") if rate < 0 + argument("Interest rate must be >= 0") if rate < 0 interest = @balance * (rate/100) @balance += interest diff --git a/specs/money_market_account_spec.rb b/specs/money_market_account_spec.rb index 83efb6b2..72d9a73b 100644 --- a/specs/money_market_account_spec.rb +++ b/specs/money_market_account_spec.rb @@ -134,9 +134,3 @@ end end - - - -# Add interest same as to SavingsAccount -# Inputs are interest rate, balance -# Outputs are updated balance, returning interest earned. From 970e88c19a08fe9c26d879aa91668cf8df2c6793 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Fri, 24 Feb 2017 15:58:19 -0800 Subject: [PATCH 73/74] pulling out fees for withdrawals and creating them as their own methods --- lib/account.rb | 49 +++++++++++++++++++++++++++++++------ lib/checking_account.rb | 19 +++++++++++--- lib/money_market_account.rb | 8 +++--- lib/savings_account.rb | 7 +++++- 4 files changed, 67 insertions(+), 16 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 3edc06f7..b18b1704 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -7,30 +7,38 @@ class Account attr_reader :id, :owner def initialize(id, start_balance, opendate = nil) + @id = id @opendate = opendate @balance = set_balance(start_balance) + end def set_balance(start_balance) + if start_balance < 0 argument("You cannot initialize a new account with a negative balance.") else start_balance end + end def self.all + accounts = [] CSV.open("support/accounts.csv").each do |account| accounts << Bank::Account.new(account[0].to_i, account[1].to_i, account[2]) end return accounts + end def self.find(id) + @account = nil + CSV.open("support/accounts.csv").each do |line| if line[0].to_i == id @account = Bank::Account.new(line[0].to_i, line[1].to_i, line[2]) @@ -42,17 +50,21 @@ def self.find(id) else return @account end + end def add_owner(owner) + if owner.class == Owner @owner = owner else argument("You must add a class type of Owner.") end + end def withdraw(withdrawal_amount) + withdraw_positive(withdrawal_amount) if balance - withdrawal_amount < 0 @@ -61,64 +73,87 @@ def withdraw(withdrawal_amount) else @balance -= withdrawal_amount end + end #Should this be private?? - #creating this as a method b/c - #used in check_withdrawals + #b/c only used in check_withdrawals? def withdraw_positive(withdrawal_amount) + #makes sure the withdrawal amount is pos. argument("Withdrawal must be >= 0") if withdrawal_amount < 0 + end def deposit(deposit_amount) + if deposit_amount > 0 @balance += deposit_amount else argument("Your deposit must be greater than zero.") end + end def argument(output) + raise ArgumentError.new "#{ output }" + end end class Owner + attr_reader :last_name, :first_name, :street_address, :city, :state - def initialize(id = nil, last_name = nil, first_name = nil, street_address = nil, city = nil, state = nil) + def initialize( + + id = nil, last_name = nil, + first_name = nil, street_address = nil, + city = nil, state = nil) @id = id @last_name = last_name @first_name = first_name @street_address = street_address @city = city @state = state + end def self.all + owners = [] CSV.open("support/owners.csv").each do |owner| - owners << Bank::Owner.new(owner[0].to_i, owner[1], owner[2], owner[3], owner[4], owner[5]) + owners << Bank::Owner.new( + owner[0].to_i, owner[1], + owner[2], owner[3], + owner[4], owner[5]) end + return owners + end def self.find(id) + @owner = nil CSV.open("support/owners.csv").each do |owner| if owner[0].to_i == id - @owner = Bank::Owner.new(owner[0].to_i, owner[1], owner[2], owner[3], owner[4], owner[5]) + @owner = Bank::Owner.new( + owner[0].to_i, owner[1], + owner[2], owner[3], + owner[4], owner[5]) end + end if @owner == nil - argument("This owner does not exist!") + raise ArgumentError.new "This owner does not exist!" else return @owner end - + end end diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 5d6e3210..f5e7f0e9 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -21,11 +21,15 @@ def withdraw(withdrawal_amount) puts "This withdrawal and fee will take your balance below 0." @balance = original_balance else - @balance -= 1 + withdrawal_fee end end + def withdrawal_fee + @balance -= 1 + end + def withdraw_using_check(withdrawal_amount) withdraw_positive(withdrawal_amount) @@ -36,11 +40,18 @@ def withdraw_using_check(withdrawal_amount) end @check_withdrawals += 1 + @balance -= withdrawal_amount + + check_fee + + end + + def check_fee - if @check_withdrawals <= 3 - @balance -= withdrawal_amount + if @check_withdrawals > 3 + @balance -= 2 else - @balance = (@balance - withdrawal_amount - 2) + @balance end end diff --git a/lib/money_market_account.rb b/lib/money_market_account.rb index dfe2fec5..c7d9b6fc 100644 --- a/lib/money_market_account.rb +++ b/lib/money_market_account.rb @@ -24,11 +24,11 @@ def withdraw(withdrawal_amount) @total_transactions += 1 if @total_transactions > 6 - raise ArgumentError.new "You cannot make more than six transactions per month." + argument("You cannot make more than six transactions per month.") end if @balance < 10000 - raise ArgumentError.new "You cannot make another withdrawal until you make a deposit" + argument("You cannot make another withdrawal until you make a deposit") end super @@ -46,7 +46,7 @@ def deposit(deposit_amount) end if @total_transactions > 6 - raise ArgumentError.new "You cannot make more than six transactions per month." + argument("You cannot make more than six transactions per month.") end super @@ -59,7 +59,7 @@ def reset_transactions def add_interest(rate) - raise ArgumentError.new("Interest rate >=0") if rate < 0 + argument("Interest rate >=0") if rate < 0 interest = @balance * (rate/100) @balance += interest diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 3d902c98..4b435951 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -23,8 +23,13 @@ def withdraw(withdrawal_amount) puts "This withdrawal and fee will take your balance below $10." return @balance = original_balance else - @balance -= 2 + withdrawal_fee end + + end + + def withdrawal_fee + @balance -= 2 end def add_interest(rate) From 1754f3ba8a6ca4bd057b999c28e65db31553ee49 Mon Sep 17 00:00:00 2001 From: Lynn Trickey Date: Sun, 26 Feb 2017 22:20:46 -0800 Subject: [PATCH 74/74] Added in Interest module to practice Object Comparison --- lib/account.rb | 43 +++++++++++++++---------------------- lib/checking_account.rb | 8 ------- lib/money_market_account.rb | 19 +++------------- lib/savings_account.rb | 25 ++++++--------------- 4 files changed, 26 insertions(+), 69 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index b18b1704..eea19d78 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,5 +1,21 @@ require 'csv' +#Adding this in after the reading this weekend. +#b/c both savings and money market have interest +#but are sisters not mother/daughter classes! +module Interest + + def add_interest(rate) + argument("Interest rate >=0") if rate < 0 + + interest = @balance * (rate/100) + @balance += interest + + return interest + end + +end + module Bank class Account @@ -11,32 +27,26 @@ def initialize(id, start_balance, opendate = nil) @id = id @opendate = opendate @balance = set_balance(start_balance) - end def set_balance(start_balance) - if start_balance < 0 argument("You cannot initialize a new account with a negative balance.") else start_balance end - end def self.all - accounts = [] CSV.open("support/accounts.csv").each do |account| accounts << Bank::Account.new(account[0].to_i, account[1].to_i, account[2]) end return accounts - end def self.find(id) - @account = nil CSV.open("support/accounts.csv").each do |line| @@ -50,21 +60,17 @@ def self.find(id) else return @account end - end def add_owner(owner) - if owner.class == Owner @owner = owner else argument("You must add a class type of Owner.") end - end def withdraw(withdrawal_amount) - withdraw_positive(withdrawal_amount) if balance - withdrawal_amount < 0 @@ -73,42 +79,32 @@ def withdraw(withdrawal_amount) else @balance -= withdrawal_amount end - end #Should this be private?? #b/c only used in check_withdrawals? def withdraw_positive(withdrawal_amount) - - #makes sure the withdrawal amount is pos. argument("Withdrawal must be >= 0") if withdrawal_amount < 0 - end def deposit(deposit_amount) - if deposit_amount > 0 @balance += deposit_amount else argument("Your deposit must be greater than zero.") end - end def argument(output) - raise ArgumentError.new "#{ output }" - end end class Owner - attr_reader :last_name, :first_name, :street_address, :city, :state def initialize( - id = nil, last_name = nil, first_name = nil, street_address = nil, city = nil, state = nil) @@ -118,11 +114,9 @@ def initialize( @street_address = street_address @city = city @state = state - end def self.all - owners = [] CSV.open("support/owners.csv").each do |owner| owners << Bank::Owner.new( @@ -132,11 +126,9 @@ def self.all end return owners - end def self.find(id) - @owner = nil CSV.open("support/owners.csv").each do |owner| if owner[0].to_i == id @@ -145,7 +137,6 @@ def self.find(id) owner[2], owner[3], owner[4], owner[5]) end - end if @owner == nil @@ -153,7 +144,7 @@ def self.find(id) else return @owner end - + end end diff --git a/lib/checking_account.rb b/lib/checking_account.rb index f5e7f0e9..6bbd248b 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -3,14 +3,11 @@ module Bank class CheckingAccount < Account def initialize(id, balance, opendate = nil) - super @check_withdrawals = 0 - end def withdraw(withdrawal_amount) - original_balance = balance super @@ -23,7 +20,6 @@ def withdraw(withdrawal_amount) else withdrawal_fee end - end def withdrawal_fee @@ -31,7 +27,6 @@ def withdrawal_fee end def withdraw_using_check(withdrawal_amount) - withdraw_positive(withdrawal_amount) if @balance - withdrawal_amount < -10 @@ -43,17 +38,14 @@ def withdraw_using_check(withdrawal_amount) @balance -= withdrawal_amount check_fee - end def check_fee - if @check_withdrawals > 3 @balance -= 2 else @balance end - end def reset_checks diff --git a/lib/money_market_account.rb b/lib/money_market_account.rb index c7d9b6fc..4ce7bf07 100644 --- a/lib/money_market_account.rb +++ b/lib/money_market_account.rb @@ -3,6 +3,9 @@ module Bank class MoneyMarketAccount < Bank::Account + + include Interest + attr_reader :total_transactions def initialize(id, balance, opendate = nil) @@ -11,8 +14,6 @@ def initialize(id, balance, opendate = nil) end def set_balance(start_balance) - # IF the initial balance is < 10,000 - #raise an argument error. if start_balance < 10000 argument("You cannot initialize a new Money Market account with less than 10k.") else @@ -36,11 +37,9 @@ def withdraw(withdrawal_amount) if @balance < 10000 @balance -= 100 end - end def deposit(deposit_amount) - if @balance > 10000 @total_transactions += 1 end @@ -50,24 +49,12 @@ def deposit(deposit_amount) end super - end def reset_transactions @total_transactions = 0 end - def add_interest(rate) - - argument("Interest rate >=0") if rate < 0 - - interest = @balance * (rate/100) - @balance += interest - - return interest - - end - end end diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 4b435951..35867e69 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -2,47 +2,34 @@ module Bank class SavingsAccount < Account - def initialize(id, balance, opendate = nil) + include Interest + def initialize(id, balance, opendate = nil) super if @balance < 10 argument("You must initially deposit at least $10.00") end - end def withdraw(withdrawal_amount) - - original_balance = @balance + original_balance = balance super - if @balance == original_balance + if balance == original_balance balance - elsif @balance - 2 <= 10 + elsif balance - 2 <= 10 puts "This withdrawal and fee will take your balance below $10." - return @balance = original_balance + @balance = original_balance else withdrawal_fee end - end def withdrawal_fee @balance -= 2 end - def add_interest(rate) - - argument("Interest rate must be >= 0") if rate < 0 - - interest = @balance * (rate/100) - @balance += interest - - return interest - - end - end end