From 0a60d6539d0d86be0ed6b9175b52815a6c8e345e Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Tue, 21 Feb 2017 18:09:53 -0800 Subject: [PATCH 01/20] Meets all Wave 1 requirements --- lib/account.rb | 27 +++++++++++++++++++++++++++ specs/account_spec.rb | 3 ++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/account.rb b/lib/account.rb index e69de29b..19d0cd11 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -0,0 +1,27 @@ +# Janice Lichtman's Bank Accounts - Wave 1 + +module Bank + class Account + attr_reader :id, :balance + + def initialize(id, balance) + raise ArgumentError.new("balance must be >= 0") if balance < 0 + @id = id + @balance = balance + end + + def withdraw(withdrawal_amount) + raise ArgumentError.new("Withdrawal amount must be >= 0") if withdrawal_amount < 0 + if withdrawal_amount > @balance + puts "You don't have enough in your account to withdraw that amount!" + else @balance -= withdrawal_amount + end + return @balance + end + + def deposit(deposit_amount) + raise ArgumentError.new("Deposit amount must be >= 0") if deposit_amount < 0 + @balance += deposit_amount + end + end +end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 6c399139..1c5511b1 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -67,7 +67,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 @@ -136,6 +136,7 @@ end end + # TODO: change 'xdescribe' to 'describe' to run these tests xdescribe "Wave 2" do describe "Account.all" do From 03898588c91bf3997f7d0e17db5a5c7d6d3e1b6b Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Tue, 21 Feb 2017 18:12:01 -0800 Subject: [PATCH 02/20] Setting up files for Wave 1 optionals --- lib/owner.rb | 0 specs/owner_spec.rb | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 lib/owner.rb create mode 100644 specs/owner_spec.rb diff --git a/lib/owner.rb b/lib/owner.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/owner_spec.rb b/specs/owner_spec.rb new file mode 100644 index 00000000..e69de29b From 332d0f4145b2e6dea992bc5b2e575d6e1c6d25ef Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Tue, 21 Feb 2017 20:09:25 -0800 Subject: [PATCH 03/20] Wave 1 optionals are working --- lib/account.rb | 11 +++++++++++ lib/owner.rb | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/account.rb b/lib/account.rb index 19d0cd11..acca312a 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,13 +1,17 @@ # Janice Lichtman's Bank Accounts - Wave 1 +require_relative 'owner' + module Bank class Account attr_reader :id, :balance + attr_accessor :owner def initialize(id, balance) raise ArgumentError.new("balance must be >= 0") if balance < 0 @id = id @balance = balance + end def withdraw(withdrawal_amount) @@ -23,5 +27,12 @@ def deposit(deposit_amount) raise ArgumentError.new("Deposit amount must be >= 0") if deposit_amount < 0 @balance += deposit_amount end + end end + +# acct = Bank::Account.new('4567',100) +# acct.owner = Bank::Owner.new(name:"Janice Lichtman", address:"512A N 46th St, Seattle, WA", birthday:"May 16, 1974", pets_name: "Marshmallo") +# +# puts acct.owner +# puts acct.owner.birthday diff --git a/lib/owner.rb b/lib/owner.rb index e69de29b..564ea775 100644 --- a/lib/owner.rb +++ b/lib/owner.rb @@ -0,0 +1,22 @@ +# Janice Lichtman's Bank Accounts - Wave 1 Optionals + +module Bank + class Owner + attr_reader :name, :address, :birthday, :pets_name + + def initialize(owner_hash) + @name = owner_hash[:name] + @address = owner_hash[:address] + @birthday = owner_hash[:birthday] + @pets_name = owner_hash[:pets_name] + end + end + +end + +#janice = Bank::Owner.new(name:"Janice Lichtman", address:"512A N 46th St, Seattle, WA", birthday:"May 16, 1974", pets_name: "Marshmallo") + +# puts janice.name +# puts janice.address +# puts janice.birthday +# puts janice.pets_name From 184d37b8e8885c90d52dee22435b0901a3a3eb27 Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Wed, 22 Feb 2017 09:14:42 -0800 Subject: [PATCH 04/20] Improved tests for an owner associated with an account. --- dummy_file.rb | 16 ++++++++++++++++ specs/owner_spec.rb | 46 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 dummy_file.rb diff --git a/dummy_file.rb b/dummy_file.rb new file mode 100644 index 00000000..3a529ccc --- /dev/null +++ b/dummy_file.rb @@ -0,0 +1,16 @@ +# die.rb +module Bank + + class Die + def initialize + end + + def roll + return rand(1..6) + end + +end +end + +die = Die.new +puts die diff --git a/specs/owner_spec.rb b/specs/owner_spec.rb index e69de29b..43eb5002 100644 --- a/specs/owner_spec.rb +++ b/specs/owner_spec.rb @@ -0,0 +1,46 @@ +require 'minitest/autorun' +require 'minitest/reporters' +require 'minitest/skip_dsl' +require_relative '../lib/owner' +require_relative '../lib/account' + +describe "Wave 1- optionals" do + + describe "Owner#initialize" do + it "Takes an owner hash" do + janice_hash={name:"Janice Lichtman", address:"512A N 46th St, Seattle, WA", birthday:"May 16, 1974", pets_name: "Marshmallo"} + janice = Bank::Owner.new(janice_hash) + + janice.must_respond_to :name + janice.name.must_equal janice_hash[:name] + + janice.must_respond_to :address + janice.address.must_equal janice_hash[:address] + + janice.must_respond_to :birthday + janice.birthday.must_equal janice_hash[:birthday] + + janice.must_respond_to :pets_name + janice.pets_name.must_equal janice_hash[:pets_name] + end + end + + describe "Adding owner to account" do + it "associates an owner, and the owner's details, with an account" do + janice = Bank::Owner.new(name:"Janice") + janices_account=Bank::Account.new('jans_acct_id',100) + janices_account.owner = janice + + janices_account.owner.name.must_equal "Janice" + end + + it "has an owner of the Owner class" do + janice = Bank::Owner.new(name:"Janice") + janices_account=Bank::Account.new('jans_acct_id',100) + janices_account.owner = janice + + janices_account.owner.must_be_instance_of Bank::Owner + end + end + +end From 578f1880577af70f6c25d323a9d1cfc39de301a2 Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Wed, 22 Feb 2017 18:16:02 -0800 Subject: [PATCH 05/20] Wave 2 requirements met --- lib/account.rb | 41 +++++++++++++++++++++++-- specs/account_spec.rb | 70 +++++++++++++++++++++++++++++-------------- 2 files changed, 85 insertions(+), 26 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index acca312a..2d293f06 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,17 +1,46 @@ # Janice Lichtman's Bank Accounts - Wave 1 require_relative 'owner' +require 'csv' module Bank class Account - attr_reader :id, :balance + attr_reader :id, :balance , :open_date attr_accessor :owner - def initialize(id, balance) + + @@all_accounts = [] + + def initialize(id, balance, open_date='2010-12-21 12:21:12 -0800') raise ArgumentError.new("balance must be >= 0") if balance < 0 @id = id @balance = balance + @open_date = open_date + @@all_accounts << self + end + + def self.read_csv + @@all_accounts = [] + CSV.open("./support/accounts.csv").each do |acct| + self.new(acct[0].to_i, acct[1].to_i, acct[2]) + end + end + + def self.all + @@all_accounts + end + + + def self.find(id) + found_account = "" + @@all_accounts.each do |account| + if account.id == id + found_account = account + end + end + raise ArgumentError.new("That account doesn't exist!") if found_account == "" + return found_account end def withdraw(withdrawal_amount) @@ -31,7 +60,13 @@ def deposit(deposit_amount) end end -# acct = Bank::Account.new('4567',100) + +# puts Bank::Account.all +# acct = Bank::Account.new(1212,1235667,'1999-03-27 11:30:09 -0800') +# puts acct.id +# puts acct.balance +# puts acct.open_date + # acct.owner = Bank::Owner.new(name:"Janice Lichtman", address:"512A N 46th St, Seattle, WA", birthday:"May 16, 1974", pets_name: "Marshmallo") # # puts acct.owner diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 1c5511b1..53b6a515 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -3,6 +3,8 @@ require 'minitest/skip_dsl' require_relative '../lib/account' +#Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new + describe "Wave 1" do describe "Account#initialize" do it "Takes an ID and an initial balance" do @@ -137,36 +139,58 @@ end -# TODO: change 'xdescribe' to 'describe' to run these tests -xdescribe "Wave 2" do +describe "Wave 2" do + describe "Account.all" do - it "Returns an array of all accounts" do - # TODO: Your test code here! - # 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 + it "Returns an array" do + Bank::Account.read_csv + expect(Bank::Account.all).must_be_instance_of Array, "Not an array." end - end - describe "Account.find" do - it "Returns an account that exists" do - # TODO: Your test code here! + it "Returns an array consisting only of accounts" do + Bank::Account.read_csv + Bank::Account.all.each do |account| + account.must_be_instance_of Bank::Account, "Not an instance of Account class." + end end - it "Can find the first account from the CSV" do - # TODO: Your test code here! + it "Returns an array with the correct number of accounts" do + Bank::Account.read_csv + expect(Bank::Account.all.length).must_equal 12, "Wrong number of accounts" end - it "Can find the last account from the CSV" do - # TODO: Your test code here! - end - it "Raises an error for an account that doesn't exist" do - # TODO: Your test code here! - end + it "gives correct values for the ID and balance of the first and last + accounts match what's in the CSV file" do + expect(Bank::Account.all.first.id).must_equal 1212, "ID of first account is incorrect." + expect(Bank::Account.all.first.balance).must_equal 1235667, "ID of first account is incorrect." + expect(Bank::Account.all.last.id).must_equal 15156, "ID of first account is incorrect." + expect(Bank::Account.all.last.balance).must_equal 4356772, "ID of first account is incorrect." + end +end + + +describe "Account.find" do + it "Returns an Account that exists" do + Bank::Account.read_csv + expect(Bank::Account.find(15151)).must_be_instance_of Bank::Account, "Does not return account" + end + + it "Can find the first account from the CSV" do + Bank::Account.read_csv + expect(Bank::Account.find(1212)).must_equal Bank::Account.all.first, "Cannot find first account" + end + + it "Can find the last account from the CSV" do + Bank::Account.read_csv + expect(Bank::Account.find(15156)).must_equal Bank::Account.all.last, "Cannot find last account" + end + + it "Raises an error for an account that doesn't exist" do + Bank::Account.read_csv + proc { + Bank::Account.find(9999999) + }.must_raise ArgumentError end end +end From f19371e8e0961f6b14f0b3f521b087a859ab131d Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Thu, 23 Feb 2017 08:54:55 -0800 Subject: [PATCH 06/20] Improved structure. Still works --- lib/account.rb | 10 ++++++++-- specs/account_spec.rb | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 2d293f06..680ad05a 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -8,7 +8,6 @@ class Account attr_reader :id, :balance , :open_date attr_accessor :owner - @@all_accounts = [] def initialize(id, balance, open_date='2010-12-21 12:21:12 -0800') @@ -19,6 +18,12 @@ def initialize(id, balance, open_date='2010-12-21 12:21:12 -0800') @@all_accounts << self end + + def self.reset_all_accounts_for_test + @@all_accounts = [] + end + + def self.read_csv @@all_accounts = [] CSV.open("./support/accounts.csv").each do |acct| @@ -60,7 +65,8 @@ def deposit(deposit_amount) end end - +# Bank::Account.read_csv +# puts Bank::Account.reset_all_accounts_for_test # puts Bank::Account.all # acct = Bank::Account.new(1212,1235667,'1999-03-27 11:30:09 -0800') # puts acct.id diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 53b6a515..ac567a90 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -43,7 +43,7 @@ account.withdraw(withdrawal_amount) - expected_balance = start_balance - withdrawal_amount + expected_balance = start_balance - withdrawal_amount account.balance.must_equal expected_balance end @@ -143,11 +143,14 @@ describe "Account.all" do it "Returns an array" do + Bank::Account.reset_all_accounts_for_test + Bank::Account.reset_all_accounts_for_test Bank::Account.read_csv expect(Bank::Account.all).must_be_instance_of Array, "Not an array." end it "Returns an array consisting only of accounts" do + Bank::Account.reset_all_accounts_for_test Bank::Account.read_csv Bank::Account.all.each do |account| account.must_be_instance_of Bank::Account, "Not an instance of Account class." @@ -155,6 +158,7 @@ end it "Returns an array with the correct number of accounts" do + Bank::Account.reset_all_accounts_for_test Bank::Account.read_csv expect(Bank::Account.all.length).must_equal 12, "Wrong number of accounts" end @@ -162,9 +166,17 @@ it "gives correct values for the ID and balance of the first and last accounts match what's in the CSV file" do + Bank::Account.reset_all_accounts_for_test + Bank::Account.read_csv expect(Bank::Account.all.first.id).must_equal 1212, "ID of first account is incorrect." + Bank::Account.reset_all_accounts_for_test + Bank::Account.read_csv expect(Bank::Account.all.first.balance).must_equal 1235667, "ID of first account is incorrect." + Bank::Account.reset_all_accounts_for_test + Bank::Account.read_csv expect(Bank::Account.all.last.id).must_equal 15156, "ID of first account is incorrect." + Bank::Account.reset_all_accounts_for_test + Bank::Account.read_csv expect(Bank::Account.all.last.balance).must_equal 4356772, "ID of first account is incorrect." end end @@ -172,21 +184,25 @@ describe "Account.find" do it "Returns an Account that exists" do + Bank::Account.reset_all_accounts_for_test Bank::Account.read_csv expect(Bank::Account.find(15151)).must_be_instance_of Bank::Account, "Does not return account" end it "Can find the first account from the CSV" do + Bank::Account.reset_all_accounts_for_test Bank::Account.read_csv expect(Bank::Account.find(1212)).must_equal Bank::Account.all.first, "Cannot find first account" end it "Can find the last account from the CSV" do + Bank::Account.reset_all_accounts_for_test Bank::Account.read_csv expect(Bank::Account.find(15156)).must_equal Bank::Account.all.last, "Cannot find last account" end it "Raises an error for an account that doesn't exist" do + Bank::Account.reset_all_accounts_for_test Bank::Account.read_csv proc { Bank::Account.find(9999999) From a499f8c9977b86e2203a65882f1927f4327f170a Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Thu, 23 Feb 2017 13:53:29 -0800 Subject: [PATCH 07/20] nicer implementation of find --- lib/account.rb | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 680ad05a..9888deb3 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,7 +1,9 @@ # Janice Lichtman's Bank Accounts - Wave 1 -require_relative 'owner' require 'csv' +require 'date' +require_relative 'owner' + module Bank class Account @@ -27,26 +29,31 @@ def self.reset_all_accounts_for_test def self.read_csv @@all_accounts = [] CSV.open("./support/accounts.csv").each do |acct| - self.new(acct[0].to_i, acct[1].to_i, acct[2]) + acct_date = DateTime.parse(acct[2]) + self.new(acct[0].to_i, acct[1].to_i, acct_date) end end - def self.all @@all_accounts end - def self.find(id) - found_account = "" - @@all_accounts.each do |account| - if account.id == id - found_account = account - end - end - raise ArgumentError.new("That account doesn't exist!") if found_account == "" - return found_account - end + found_accounts = @@all_accounts.select {|acct| acct.id == id} + raise ArgumentError.new("That account doesn't exist!") if found_accounts[0]==nil + return found_accounts[0] + end + + + # found_account = "" + # @@all_accounts.each do |account| + # if account.id == id + # found_account = account + # end + # end + # raise ArgumentError.new("That account doesn't exist!") if found_account == "" + # return found_account + # end def withdraw(withdrawal_amount) raise ArgumentError.new("Withdrawal amount must be >= 0") if withdrawal_amount < 0 @@ -65,7 +72,9 @@ def deposit(deposit_amount) end end -# Bank::Account.read_csv + +Bank::Account.read_csv +Bank::Account.find(1212) # puts Bank::Account.reset_all_accounts_for_test # puts Bank::Account.all # acct = Bank::Account.new(1212,1235667,'1999-03-27 11:30:09 -0800') From 335221fd31a5e0537fd6845a48399e2eeb01af39 Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Thu, 23 Feb 2017 23:54:03 -0800 Subject: [PATCH 08/20] Wave 3 works through checking account withdrawal fee. No withdraw_using_check method yet. --- lib/account.rb | 38 +++++++++------------- lib/checking_account.rb | 25 ++++++++++++++ lib/savings_account.rb | 30 +++++++++++++++++ specs/account_spec.rb | 4 +-- specs/checking_account_spec.rb | 26 +++++++++++---- specs/savings_account_spec.rb | 56 +++++++++++++++++++++++++------- {specs => support}/owner_spec.rb | 0 7 files changed, 135 insertions(+), 44 deletions(-) create mode 100644 lib/checking_account.rb create mode 100644 lib/savings_account.rb rename {specs => support}/owner_spec.rb (100%) diff --git a/lib/account.rb b/lib/account.rb index 9888deb3..10ab106e 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,10 +1,7 @@ -# Janice Lichtman's Bank Accounts - Wave 1 - require 'csv' require 'date' require_relative 'owner' - module Bank class Account attr_reader :id, :balance , :open_date @@ -29,8 +26,10 @@ def self.reset_all_accounts_for_test def self.read_csv @@all_accounts = [] CSV.open("./support/accounts.csv").each do |acct| + acct_id = acct[0].to_i + acct_balance_dollars = acct[1].to_i / 100.0 acct_date = DateTime.parse(acct[2]) - self.new(acct[0].to_i, acct[1].to_i, acct_date) + self.new(acct_id, acct_balance_dollars, acct_date) end end @@ -39,21 +38,11 @@ def self.all end def self.find(id) - found_accounts = @@all_accounts.select {|acct| acct.id == id} - raise ArgumentError.new("That account doesn't exist!") if found_accounts[0]==nil - return found_accounts[0] - end - - - # found_account = "" - # @@all_accounts.each do |account| - # if account.id == id - # found_account = account - # end - # end - # raise ArgumentError.new("That account doesn't exist!") if found_account == "" - # return found_account - # end + found_accounts = @@all_accounts.select {|acct| acct.id == id} + raise ArgumentError.new("That account doesn't exist!") if found_accounts[0]==nil + return found_accounts[0] + end + def withdraw(withdrawal_amount) raise ArgumentError.new("Withdrawal amount must be >= 0") if withdrawal_amount < 0 @@ -72,14 +61,17 @@ def deposit(deposit_amount) end end +# +# acct = Bank::Account.new(1212,1235667,'1999-03-27 11:30:09 -0800') +# Bank::Account.find(1212) +# +# puts acct.balance -Bank::Account.read_csv -Bank::Account.find(1212) # puts Bank::Account.reset_all_accounts_for_test # puts Bank::Account.all -# acct = Bank::Account.new(1212,1235667,'1999-03-27 11:30:09 -0800') + # puts acct.id -# puts acct.balance + # puts acct.open_date # acct.owner = Bank::Owner.new(name:"Janice Lichtman", address:"512A N 46th St, Seattle, WA", birthday:"May 16, 1974", pets_name: "Marshmallo") diff --git a/lib/checking_account.rb b/lib/checking_account.rb new file mode 100644 index 00000000..a475963d --- /dev/null +++ b/lib/checking_account.rb @@ -0,0 +1,25 @@ +require 'csv' +require 'date' +require_relative 'account' + + +module Bank + class CheckingAccount < Account + + def initialize(id, balance, open_date='2010-12-21 12:21:12 -0800') + super(id, balance, open_date) + end + + def withdraw(withdrawal_amount) + raise ArgumentError.new("Withdrawal amount must be >= 0") if withdrawal_amount < 0 + if withdrawal_amount > (@balance - 1) + puts "You don't have enough in your account to withdraw that amount!" + else @balance -= (withdrawal_amount + 1) + end + return @balance + end + + + + end +end diff --git a/lib/savings_account.rb b/lib/savings_account.rb new file mode 100644 index 00000000..6be23e5d --- /dev/null +++ b/lib/savings_account.rb @@ -0,0 +1,30 @@ +require 'csv' +require 'date' +require_relative 'account' + + +module Bank + class SavingsAccount < Account + + def initialize(id, balance, open_date='2010-12-21 12:21:12 -0800') + super(id, balance, open_date) + raise ArgumentError.new("balance must be >= 10") if balance < 10 + end + + def withdraw(withdrawal_amount) + raise ArgumentError.new("Withdrawal amount must be >= 0") if withdrawal_amount < 0 + if withdrawal_amount > (@balance - 12) + puts "You don't have enough in your account to withdraw that amount!" + else @balance -= (withdrawal_amount + 2) + end + return @balance + end + + def add_interest(rate) + raise ArgumentError.new("Interest rate must be > 0") if rate <= 0 + interest = @balance * (rate/100) + @balance += interest + return interest + end + end +end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index ac567a90..3c64ae23 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -171,13 +171,13 @@ expect(Bank::Account.all.first.id).must_equal 1212, "ID of first account is incorrect." Bank::Account.reset_all_accounts_for_test Bank::Account.read_csv - expect(Bank::Account.all.first.balance).must_equal 1235667, "ID of first account is incorrect." + expect(Bank::Account.all.first.balance).must_equal 12356.67, "ID of first account is incorrect." Bank::Account.reset_all_accounts_for_test Bank::Account.read_csv expect(Bank::Account.all.last.id).must_equal 15156, "ID of first account is incorrect." Bank::Account.reset_all_accounts_for_test Bank::Account.read_csv - expect(Bank::Account.all.last.balance).must_equal 4356772, "ID of first account is incorrect." + expect(Bank::Account.all.last.balance).must_equal 43567.72, "ID of first account is incorrect." end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 7f95339e..cf461970 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -1,17 +1,16 @@ require 'minitest/autorun' require 'minitest/reporters' 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 # on Account, we effectively get all that testing for free! # Here we'll only test things that are different. -# TODO: change 'xdescribe' to 'describe' to run these tests -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 @@ -22,11 +21,24 @@ describe "#withdraw" do it "Applies a $1 fee each time" do - # TODO: Your test code here! + start_balance = 100.0 + withdrawal_amount = 25.0 + account = Bank::CheckingAccount.new(1337, start_balance) + account.withdraw(withdrawal_amount) + expected_balance = start_balance - withdrawal_amount - 1 + account.balance.must_equal expected_balance end + it "Doesn't modify the balance if the fee would put it negative" do - # TODO: Your test code here! + start_balance = 100.0 + withdrawal_amount = 99.50 + account = Bank::CheckingAccount.new(1337, start_balance) + updated_balance = account.withdraw(withdrawal_amount) + # Both the value returned and the balance in the account + # must be un-modified. + updated_balance.must_equal start_balance + account.balance.must_equal start_balance end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 3f4d1e4a..6cf36bf8 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -1,9 +1,7 @@ require 'minitest/autorun' require 'minitest/reporters' 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 +9,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 @@ -20,39 +18,73 @@ end it "Requires an initial balance of at least $10" do - # TODO: Your test code here! + proc { + Bank::SavingsAccount.new(1337, 9) + }.must_raise ArgumentError end end + describe "#withdraw" do it "Applies a $2 fee each time" do - # TODO: Your test code here! + start_balance = 100.0 + withdrawal_amount = 25.0 + account = Bank::SavingsAccount.new(1337, start_balance) + account.withdraw(withdrawal_amount) + expected_balance = start_balance - withdrawal_amount - 2 + account.balance.must_equal expected_balance end it "Outputs a warning if the balance would go below $10" do - # TODO: Your test code here! + start_balance = 100.0 + withdrawal_amount = 89 + account = Bank::SavingsAccount.new(1337, start_balance) + proc { + account.withdraw(withdrawal_amount) + }.must_output(/.+/) end + it "Doesn't modify the balance if it would go below $10" do - # TODO: Your test code here! + start_balance = 100.0 + withdrawal_amount = 95 + account = Bank::SavingsAccount.new(1337, start_balance) + updated_balance = account.withdraw(withdrawal_amount) + # Both the value returned and the balance in the account + # must be un-modified. + updated_balance.must_equal start_balance + account.balance.must_equal start_balance end it "Doesn't modify the balance if the fee would put it below $10" do - # TODO: Your test code here! + start_balance = 100.0 + withdrawal_amount = 89 + account = Bank::SavingsAccount.new(1337, start_balance) + updated_balance = account.withdraw(withdrawal_amount) + # Both the value returned and the balance in the account + # must be un-modified. + updated_balance.must_equal start_balance + account.balance.must_equal start_balance end end describe "#add_interest" do it "Returns the interest calculated" do - # TODO: Your test code here! + account = Bank::SavingsAccount.new(1337, 10000) + account.add_interest(0.25).must_equal 25 end it "Updates the balance with calculated interest" do - # TODO: Your test code here! + account = Bank::SavingsAccount.new(1337, 10000) + account.add_interest(0.25) + account.balance.must_equal 10025 end it "Requires a positive rate" do - # TODO: Your test code here! + account = Bank::SavingsAccount.new(1337, 10000) + proc { + account.add_interest(-0.25) + }.must_raise ArgumentError end end end diff --git a/specs/owner_spec.rb b/support/owner_spec.rb similarity index 100% rename from specs/owner_spec.rb rename to support/owner_spec.rb From 25d7bf854cd84d1a6f97671e6f70ae4a3249aec1 Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Fri, 24 Feb 2017 00:10:26 -0800 Subject: [PATCH 09/20] works through basic chek withdrawal. Didn't implement 3 free checks yet. --- lib/checking_account.rb | 17 ++++++++++++ specs/checking_account_spec.rb | 47 +++++++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index a475963d..d461740e 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -19,7 +19,24 @@ def withdraw(withdrawal_amount) return @balance end + def withdraw_using_check(withdrawal_amount) + raise ArgumentError.new("Withdrawal amount must be >= 0") if withdrawal_amount < 0 + if withdrawal_amount > (@balance + 10) + puts "You don't have enough in your account to withdraw that amount, even with your $10 overdraft allowance!" + else @balance -= (withdrawal_amount) + end + return @balance + end + #withdraw_using_check(amount): The input amount gets taken out of the account as a result of a check withdrawal. Returns the updated account balance. + # Allows the account to go into overdraft up to -$10 but not any lower + # The user is allowed three free check uses in one month, but any subsequent use adds a $2 transaction fee + end end + + +account = Bank::CheckingAccount.new(1337, 100) + +puts account.withdraw_using_check(110.01) diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index cf461970..e108137f 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -44,27 +44,62 @@ describe "#withdraw_using_check" do it "Reduces the balance" do - # TODO: Your test code here! + start_balance = 100.0 + withdrawal_amount = 25.0 + account = Bank::CheckingAccount.new(1337, start_balance) + + account.withdraw_using_check(withdrawal_amount) + + expected_balance = start_balance - withdrawal_amount + account.balance.must_equal expected_balance end it "Returns the modified balance" do - # TODO: Your test code here! + start_balance = 100.0 + withdrawal_amount = 25.0 + account = Bank::CheckingAccount.new(1337, start_balance) + + updated_balance = account.withdraw_using_check(withdrawal_amount) + + expected_balance = start_balance - withdrawal_amount + updated_balance.must_equal expected_balance end it "Allows the balance to go down to -$10" do - # TODO: Your test code here! + start_balance = 100.0 + withdrawal_amount = 110.0 + account = Bank::CheckingAccount.new(1337, start_balance) + + updated_balance = account.withdraw_using_check(withdrawal_amount) + + expected_balance = start_balance - withdrawal_amount + updated_balance.must_equal expected_balance end it "Outputs a warning if the account would go below -$10" do - # TODO: Your test code here! + start_balance = 100.0 + withdrawal_amount = 110.01 + account = Bank::CheckingAccount.new(1337, start_balance) + proc { + account.withdraw_using_check(withdrawal_amount) + }.must_output(/.+/) end it "Doesn't modify the balance if the account would go below -$10" do - # TODO: Your test code here! + start_balance = 100.0 + withdrawal_amount = 110.01 + account = Bank::CheckingAccount.new(1337, start_balance) + updated_balance = account.withdraw_using_check(withdrawal_amount) + # Both the value returned and the balance in the account + # must be un-modified. + updated_balance.must_equal start_balance + account.balance.must_equal start_balance end it "Requires a positive withdrawal amount" do - # TODO: Your test code here! + proc { + Bank::Account.new(1337, -100.0) + }.must_raise ArgumentError end it "Allows 3 free uses" do From 45d39eb1ebe3d6120c62f197e2891ffe396e1d94 Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Fri, 24 Feb 2017 00:55:27 -0800 Subject: [PATCH 10/20] Oops. I meant blank --- lib/checking_account.rb | 28 +++++++++++++++++++++------- specs/checking_account_spec.rb | 17 +++++++++++++---- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index d461740e..44e39367 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -4,10 +4,12 @@ module Bank + class CheckingAccount < Account def initialize(id, balance, open_date='2010-12-21 12:21:12 -0800') super(id, balance, open_date) + @free_checks_used = 0 end def withdraw(withdrawal_amount) @@ -21,13 +23,25 @@ def withdraw(withdrawal_amount) def withdraw_using_check(withdrawal_amount) raise ArgumentError.new("Withdrawal amount must be >= 0") if withdrawal_amount < 0 - if withdrawal_amount > (@balance + 10) - puts "You don't have enough in your account to withdraw that amount, even with your $10 overdraft allowance!" - else @balance -= (withdrawal_amount) + + if @free_checks_used < 3 + if withdrawal_amount > (@balance + 10) + puts "You don't have enough in your account to withdraw that amount, even with your $10 overdraft allowance!" + else @balance -= (withdrawal_amount) + @free_checks_used += 1 + end + else + if withdrawal_amount > (@balance + 10 - 2) + puts "You don't have enough in your account to withdraw that amount and pay the check fee, even with your $10 overdraft allowance!" + else @balance -= (withdrawal_amount +2) + end end return @balance end + def reset_checks + @free_checks_used = 0 + end #withdraw_using_check(amount): The input amount gets taken out of the account as a result of a check withdrawal. Returns the updated account balance. # Allows the account to go into overdraft up to -$10 but not any lower @@ -36,7 +50,7 @@ def withdraw_using_check(withdrawal_amount) end end - -account = Bank::CheckingAccount.new(1337, 100) - -puts account.withdraw_using_check(110.01) +# +# account = Bank::CheckingAccount.new(1337, 100) +# +# puts account.withdraw_using_check(110.01) diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index e108137f..b500a105 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -103,17 +103,26 @@ end it "Allows 3 free uses" do - # TODO: Your test code here! + account = Bank::CheckingAccount.new(1337, 100) + withdrawal_amount = 10 + 3.times {account.withdraw_using_check(withdrawal_amount)} + + account.balance.must_equal 70 end it "Applies a $2 fee after the third use" do - # TODO: Your test code here! + account = Bank::CheckingAccount.new(1337, 100) + withdrawal_amount = 10 + 4.times {account.withdraw_using_check(withdrawal_amount)} + + account.balance.must_equal 58 end end describe "#reset_checks" do - it "Can be called without error" do - # TODO: Your test code here! + it "Can be called without error" do + account = Bank::CheckingAccount.new(1337, 100) + account.reset_checks end it "Makes the next three checks free if less than 3 checks had been used" do From 00b1579230c72a25cc9a89badd1a9f899388467b Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Fri, 24 Feb 2017 01:01:33 -0800 Subject: [PATCH 11/20] Files cleaned up. --- lib/account.rb | 18 ------------------ lib/checking_account.rb | 12 +----------- lib/savings_account.rb | 12 ++++++------ 3 files changed, 7 insertions(+), 35 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 10ab106e..8f0e0544 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -60,21 +60,3 @@ def deposit(deposit_amount) end end - -# -# acct = Bank::Account.new(1212,1235667,'1999-03-27 11:30:09 -0800') -# Bank::Account.find(1212) -# -# puts acct.balance - -# puts Bank::Account.reset_all_accounts_for_test -# puts Bank::Account.all - -# puts acct.id - -# puts acct.open_date - -# acct.owner = Bank::Owner.new(name:"Janice Lichtman", address:"512A N 46th St, Seattle, WA", birthday:"May 16, 1974", pets_name: "Marshmallo") -# -# puts acct.owner -# puts acct.owner.birthday diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 44e39367..38fa3cbc 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -33,7 +33,7 @@ def withdraw_using_check(withdrawal_amount) else if withdrawal_amount > (@balance + 10 - 2) puts "You don't have enough in your account to withdraw that amount and pay the check fee, even with your $10 overdraft allowance!" - else @balance -= (withdrawal_amount +2) + else @balance -= (withdrawal_amount + 2) end end return @balance @@ -42,15 +42,5 @@ def withdraw_using_check(withdrawal_amount) def reset_checks @free_checks_used = 0 end - - #withdraw_using_check(amount): The input amount gets taken out of the account as a result of a check withdrawal. Returns the updated account balance. - # Allows the account to go into overdraft up to -$10 but not any lower - # The user is allowed three free check uses in one month, but any subsequent use adds a $2 transaction fee - end end - -# -# account = Bank::CheckingAccount.new(1337, 100) -# -# puts account.withdraw_using_check(110.01) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 6be23e5d..c283a8fc 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -20,11 +20,11 @@ def withdraw(withdrawal_amount) return @balance end - def add_interest(rate) - raise ArgumentError.new("Interest rate must be > 0") if rate <= 0 - interest = @balance * (rate/100) - @balance += interest - return interest - end + def add_interest(rate) + raise ArgumentError.new("Interest rate must be > 0") if rate <= 0 + interest = @balance * (rate/100) + @balance += interest + return interest + end end end From 999a19391d566e28244827112c9b84a4920381c1 Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Fri, 24 Feb 2017 10:32:40 -0800 Subject: [PATCH 12/20] Finished last wave 3 tests. --- specs/checking_account_spec.rb | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index b500a105..90a4a267 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -126,11 +126,31 @@ end it "Makes the next three checks free if less than 3 checks had been used" do - # TODO: Your test code here! + account = Bank::CheckingAccount.new(1337, 100) + withdrawal_amount = 10 + 2.times {account.withdraw_using_check(withdrawal_amount)} + account.reset_checks + 3.times {account.withdraw_using_check(withdrawal_amount)} + account.balance.must_equal 50 end it "Makes the next three checks free if more than 3 checks had been used" do - # TODO: Your test code here! + account = Bank::CheckingAccount.new(1337, 100) + withdrawal_amount = 10 + 4.times {account.withdraw_using_check(withdrawal_amount)} + account.reset_checks + 3.times {account.withdraw_using_check(withdrawal_amount)} + account.balance.must_equal 28 end + + it "Makes ONLY the next three checks free if more than 3 checks had been used" do + account = Bank::CheckingAccount.new(1337, 100) + withdrawal_amount = 10 + 4.times {account.withdraw_using_check(withdrawal_amount)} + account.reset_checks + 4.times {account.withdraw_using_check(withdrawal_amount)} + account.balance.must_equal 16 + end + end end From 0a0d3f2fc525f4a53393b2aef536c445ea92dc39 Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Fri, 24 Feb 2017 11:59:42 -0800 Subject: [PATCH 13/20] Created new branch for Wave 3 Optionals: MoneyMarket --- lib/money_market_account.rb | 16 ++++++++++++++++ specs/checking_account_spec.rb | 16 +++++++++++++++- specs/money_market_account_spec.rb | 26 ++++++++++++++++++++++++++ specs/savings_account_spec.rb | 12 +++++++++++- 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 lib/money_market_account.rb create mode 100644 specs/money_market_account_spec.rb diff --git a/lib/money_market_account.rb b/lib/money_market_account.rb new file mode 100644 index 00000000..0c2a2e1a --- /dev/null +++ b/lib/money_market_account.rb @@ -0,0 +1,16 @@ +require 'csv' +require 'date' +require_relative 'account' + + +module Bank + + class MoneyMarketAccount < Account + + def initialize(id, balance, open_date='2010-12-21 12:21:12 -0800') + super(id, balance, open_date) + raise ArgumentError.new("balance must be >= 10,000") if balance < 10000 + end + + end +end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 90a4a267..d522ad7b 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -3,6 +3,8 @@ require 'minitest/skip_dsl' require_relative '../lib/checking_account' +#Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new + # Because a CheckingAccount is a kind # of Account, and we've already tested a bunch of functionality # on Account, we effectively get all that testing for free! @@ -20,6 +22,18 @@ end describe "#withdraw" do + + #Since withdraw was overridden, must retest the basic functionality + it "Requires a positive withdrawal amount" do + start_balance = 100.0 + withdrawal_amount = -25.0 + account = Bank::CheckingAccount.new(1337, start_balance) + proc { + account.withdraw(withdrawal_amount) + }.must_raise ArgumentError + end + + it "Applies a $1 fee each time" do start_balance = 100.0 withdrawal_amount = 25.0 @@ -120,7 +134,7 @@ end describe "#reset_checks" do - it "Can be called without error" do + it "Can be called without error" do account = Bank::CheckingAccount.new(1337, 100) account.reset_checks end diff --git a/specs/money_market_account_spec.rb b/specs/money_market_account_spec.rb new file mode 100644 index 00000000..8758da49 --- /dev/null +++ b/specs/money_market_account_spec.rb @@ -0,0 +1,26 @@ +require 'minitest/autorun' +require 'minitest/reporters' +require 'minitest/skip_dsl' +require_relative '../lib/money_market_account' + +#Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new + + +describe "MoneyMarketAccount" do + + describe "#initialize" do + + # Check that a MoneyMarketAccount is in fact a kind of account + it "Is a kind of Account" do + account = Bank::MoneyMarketAccount.new(12345, 10000) + account.must_be_kind_of Bank::Account + end + + it "Requires an initial balance of at least $10,000" do + proc { + Bank::MoneyMarketAccount.new(1337, 9999) + }.must_raise ArgumentError + end + + end +end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 6cf36bf8..186bdb33 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -8,7 +8,6 @@ # on Account, we effectively get all that testing for free! # Here we'll only test things that are different. -# TODO: change 'xdescribe' to 'describe' to run these tests describe "SavingsAccount" do describe "#initialize" do it "Is a kind of Account" do @@ -26,6 +25,17 @@ describe "#withdraw" do + + #Since withdraw was overridden, must retest the basic functionality + it "Requires a positive withdrawal amount" do + start_balance = 100.0 + withdrawal_amount = -25.0 + account = Bank::SavingsAccount.new(1337, start_balance) + proc { + account.withdraw(withdrawal_amount) + }.must_raise ArgumentError + end + it "Applies a $2 fee each time" do start_balance = 100.0 withdrawal_amount = 25.0 From 1b511a11160a5f5ed30f7d6e648dd06101adc128 Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Fri, 24 Feb 2017 15:19:30 -0800 Subject: [PATCH 14/20] MoneyMarket includes withdrawal logic --- lib/money_market_account.rb | 41 +++++++++++++++ specs/money_market_account_spec.rb | 82 ++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) diff --git a/lib/money_market_account.rb b/lib/money_market_account.rb index 0c2a2e1a..494ca77b 100644 --- a/lib/money_market_account.rb +++ b/lib/money_market_account.rb @@ -10,6 +10,47 @@ class MoneyMarketAccount < Account def initialize(id, balance, open_date='2010-12-21 12:21:12 -0800') super(id, balance, open_date) raise ArgumentError.new("balance must be >= 10,000") if balance < 10000 + @transactions_used = 0 + @transactions_allowed = true + end + + def transaction_count + @transactions_used + end + + def withdraw(withdrawal_amount) + if @transactions_allowed + + if @transactions_used < 6 + @transactions_used += 1 + super(withdrawal_amount) + if @balance < 10000 + @balance -= 100 + @transactions_allowed = false + puts "Your account is now too low. You must make a deposit to allow more transactions." + return @balance + end + else + puts "You have already used all your transactions this month." + @balance + end + else + puts "Withdrawal not allowed. Account balance is too low. You must make a deposit to re-enable transactions. " + return @balance + end + end + + def deposit(deposit_amount) + + if @transactions_used < 6 + @transactions_used += 1 + super(deposit_amount) + if !(@transactions_allowed) + @transactions_allowed = true + end + else puts "You have already used all your transactions this month." + @balance + end end end diff --git a/specs/money_market_account_spec.rb b/specs/money_market_account_spec.rb index 8758da49..c1869322 100644 --- a/specs/money_market_account_spec.rb +++ b/specs/money_market_account_spec.rb @@ -21,6 +21,88 @@ Bank::MoneyMarketAccount.new(1337, 9999) }.must_raise ArgumentError end + end + + describe "Maximum of 6 transacctions" do + + it "increases the transaction count when either a withdrawal or a deposit is made." do + account = Bank::MoneyMarketAccount.new(12345, 50000) + withdrawal_amount = 100 + deposit_amount = 300 + account.withdraw(withdrawal_amount) + account.deposit(deposit_amount) + account.transaction_count.must_equal 2 + end + + it "Outputs a message when a transaction is attempted after 6 transactions have been made." do + withdrawal_amount = 100 + deposit_amount = 300 + account = Bank::MoneyMarketAccount.new(1337, 50000) + 3.times {account.withdraw(withdrawal_amount)} + 3.times {account.deposit(deposit_amount)} + proc { + account.withdraw(withdrawal_amount) + }.must_output(/.+/) + proc { + account.deposit(deposit_amount) + }.must_output(/.+/) + end + + it "Does not implement a requested transaction or modify the balance after 6 transactions have been made." do + withdrawal_amount = 100 + deposit_amount = 300 + account = Bank::MoneyMarketAccount.new(1337, 50000) + 6.times {account.withdraw(withdrawal_amount)} + updated_balance = account.balance + account.deposit(deposit_amount) + account.withdraw(withdrawal_amount) + account.balance.must_equal updated_balance + end + end + + describe "#withdraw" do + + it "Deducts a $100 fee if the balance would go below $10000" do + start_balance = 11000 + withdrawal_amount = 2000 + account = Bank::MoneyMarketAccount.new(1337, start_balance) + account.withdraw(withdrawal_amount) + updated_balance = start_balance - withdrawal_amount - 100 + account.balance.must_equal updated_balance + end + + it "Outputs a 'disallowed' message if the balance has not been increased using a deposit transaction" do + start_balance = 11000 + withdrawal_amount = 2000 + account = Bank::MoneyMarketAccount.new(1337, start_balance) + account.withdraw(withdrawal_amount) + proc { + account.withdraw(10) + }.must_output(/.+/) + end + + it "Does not change balance upon withdrawal attempt if the balance has not been increased using a deposit transaction" do + start_balance = 11000 + withdrawal_amount = 2000 + account = Bank::MoneyMarketAccount.new(1337, start_balance) + account.withdraw(withdrawal_amount) + updated_balance = account.balance + + account.withdraw(10) + account.balance.must_equal updated_balance + end + + it "Implements new transactions once the balance has been increased using a deposit transaction" do + start_balance = 11000 + withdrawal_amount = 2000 + account = Bank::MoneyMarketAccount.new(1337, start_balance) + account.withdraw(withdrawal_amount) + deposit_amount = 5000 + account.deposit(deposit_amount) + updated_balance = account.balance + account.withdraw(100) + account.balance.must_equal (updated_balance - 100) + end end end From 148a08989b798ad83840cea8d7a6aefe7e82d769 Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Sun, 26 Feb 2017 18:36:02 -0800 Subject: [PATCH 15/20] MoneyMarket has full functionality --- lib/money_market_account.rb | 28 +++++++++++----- specs/money_market_account_spec.rb | 53 +++++++++++++++++++++++++++++- specs/savings_account_spec.rb | 2 +- 3 files changed, 73 insertions(+), 10 deletions(-) diff --git a/lib/money_market_account.rb b/lib/money_market_account.rb index 494ca77b..79fd8c80 100644 --- a/lib/money_market_account.rb +++ b/lib/money_market_account.rb @@ -2,11 +2,11 @@ require 'date' require_relative 'account' - module Bank class MoneyMarketAccount < Account + def initialize(id, balance, open_date='2010-12-21 12:21:12 -0800') super(id, balance, open_date) raise ArgumentError.new("balance must be >= 10,000") if balance < 10000 @@ -18,6 +18,10 @@ def transaction_count @transactions_used end + def reset_transactions + @transactions_used = 0 + end + def withdraw(withdrawal_amount) if @transactions_allowed @@ -41,17 +45,25 @@ def withdraw(withdrawal_amount) end def deposit(deposit_amount) - - if @transactions_used < 6 - @transactions_used += 1 + if !(@transactions_allowed) + @transactions_allowed = true super(deposit_amount) - if !(@transactions_allowed) - @transactions_allowed = true + else + if @transactions_used < 6 + @transactions_used += 1 + super(deposit_amount) + else puts "You have already used all your transactions this month." + @balance end - else puts "You have already used all your transactions this month." - @balance end end + def add_interest(rate) + raise ArgumentError.new("Interest rate must be > 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 c1869322..ec6a0d32 100644 --- a/specs/money_market_account_spec.rb +++ b/specs/money_market_account_spec.rb @@ -58,6 +58,18 @@ account.withdraw(withdrawal_amount) account.balance.must_equal updated_balance end + + it "A deposit performed to reach or exceed the minimum balance of $10,000 is not counted as part of the 6 transactions" do + start_balance = 11050 + withdrawal_amount = 10 + account = Bank::MoneyMarketAccount.new(1337, start_balance) + 5.times {account.withdraw(withdrawal_amount)} + account.withdraw(2000) + updated_balance = account.balance + deposit_amount = 5000 + account.deposit(deposit_amount) + account.balance.must_equal (updated_balance + 5000) + end end describe "#withdraw" do @@ -103,6 +115,45 @@ account.withdraw(100) account.balance.must_equal (updated_balance - 100) end + end + + describe "#reset_transactions" do + it "Can be called without error" do + account = Bank::MoneyMarketAccount.new(1337, 50000) + account.reset_transactions + end + + it "Re-enables transactions after they have been disabled dur to 6 transactions" do + withdrawal_amount = 100 + deposit_amount = 300 + account = Bank::MoneyMarketAccount.new(1337, 50000) + 3.times {account.withdraw(withdrawal_amount)} + 3.times {account.deposit(deposit_amount)} + account.reset_transactions + updated_balance = account.balance + account.withdraw(withdrawal_amount) + account.balance.must_equal (updated_balance - withdrawal_amount) + end + end + + describe "#add_interest" do + it "Returns the interest calculated" do + account = Bank::MoneyMarketAccount.new(1337, 10000) + account.add_interest(0.25).must_equal 25 + end + + it "Updates the balance with calculated interest" do + account = Bank::MoneyMarketAccount.new(1337, 10000) + account.add_interest(0.25) + account.balance.must_equal 10025 + end + + it "Requires a positive rate" do + account = Bank::MoneyMarketAccount.new(1337, 10000) + proc { + account.add_interest(-0.25) + }.must_raise ArgumentError + end + end end -end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 186bdb33..28f3216b 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -25,7 +25,7 @@ describe "#withdraw" do - + #Since withdraw was overridden, must retest the basic functionality it "Requires a positive withdrawal amount" do start_balance = 100.0 From a4254ba548b21aed102ef5e3126d4e94dde5633d Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Sun, 26 Feb 2017 21:46:47 -0800 Subject: [PATCH 16/20] working on wave 2 optionals in a branch called owner --- lib/account.rb | 3 --- lib/owner.rb | 57 ++++++++++++++++++++++++++++++++++--------- specs/account_spec.rb | 3 +-- specs/owner_spec.rb | 52 +++++++++++++++++++++++++++++++++++++++ support/owner_spec.rb | 46 ---------------------------------- 5 files changed, 99 insertions(+), 62 deletions(-) create mode 100644 specs/owner_spec.rb delete mode 100644 support/owner_spec.rb diff --git a/lib/account.rb b/lib/account.rb index 8f0e0544..47ec1e23 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -17,14 +17,11 @@ def initialize(id, balance, open_date='2010-12-21 12:21:12 -0800') @@all_accounts << self end - def self.reset_all_accounts_for_test @@all_accounts = [] end - def self.read_csv - @@all_accounts = [] CSV.open("./support/accounts.csv").each do |acct| acct_id = acct[0].to_i acct_balance_dollars = acct[1].to_i / 100.0 diff --git a/lib/owner.rb b/lib/owner.rb index 564ea775..7495f129 100644 --- a/lib/owner.rb +++ b/lib/owner.rb @@ -2,21 +2,56 @@ module Bank class Owner - attr_reader :name, :address, :birthday, :pets_name + attr_reader :id, :last_name, :first_name, :street_address, :city, :state + + @@all_owners = [] def initialize(owner_hash) - @name = owner_hash[:name] - @address = owner_hash[:address] - @birthday = owner_hash[:birthday] - @pets_name = owner_hash[:pets_name] + @id = owner_hash[:id] + @last_name = owner_hash[:last_name] + @first_name = owner_hash[:first_name] + @street_address = owner_hash[:street_address] + @city = owner_hash[:city] + @state = owner_hash[:state] + @@all_owners << self end - end + + # def self.reset_all_owners_for_test + # @@all_owners = [] + # end + # + # def self.read_csv + # CSV.open("./support/owners.csv").each do |owner| + # owner_id = owner[0].to_i + # owner_last_name = owner[1].to_s + # owner_first_name = owner[2].to_s + # owner_street_address = owner[3].to_s + # owner_city = owner[4].to_s + # owner_state = owner[5].to_s + # self.new(id:owner_id, last_name:owner_last_name, first_name:owner_first_name, street_address:owner_street_address, city:owner_city, state:owner_state) + # end + # end + # + # def self.all + # @@all_owners + # end + + # self.find(id) - returns an instance of Owner where the value of the id field in the CSV matches the passed parameter + + + + + end end -#janice = Bank::Owner.new(name:"Janice Lichtman", address:"512A N 46th St, Seattle, WA", birthday:"May 16, 1974", pets_name: "Marshmallo") +janice_hash={id:12345, last_name:'Lichtman', first_name:'Janice', street_address:'16-28 Radburn Rd', city:'Fair Lawn', state:'NJ'} + +janice = Bank::Owner.new(janice_hash) -# puts janice.name -# puts janice.address -# puts janice.birthday -# puts janice.pets_name +puts janice.id +puts janice.last_name +puts janice.first_name +puts janice.street_address +puts janice.city +puts janice.state diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 3c64ae23..ddf996f9 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -30,7 +30,7 @@ end it "Can be created with a balance of 0" do - # If this raises, the test will fail. No 'must's needed! + #If this raises an error, the test will fail. No 'must's needed! Bank::Account.new(1337, 0) end end @@ -143,7 +143,6 @@ describe "Account.all" do it "Returns an array" do - Bank::Account.reset_all_accounts_for_test Bank::Account.reset_all_accounts_for_test Bank::Account.read_csv expect(Bank::Account.all).must_be_instance_of Array, "Not an array." diff --git a/specs/owner_spec.rb b/specs/owner_spec.rb new file mode 100644 index 00000000..042413eb --- /dev/null +++ b/specs/owner_spec.rb @@ -0,0 +1,52 @@ +require 'minitest/autorun' +require 'minitest/reporters' +require 'minitest/skip_dsl' +require_relative '../lib/owner' +require_relative '../lib/account' + +describe "Wave 1- optionals" do + + describe "Owner#initialize" do + it "Takes an owner hash" do + janice_hash={id:12345, last_name:'Lichtman', first_name:'Janice', street_address:'16-28 Radburn Rd', city:'Fair Lawn', state:'NJ'} + janice = Bank::Owner.new(janice_hash) + + janice.must_respond_to :id + janice.id.must_equal janice_hash[:id] + + janice.must_respond_to :last_name + janice.last_name.must_equal janice_hash[:last_name] + + janice.must_respond_to :first_name + janice.first_name.must_equal janice_hash[:first_name] + + janice.must_respond_to :street_address + janice.street_address.must_equal janice_hash[:street_address] + + janice.must_respond_to :city + janice.city.must_equal janice_hash[:city] + + janice.must_respond_to :state + janice.state.must_equal janice_hash[:state] + end + end + + describe "Adding owner to account" do + it "associates an owner, and the owner's details, with an account" do + janice = Bank::Owner.new(id:12345, first_name:"Janice") + janices_account=Bank::Account.new('jans_acct_id',100) + janices_account.owner = janice + + janices_account.owner.first_name.must_equal "Janice" + end + + it "has an owner of the Owner class" do + janice = Bank::Owner.new(id:12345, first_name:"Janice") + janices_account=Bank::Account.new('jans_acct_id',100) + janices_account.owner = janice + + janices_account.owner.must_be_instance_of Bank::Owner + end + end + +end diff --git a/support/owner_spec.rb b/support/owner_spec.rb deleted file mode 100644 index 43eb5002..00000000 --- a/support/owner_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -require 'minitest/autorun' -require 'minitest/reporters' -require 'minitest/skip_dsl' -require_relative '../lib/owner' -require_relative '../lib/account' - -describe "Wave 1- optionals" do - - describe "Owner#initialize" do - it "Takes an owner hash" do - janice_hash={name:"Janice Lichtman", address:"512A N 46th St, Seattle, WA", birthday:"May 16, 1974", pets_name: "Marshmallo"} - janice = Bank::Owner.new(janice_hash) - - janice.must_respond_to :name - janice.name.must_equal janice_hash[:name] - - janice.must_respond_to :address - janice.address.must_equal janice_hash[:address] - - janice.must_respond_to :birthday - janice.birthday.must_equal janice_hash[:birthday] - - janice.must_respond_to :pets_name - janice.pets_name.must_equal janice_hash[:pets_name] - end - end - - describe "Adding owner to account" do - it "associates an owner, and the owner's details, with an account" do - janice = Bank::Owner.new(name:"Janice") - janices_account=Bank::Account.new('jans_acct_id',100) - janices_account.owner = janice - - janices_account.owner.name.must_equal "Janice" - end - - it "has an owner of the Owner class" do - janice = Bank::Owner.new(name:"Janice") - janices_account=Bank::Account.new('jans_acct_id',100) - janices_account.owner = janice - - janices_account.owner.must_be_instance_of Bank::Owner - end - end - -end From b5ea4d334652d7416ae907bdeac0605642a1bbe7 Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Sun, 26 Feb 2017 22:05:43 -0800 Subject: [PATCH 17/20] Owner.all is complete --- lib/owner.rb | 66 +++++++++++++++++++++++-------------------- specs/account_spec.rb | 6 ++-- specs/owner_spec.rb | 45 +++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 33 deletions(-) diff --git a/lib/owner.rb b/lib/owner.rb index 7495f129..12038ee3 100644 --- a/lib/owner.rb +++ b/lib/owner.rb @@ -1,4 +1,4 @@ -# Janice Lichtman's Bank Accounts - Wave 1 Optionals +require 'csv' module Bank class Owner @@ -17,25 +17,25 @@ def initialize(owner_hash) end - # def self.reset_all_owners_for_test - # @@all_owners = [] - # end - # - # def self.read_csv - # CSV.open("./support/owners.csv").each do |owner| - # owner_id = owner[0].to_i - # owner_last_name = owner[1].to_s - # owner_first_name = owner[2].to_s - # owner_street_address = owner[3].to_s - # owner_city = owner[4].to_s - # owner_state = owner[5].to_s - # self.new(id:owner_id, last_name:owner_last_name, first_name:owner_first_name, street_address:owner_street_address, city:owner_city, state:owner_state) - # end - # end - # - # def self.all - # @@all_owners - # end + def self.reset_all_owners_for_test + @@all_owners = [] + end + + def self.read_csv + CSV.open("./support/owners.csv").each do |owner| + owner_id = owner[0].to_i + owner_last_name = owner[1].to_s + owner_first_name = owner[2].to_s + owner_street_address = owner[3].to_s + owner_city = owner[4].to_s + owner_state = owner[5].to_s + self.new(id:owner_id, last_name:owner_last_name, first_name:owner_first_name, street_address:owner_street_address, city:owner_city, state:owner_state) + end + end + + def self.all + @@all_owners + end # self.find(id) - returns an instance of Owner where the value of the id field in the CSV matches the passed parameter @@ -45,13 +45,19 @@ def initialize(owner_hash) end end -janice_hash={id:12345, last_name:'Lichtman', first_name:'Janice', street_address:'16-28 Radburn Rd', city:'Fair Lawn', state:'NJ'} - -janice = Bank::Owner.new(janice_hash) - -puts janice.id -puts janice.last_name -puts janice.first_name -puts janice.street_address -puts janice.city -puts janice.state +# janice_hash={id:12345, last_name:'Lichtman', first_name:'Janice', street_address:'16-28 Radburn Rd', city:'Fair Lawn', state:'NJ'} +# +# janice = Bank::Owner.new(janice_hash) +# puts Bank::Owner.read_csv +# puts janice.id +# puts janice.last_name +# puts janice.first_name +# puts janice.street_address +# puts janice.city +# puts janice.state +# +# puts Bank::Owner.all +# +# Bank::Owner.reset_all_owners_for_test +# puts "********" +# puts Bank::Owner.all diff --git a/specs/account_spec.rb b/specs/account_spec.rb index ddf996f9..65fd72f6 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -170,13 +170,13 @@ expect(Bank::Account.all.first.id).must_equal 1212, "ID of first account is incorrect." Bank::Account.reset_all_accounts_for_test Bank::Account.read_csv - expect(Bank::Account.all.first.balance).must_equal 12356.67, "ID of first account is incorrect." + expect(Bank::Account.all.first.balance).must_equal 12356.67, "Balance of first account is incorrect." Bank::Account.reset_all_accounts_for_test Bank::Account.read_csv - expect(Bank::Account.all.last.id).must_equal 15156, "ID of first account is incorrect." + expect(Bank::Account.all.last.id).must_equal 15156, "ID of second account is incorrect." Bank::Account.reset_all_accounts_for_test Bank::Account.read_csv - expect(Bank::Account.all.last.balance).must_equal 43567.72, "ID of first account is incorrect." + expect(Bank::Account.all.last.balance).must_equal 43567.72, "Balance of second account is incorrect." end end diff --git a/specs/owner_spec.rb b/specs/owner_spec.rb index 042413eb..ea1c77d3 100644 --- a/specs/owner_spec.rb +++ b/specs/owner_spec.rb @@ -48,5 +48,50 @@ janices_account.owner.must_be_instance_of Bank::Owner end end +end + +describe "Wave 2- optionals" do + + describe "Owner.all" do + it "Returns an array" do + Bank::Owner.reset_all_owners_for_test + Bank::Owner.read_csv + expect(Bank::Owner.all).must_be_instance_of Array, "Not an array." + end + + it "Returns an array consisting only of owners" do + Bank::Owner.reset_all_owners_for_test + Bank::Owner.read_csv + Bank::Owner.all.each do |owner| + owner.must_be_instance_of Bank::Owner, "Not an instance of Account class." + end + end + + it "Returns an array with the correct number of accounts" do + Bank::Owner.reset_all_owners_for_test + Bank::Owner.read_csv + expect(Bank::Owner.all.length).must_equal 12, "Wrong number of accounts" + end + + it "gives correct values for the ID and state of the first and last + accounts match what's in the CSV file" do + Bank::Owner.reset_all_owners_for_test + Bank::Owner.read_csv + expect(Bank::Owner.all.first.id).must_equal 14, "ID of first owner is incorrect." + Bank::Owner.reset_all_owners_for_test + Bank::Owner.read_csv + expect(Bank::Owner.all.first.state).must_equal "Hawaii", "State of first owner is incorrect." + Bank::Owner.reset_all_owners_for_test + Bank::Owner.read_csv + expect(Bank::Owner.all.last.id).must_equal 25, "ID of second owner is incorrect." + Bank::Owner.reset_all_owners_for_test + Bank::Owner.read_csv + expect(Bank::Owner.all.last.state).must_equal "New York", "ID of second owner is incorrect." + end end + +describe "Account.find" do + +end +end From 49c096549f09d1d2962e247c674889afac0b2e4d Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Sun, 26 Feb 2017 22:14:49 -0800 Subject: [PATCH 18/20] Owner.find complete --- lib/owner.rb | 15 +++++++++------ specs/owner_spec.rb | 27 +++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/lib/owner.rb b/lib/owner.rb index 12038ee3..eaa49f9b 100644 --- a/lib/owner.rb +++ b/lib/owner.rb @@ -37,14 +37,15 @@ def self.all @@all_owners end - # self.find(id) - returns an instance of Owner where the value of the id field in the CSV matches the passed parameter - - - - + def self.find(id) + found_accounts = @@all_owners.select {|owner| owner.id.to_i == id.to_i} + raise ArgumentError.new("That account doesn't exist!") if found_accounts[0]==nil + return found_accounts[0] + end end end + # janice_hash={id:12345, last_name:'Lichtman', first_name:'Janice', street_address:'16-28 Radburn Rd', city:'Fair Lawn', state:'NJ'} # # janice = Bank::Owner.new(janice_hash) @@ -58,6 +59,8 @@ def self.all # # puts Bank::Owner.all # -# Bank::Owner.reset_all_owners_for_test +# #Bank::Owner.reset_all_owners_for_test # puts "********" # puts Bank::Owner.all +# +# Bank::Owner.find(25) diff --git a/specs/owner_spec.rb b/specs/owner_spec.rb index ea1c77d3..14b37896 100644 --- a/specs/owner_spec.rb +++ b/specs/owner_spec.rb @@ -88,10 +88,33 @@ Bank::Owner.read_csv expect(Bank::Owner.all.last.state).must_equal "New York", "ID of second owner is incorrect." end - end -describe "Account.find" do +describe "Owner.find" do + it "Returns an Owner that exists" do + Bank::Owner.reset_all_owners_for_test + Bank::Owner.read_csv + expect(Bank::Owner.find(20)).must_be_instance_of Bank::Owner, "Does not return account" + end + + it "Can find the first account from the CSV" do + Bank::Owner.reset_all_owners_for_test + Bank::Owner.read_csv + expect(Bank::Owner.find(14)).must_equal Bank::Owner.all.first, "Cannot find first account" + end + it "Can find the last account from the CSV" do + Bank::Owner.reset_all_owners_for_test + Bank::Owner.read_csv + expect(Bank::Owner.find(25)).must_equal Bank::Owner.all.last, "Cannot find last account" + end + + it "Raises an error for an account that doesn't exist" do + Bank::Owner.reset_all_owners_for_test + Bank::Owner.read_csv + proc { + Bank::Owner.find(9999999) + }.must_raise ArgumentError + end end end From 3946423b65519fb29997527fe059f23ef567724d Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Sun, 26 Feb 2017 23:08:28 -0800 Subject: [PATCH 19/20] accounts and owners linked from account_owners.csv --- lib/account.rb | 46 +++++++++++++++++++++++++++++++++------------- lib/owner.rb | 20 -------------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 47ec1e23..d7285aee 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -17,6 +17,21 @@ def initialize(id, balance, open_date='2010-12-21 12:21:12 -0800') @@all_accounts << self end + + def withdraw(withdrawal_amount) + raise ArgumentError.new("Withdrawal amount must be >= 0") if withdrawal_amount < 0 + if withdrawal_amount > @balance + puts "You don't have enough in your account to withdraw that amount!" + else @balance -= withdrawal_amount + end + return @balance + end + + def deposit(deposit_amount) + raise ArgumentError.new("Deposit amount must be >= 0") if deposit_amount < 0 + @balance += deposit_amount + end + def self.reset_all_accounts_for_test @@all_accounts = [] end @@ -40,20 +55,25 @@ def self.find(id) return found_accounts[0] end + def self.add_owners_to_all_accounts + #self.reset_all_accounts_for_test + #Bank::Owner.reset_all_owners_for_test + self.read_csv + Bank::Owner.read_csv - def withdraw(withdrawal_amount) - raise ArgumentError.new("Withdrawal amount must be >= 0") if withdrawal_amount < 0 - if withdrawal_amount > @balance - puts "You don't have enough in your account to withdraw that amount!" - else @balance -= withdrawal_amount - end - return @balance + account_owners_csv = CSV.open("./support/account_owners.csv") + account_owners_csv.each {|pair| + account_id = pair[0].to_i + owner_id = pair[1].to_i + account = self.find(account_id) + account.owner = Bank::Owner.find(owner_id) + } end - - def deposit(deposit_amount) - raise ArgumentError.new("Deposit amount must be >= 0") if deposit_amount < 0 - @balance += deposit_amount - end - end end + +Bank::Account.add_owners_to_all_accounts +Bank::Account.all.each {|acct| + puts acct.owner.state + +} diff --git a/lib/owner.rb b/lib/owner.rb index eaa49f9b..27c9a6a9 100644 --- a/lib/owner.rb +++ b/lib/owner.rb @@ -44,23 +44,3 @@ def self.find(id) end end end - - -# janice_hash={id:12345, last_name:'Lichtman', first_name:'Janice', street_address:'16-28 Radburn Rd', city:'Fair Lawn', state:'NJ'} -# -# janice = Bank::Owner.new(janice_hash) -# puts Bank::Owner.read_csv -# puts janice.id -# puts janice.last_name -# puts janice.first_name -# puts janice.street_address -# puts janice.city -# puts janice.state -# -# puts Bank::Owner.all -# -# #Bank::Owner.reset_all_owners_for_test -# puts "********" -# puts Bank::Owner.all -# -# Bank::Owner.find(25) From 5ded27778f2c2eb4e40fbcff6494c11cee0ea7bd Mon Sep 17 00:00:00 2001 From: Janice Lichtman Date: Sun, 26 Feb 2017 23:22:19 -0800 Subject: [PATCH 20/20] wave 2 optionals complete with testing --- lib/account.rb | 11 +---------- specs/account_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index d7285aee..c609681a 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -56,8 +56,6 @@ def self.find(id) end def self.add_owners_to_all_accounts - #self.reset_all_accounts_for_test - #Bank::Owner.reset_all_owners_for_test self.read_csv Bank::Owner.read_csv @@ -65,15 +63,8 @@ def self.add_owners_to_all_accounts account_owners_csv.each {|pair| account_id = pair[0].to_i owner_id = pair[1].to_i - account = self.find(account_id) - account.owner = Bank::Owner.find(owner_id) + self.find(account_id).owner = Bank::Owner.find(owner_id) } end end end - -Bank::Account.add_owners_to_all_accounts -Bank::Account.all.each {|acct| - puts acct.owner.state - -} diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 65fd72f6..db9cfd9c 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -209,3 +209,19 @@ end end end + +describe "Wave 2 optionals - linkage between acounts and owners" do + + describe "add_owners_to_all_accounts" do + it "adds an owner of type owner to each account" do + Bank::Account.add_owners_to_all_accounts + Bank::Account.find(15151).owner.must_be_instance_of Bank::Owner, "Does not associate an owner with an account" + end + + it "associates the correct owner with each account" do + Bank::Account.add_owners_to_all_accounts + Bank::Account.find(15151).owner.must_equal Bank::Owner.find(17), "Does not associate the correct owner with the tested account" + end + end + +end