From f7f65826528d6a8dbf3a6cf2f26000be5fb8de8a Mon Sep 17 00:00:00 2001 From: ashtn Date: Tue, 21 Feb 2017 15:19:46 -0800 Subject: [PATCH 01/48] Added skip to specs document to create space on terminal& 1st test case passed --- lib/account.rb | 15 +++++++++++++++ specs/account_spec.rb | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/account.rb b/lib/account.rb index e69de29b..61aee7b2 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -0,0 +1,15 @@ +module Bank + + class Account + +@@id = 1336 + attr_reader :id, :balance + + def initialize(id, balance) + @id = @@id +=1 + @balance = balance + end + + end + +end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 6c399139..39ed2791 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -18,6 +18,7 @@ end it "Raises an ArgumentError when created with a negative balance" do + skip # Note: we haven't talked about procs yet. You can think # of them like blocks that sit by themselves. # This code checks that, when the proc is executed, it @@ -28,6 +29,7 @@ end it "Can be created with a balance of 0" do + skip # If this raises, the test will fail. No 'must's needed! Bank::Account.new(1337, 0) end @@ -35,6 +37,7 @@ describe "Account#withdraw" do it "Reduces the balance" do + skip start_balance = 100.0 withdrawal_amount = 25.0 account = Bank::Account.new(1337, start_balance) @@ -46,6 +49,7 @@ end it "Returns the modified balance" do + skip start_balance = 100.0 withdrawal_amount = 25.0 account = Bank::Account.new(1337, start_balance) @@ -57,6 +61,7 @@ end it "Outputs a warning if the account would go negative" do + skip start_balance = 100.0 withdrawal_amount = 200.0 account = Bank::Account.new(1337, start_balance) @@ -71,6 +76,7 @@ end it "Doesn't modify the balance if the account would go negative" do + skip start_balance = 100.0 withdrawal_amount = 200.0 account = Bank::Account.new(1337, start_balance) @@ -84,6 +90,7 @@ end it "Allows the balance to go to 0" do + skip account = Bank::Account.new(1337, 100.0) updated_balance = account.withdraw(account.balance) updated_balance.must_equal 0 @@ -91,6 +98,7 @@ end it "Requires a positive withdrawal amount" do + skip start_balance = 100.0 withdrawal_amount = -25.0 account = Bank::Account.new(1337, start_balance) @@ -103,6 +111,7 @@ describe "Account#deposit" do it "Increases the balance" do + skip start_balance = 100.0 deposit_amount = 25.0 account = Bank::Account.new(1337, start_balance) @@ -114,6 +123,7 @@ end it "Returns the modified balance" do + skip start_balance = 100.0 deposit_amount = 25.0 account = Bank::Account.new(1337, start_balance) @@ -125,6 +135,7 @@ end it "Requires a positive deposit amount" do + skip start_balance = 100.0 deposit_amount = -25.0 account = Bank::Account.new(1337, start_balance) @@ -140,6 +151,7 @@ xdescribe "Wave 2" do describe "Account.all" do it "Returns an array of all accounts" do + skip # TODO: Your test code here! # Useful checks might include: # - Account.all returns an array @@ -153,18 +165,22 @@ describe "Account.find" do it "Returns an account that exists" do + skip # TODO: Your test code here! end it "Can find the first account from the CSV" do + skip # TODO: Your test code here! end it "Can find the last account from the CSV" do + skip # TODO: Your test code here! end it "Raises an error for an account that doesn't exist" do + skip # TODO: Your test code here! end end From 0840db6f77d9745b86099f286e4f789183f137d9 Mon Sep 17 00:00:00 2001 From: ashtn Date: Tue, 21 Feb 2017 16:53:27 -0800 Subject: [PATCH 02/48] 2nd test case passed --- lib/account.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 61aee7b2..15554691 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -2,12 +2,19 @@ module Bank class Account -@@id = 1336 attr_reader :id, :balance def initialize(id, balance) - @id = @@id +=1 - @balance = balance + @id = id + + if balance > 0 + @balance = balance + else + raise ArgumentError.new "Account balance should not start with a negative number" + + end + + end end From 858f1115f3b0b8f7e60d39914f00cb7da532e17f Mon Sep 17 00:00:00 2001 From: ashtn Date: Tue, 21 Feb 2017 21:41:29 -0800 Subject: [PATCH 03/48] Fu=irst test case and 3 assertions passed --- specs/account_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 39ed2791..86ac58f8 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -3,9 +3,11 @@ require 'minitest/skip_dsl' require_relative '../lib/account' + + describe "Wave 1" do describe "Account#initialize" do - it "Takes an ID and an initial balance" do + it "Takes an ID and an initial balance" do #this is one test case with 4 assertions id = 1337 balance = 100.0 account = Bank::Account.new(id, balance) @@ -18,7 +20,7 @@ end it "Raises an ArgumentError when created with a negative balance" do - skip + # Note: we haven't talked about procs yet. You can think # of them like blocks that sit by themselves. # This code checks that, when the proc is executed, it @@ -29,7 +31,6 @@ end it "Can be created with a balance of 0" do - skip # If this raises, the test will fail. No 'must's needed! Bank::Account.new(1337, 0) end @@ -37,7 +38,6 @@ describe "Account#withdraw" do it "Reduces the balance" do - skip start_balance = 100.0 withdrawal_amount = 25.0 account = Bank::Account.new(1337, start_balance) From 06dd983e061d424836c636a06d25060a374c933a Mon Sep 17 00:00:00 2001 From: ashtn Date: Tue, 21 Feb 2017 21:42:23 -0800 Subject: [PATCH 04/48] first test case and 3 asserstions passed --- lib/account.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 15554691..5f34c046 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -7,16 +7,18 @@ class Account def initialize(id, balance) @id = id - if balance > 0 + if balance >= 0 @balance = balance else raise ArgumentError.new "Account balance should not start with a negative number" - end + end #end of initialize + + + - end - end + end #end of class -end +end #end of module From 72f2817e135a5bf96a525465aa184e4eca12bb00 Mon Sep 17 00:00:00 2001 From: ashtn Date: Tue, 21 Feb 2017 21:52:14 -0800 Subject: [PATCH 05/48] Withdraw test case passed --- lib/account.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 5f34c046..67b8cbfb 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -15,8 +15,10 @@ def initialize(id, balance) end #end of initialize - - + def withdraw(withdrawal_amount) + @withdrawal_amount = withdrawal_amount + @balance -= @withdrawal_amount + end end #end of class From 241938e237a370b9c3c627741da6b7f2cac40935 Mon Sep 17 00:00:00 2001 From: ashtn Date: Tue, 21 Feb 2017 22:39:42 -0800 Subject: [PATCH 06/48] giving up for now --- lib/account.rb | 13 +++++++++---- specs/account_spec.rb | 3 +-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 67b8cbfb..55f10de8 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -2,7 +2,8 @@ module Bank class Account - attr_reader :id, :balance + attr_reader :id + attr_accessor :withdrawal_amount, :balance def initialize(id, balance) @id = id @@ -16,10 +17,14 @@ def initialize(id, balance) end #end of initialize def withdraw(withdrawal_amount) - @withdrawal_amount = withdrawal_amount - @balance -= @withdrawal_amount - end + if @balance > withdrawal_amount + return @balance -= withdrawal_amount + else + raise ArgumentError.new "Your account is overdrawn" + end + + end #end of withdraw method end #end of class diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 86ac58f8..0a4a77ab 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -49,7 +49,6 @@ end it "Returns the modified balance" do - skip start_balance = 100.0 withdrawal_amount = 25.0 account = Bank::Account.new(1337, start_balance) @@ -61,7 +60,6 @@ end it "Outputs a warning if the account would go negative" do - skip start_balance = 100.0 withdrawal_amount = 200.0 account = Bank::Account.new(1337, start_balance) @@ -73,6 +71,7 @@ proc { account.withdraw(withdrawal_amount) }.must_output /.+/ + end it "Doesn't modify the balance if the account would go negative" do From 0e4b4d96d3bc811104358f815f5c976c342721cd Mon Sep 17 00:00:00 2001 From: ashtn Date: Wed, 22 Feb 2017 09:47:46 -0800 Subject: [PATCH 07/48] Yay, they passed, that pesky put slash print --- lib/account.rb | 23 ++++++++++++++++++----- specs/account_spec.rb | 13 +++++-------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 55f10de8..cb158f58 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -3,7 +3,7 @@ module Bank class Account attr_reader :id - attr_accessor :withdrawal_amount, :balance + attr_accessor :balance def initialize(id, balance) @id = id @@ -17,15 +17,28 @@ def initialize(id, balance) end #end of initialize def withdraw(withdrawal_amount) - - if @balance > withdrawal_amount - return @balance -= withdrawal_amount + if withdrawal_amount < 0 + raise ArgumentError.new "Withdrawal amount cannot be negative number" else - raise ArgumentError.new "Your account is overdrawn" + if @balance < withdrawal_amount + print "Your account is going to be overdrawn" + @balance = @balance + elsif @balance >= withdrawal_amount + return @balance -= withdrawal_amount + end end end #end of withdraw method + def deposit(deposit_amount) + if deposit_amount < 0 + raise ArgumentError.new "Deposit amount cannot be negative number" + else + @balance += deposit_amount + end + + end #end of deposit method + end #end of class end #end of module diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 0a4a77ab..fad4521b 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -70,16 +70,14 @@ # 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 - skip start_balance = 100.0 withdrawal_amount = 200.0 account = Bank::Account.new(1337, start_balance) - updated_balance = account.withdraw(withdrawal_amount) # Both the value returned and the balance in the account @@ -89,7 +87,6 @@ end it "Allows the balance to go to 0" do - skip account = Bank::Account.new(1337, 100.0) updated_balance = account.withdraw(account.balance) updated_balance.must_equal 0 @@ -97,7 +94,7 @@ end it "Requires a positive withdrawal amount" do - skip + start_balance = 100.0 withdrawal_amount = -25.0 account = Bank::Account.new(1337, start_balance) @@ -110,7 +107,7 @@ describe "Account#deposit" do it "Increases the balance" do - skip + start_balance = 100.0 deposit_amount = 25.0 account = Bank::Account.new(1337, start_balance) @@ -122,7 +119,7 @@ end it "Returns the modified balance" do - skip + start_balance = 100.0 deposit_amount = 25.0 account = Bank::Account.new(1337, start_balance) @@ -134,7 +131,7 @@ end it "Requires a positive deposit amount" do - skip + start_balance = 100.0 deposit_amount = -25.0 account = Bank::Account.new(1337, start_balance) From 4e5531ddf609917e0e6154fc9ea27a2fbc2f815b Mon Sep 17 00:00:00 2001 From: ashtn Date: Wed, 22 Feb 2017 17:01:43 -0800 Subject: [PATCH 08/48] Account.all returns an array, so exciteing, but my code is a hot mess --- lib/account.rb | 35 ++++- specs/account_spec.rb | 291 +++++++++++++++++++++--------------------- 2 files changed, 177 insertions(+), 149 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index cb158f58..5c085ac6 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,3 +1,7 @@ + +require 'csv' + + module Bank class Account @@ -5,17 +9,35 @@ class Account attr_reader :id attr_accessor :balance - def initialize(id, balance) - @id = id + def self.all + accounts = [] + CSV.read("support/accounts.csv").each do |row| + account = { + id: row[0], + balance: row[1], + opendatetime: row[2] + } + accounts << Account.new(account) + end + end + + def initialize(account_hash) - if balance >= 0 - @balance = balance + @id = account_hash[:id] + @balance = account_hash[:balance] + @opendatetime = account_hash[:opendatetime] + + + if @balance.to_i >= 0 + @balance = @balance else raise ArgumentError.new "Account balance should not start with a negative number" end end #end of initialize + + def withdraw(withdrawal_amount) if withdrawal_amount < 0 raise ArgumentError.new "Withdrawal amount cannot be negative number" @@ -42,3 +64,8 @@ def deposit(deposit_amount) end #end of class end #end of module + +#puts Bank::Account.all.class +# new_account = Bank::Account.new(id: 1212, balance: 1235667, opendatetime: "1999-03-27 11:30:09 -0800") +# puts new_account +# puts "These are all the Bank accounts: #{Bank::Account.all}" diff --git a/specs/account_spec.rb b/specs/account_spec.rb index fad4521b..c6af4a3d 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -4,179 +4,180 @@ require_relative '../lib/account' - -describe "Wave 1" do - describe "Account#initialize" do - it "Takes an ID and an initial balance" do #this is one test case with 4 assertions - id = 1337 - balance = 100.0 - account = Bank::Account.new(id, balance) - - account.must_respond_to :id - account.id.must_equal id - - account.must_respond_to :balance - account.balance.must_equal balance - end - - it "Raises an ArgumentError when created with a negative balance" do - - # Note: we haven't talked about procs yet. You can think - # of them like blocks that sit by themselves. - # This code checks that, when the proc is executed, it - # raises an ArgumentError. - proc { - Bank::Account.new(1337, -100.0) - }.must_raise ArgumentError - end - - it "Can be created with a balance of 0" do - # If this raises, the test will fail. No 'must's needed! - Bank::Account.new(1337, 0) - end - end - - describe "Account#withdraw" do - it "Reduces the balance" do - start_balance = 100.0 - withdrawal_amount = 25.0 - account = Bank::Account.new(1337, start_balance) - - account.withdraw(withdrawal_amount) - - expected_balance = start_balance - withdrawal_amount - account.balance.must_equal expected_balance - end - - it "Returns the modified balance" do - start_balance = 100.0 - withdrawal_amount = 25.0 - account = Bank::Account.new(1337, start_balance) - - updated_balance = account.withdraw(withdrawal_amount) - - expected_balance = start_balance - withdrawal_amount - updated_balance.must_equal expected_balance - end - - it "Outputs a warning if the account would go negative" do - start_balance = 100.0 - withdrawal_amount = 200.0 - account = Bank::Account.new(1337, start_balance) - - # Another proc! This test expects something to be printed - # to the terminal, using 'must_output'. /.+/ is a regular - # expression matching one or more characters - as long as - # anything at all is printed out the test will pass. - proc { - account.withdraw(withdrawal_amount) - }.must_output(/.+/) - - end - - it "Doesn't modify the balance if the account would go negative" do - start_balance = 100.0 - withdrawal_amount = 200.0 - account = Bank::Account.new(1337, 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 "Allows the balance to go to 0" do - account = Bank::Account.new(1337, 100.0) - updated_balance = account.withdraw(account.balance) - updated_balance.must_equal 0 - account.balance.must_equal 0 - end - - it "Requires a positive withdrawal amount" do - - start_balance = 100.0 - withdrawal_amount = -25.0 - account = Bank::Account.new(1337, start_balance) - - proc { - account.withdraw(withdrawal_amount) - }.must_raise ArgumentError - end - end - - describe "Account#deposit" do - it "Increases the balance" do - - start_balance = 100.0 - deposit_amount = 25.0 - account = Bank::Account.new(1337, start_balance) - - account.deposit(deposit_amount) - - expected_balance = start_balance + deposit_amount - account.balance.must_equal expected_balance - end - - it "Returns the modified balance" do - - start_balance = 100.0 - deposit_amount = 25.0 - account = Bank::Account.new(1337, start_balance) - - updated_balance = account.deposit(deposit_amount) - - expected_balance = start_balance + deposit_amount - updated_balance.must_equal expected_balance - end - - it "Requires a positive deposit amount" do - - start_balance = 100.0 - deposit_amount = -25.0 - account = Bank::Account.new(1337, start_balance) - - proc { - account.deposit(deposit_amount) - }.must_raise ArgumentError - end - end -end +# +# describe "Wave 1" do +# describe "Account#initialize" do +# it "Takes an ID and an initial balance" do #this is one test case with 4 assertions +# id = 1337 +# balance = 100.0 +# account = Bank::Account.new(id, balance) +# +# account.must_respond_to :id +# account.id.must_equal id +# +# account.must_respond_to :balance +# account.balance.must_equal balance +# end +# +# it "Raises an ArgumentError when created with a negative balance" do +# +# # Note: we haven't talked about procs yet. You can think +# # of them like blocks that sit by themselves. +# # This code checks that, when the proc is executed, it +# # raises an ArgumentError. +# proc { +# Bank::Account.new(1337, -100.0) +# }.must_raise ArgumentError +# end +# +# it "Can be created with a balance of 0" do +# # If this raises, the test will fail. No 'must's needed! +# Bank::Account.new(1337, 0) +# end +# end +# +# describe "Account#withdraw" do +# it "Reduces the balance" do +# start_balance = 100.0 +# withdrawal_amount = 25.0 +# account = Bank::Account.new(1337, start_balance) +# +# account.withdraw(withdrawal_amount) +# +# expected_balance = start_balance - withdrawal_amount +# account.balance.must_equal expected_balance +# end +# +# it "Returns the modified balance" do +# start_balance = 100.0 +# withdrawal_amount = 25.0 +# account = Bank::Account.new(1337, start_balance) +# +# updated_balance = account.withdraw(withdrawal_amount) +# +# expected_balance = start_balance - withdrawal_amount +# updated_balance.must_equal expected_balance +# end +# +# it "Outputs a warning if the account would go negative" do +# start_balance = 100.0 +# withdrawal_amount = 200.0 +# account = Bank::Account.new(1337, start_balance) +# +# # Another proc! This test expects something to be printed +# # to the terminal, using 'must_output'. /.+/ is a regular +# # expression matching one or more characters - as long as +# # anything at all is printed out the test will pass. +# proc { +# account.withdraw(withdrawal_amount) +# }.must_output(/.+/) +# +# end +# +# it "Doesn't modify the balance if the account would go negative" do +# start_balance = 100.0 +# withdrawal_amount = 200.0 +# account = Bank::Account.new(1337, 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 "Allows the balance to go to 0" do +# account = Bank::Account.new(1337, 100.0) +# updated_balance = account.withdraw(account.balance) +# updated_balance.must_equal 0 +# account.balance.must_equal 0 +# end +# +# it "Requires a positive withdrawal amount" do +# +# start_balance = 100.0 +# withdrawal_amount = -25.0 +# account = Bank::Account.new(1337, start_balance) +# +# proc { +# account.withdraw(withdrawal_amount) +# }.must_raise ArgumentError +# end +# end +# +# describe "Account#deposit" do +# it "Increases the balance" do +# +# start_balance = 100.0 +# deposit_amount = 25.0 +# account = Bank::Account.new(1337, start_balance) +# +# account.deposit(deposit_amount) +# +# expected_balance = start_balance + deposit_amount +# account.balance.must_equal expected_balance +# end +# +# it "Returns the modified balance" do +# +# start_balance = 100.0 +# deposit_amount = 25.0 +# account = Bank::Account.new(1337, start_balance) +# +# updated_balance = account.deposit(deposit_amount) +# +# expected_balance = start_balance + deposit_amount +# updated_balance.must_equal expected_balance +# end +# +# it "Requires a positive deposit amount" do +# +# start_balance = 100.0 +# deposit_amount = -25.0 +# account = Bank::Account.new(1337, start_balance) +# +# proc { +# account.deposit(deposit_amount) +# }.must_raise ArgumentError +# end +# end +# 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 - skip # TODO: Your test code here! # Useful checks might include: # - Account.all returns an array + Bank::Account.all.class.must_equal Array # - Everything in the array is an Account # - The number of accounts is correct + #Bank::Account.all.length.must_equal 12 # - 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 + xdescribe "Account.find" do it "Returns an account that exists" do - skip + # TODO: Your test code here! end it "Can find the first account from the CSV" do - skip + # TODO: Your test code here! end it "Can find the last account from the CSV" do - skip + # TODO: Your test code here! end it "Raises an error for an account that doesn't exist" do - skip + # TODO: Your test code here! end end From e097a963f4ef46cdc00808183322f01876b12c5d Mon Sep 17 00:00:00 2001 From: ashtn Date: Thu, 23 Feb 2017 07:11:39 -0800 Subject: [PATCH 09/48] refactoring spec code, to account for account hash --- specs/account_spec.rb | 288 +++++++++++++++++++++--------------------- 1 file changed, 147 insertions(+), 141 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index c6af4a3d..e146e2e4 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -4,107 +4,112 @@ require_relative '../lib/account' -# -# describe "Wave 1" do -# describe "Account#initialize" do -# it "Takes an ID and an initial balance" do #this is one test case with 4 assertions -# id = 1337 -# balance = 100.0 -# account = Bank::Account.new(id, balance) -# -# account.must_respond_to :id -# account.id.must_equal id -# -# account.must_respond_to :balance -# account.balance.must_equal balance -# end -# -# it "Raises an ArgumentError when created with a negative balance" do -# -# # Note: we haven't talked about procs yet. You can think -# # of them like blocks that sit by themselves. -# # This code checks that, when the proc is executed, it -# # raises an ArgumentError. -# proc { -# Bank::Account.new(1337, -100.0) -# }.must_raise ArgumentError -# end -# -# it "Can be created with a balance of 0" do -# # If this raises, the test will fail. No 'must's needed! -# Bank::Account.new(1337, 0) -# end -# end -# -# describe "Account#withdraw" do -# it "Reduces the balance" do -# start_balance = 100.0 -# withdrawal_amount = 25.0 -# account = Bank::Account.new(1337, start_balance) -# -# account.withdraw(withdrawal_amount) -# -# expected_balance = start_balance - withdrawal_amount -# account.balance.must_equal expected_balance -# end -# -# it "Returns the modified balance" do -# start_balance = 100.0 -# withdrawal_amount = 25.0 -# account = Bank::Account.new(1337, start_balance) -# -# updated_balance = account.withdraw(withdrawal_amount) -# -# expected_balance = start_balance - withdrawal_amount -# updated_balance.must_equal expected_balance -# end -# -# it "Outputs a warning if the account would go negative" do -# start_balance = 100.0 -# withdrawal_amount = 200.0 -# account = Bank::Account.new(1337, start_balance) -# -# # Another proc! This test expects something to be printed -# # to the terminal, using 'must_output'. /.+/ is a regular -# # expression matching one or more characters - as long as -# # anything at all is printed out the test will pass. -# proc { -# account.withdraw(withdrawal_amount) -# }.must_output(/.+/) -# -# end -# -# it "Doesn't modify the balance if the account would go negative" do -# start_balance = 100.0 -# withdrawal_amount = 200.0 -# account = Bank::Account.new(1337, 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 "Allows the balance to go to 0" do -# account = Bank::Account.new(1337, 100.0) -# updated_balance = account.withdraw(account.balance) -# updated_balance.must_equal 0 -# account.balance.must_equal 0 -# end -# -# it "Requires a positive withdrawal amount" do -# -# start_balance = 100.0 -# withdrawal_amount = -25.0 -# account = Bank::Account.new(1337, start_balance) -# -# proc { -# account.withdraw(withdrawal_amount) -# }.must_raise ArgumentError -# end -# end -# + +describe "Wave 1" do + describe "Account#initialize" do + it "Takes an ID and an initial balance" do #this is one test case with 4 assertions + + account = Bank::Account.new({id: 1337, balance: 100.00}) + + account.must_respond_to :id + #account.id.must_equal id + + account.must_respond_to :balance + #account.balance.must_equal balance + end + + it "Raises an ArgumentError when created with a negative balance" do + + + # Note: we haven't talked about procs yet. You can think + # of them like blocks that sit by themselves. + # This code checks that, when the proc is executed, it + # raises an ArgumentError. + proc { + Bank::Account.new({id: 1337, balance: -100.0}) + }.must_raise ArgumentError + end + + it "Can be created with a balance of 0" do + + # If this raises, the test will fail. No 'must's needed! + Bank::Account.new({id: 1337, balance: 0}) + end + end + + describe "Account#withdraw" do + it "Reduces the balance" do + start_balance = 100.0 + withdrawal_amount = 25.0 + account = Bank::Account.new({id: 1337, balance: start_balance}) + + account.withdraw(withdrawal_amount) + + expected_balance = start_balance - withdrawal_amount + account.balance.must_equal expected_balance + end + + it "Returns the modified balance" do + skip + start_balance = 100.0 + withdrawal_amount = 25.0 + account = Bank::Account.new({id: 1337, balance: start_balance}) + + updated_balance = account.withdraw(withdrawal_amount) + + expected_balance = start_balance - withdrawal_amount + updated_balance.must_equal expected_balance + end + + it "Outputs a warning if the account would go negative" do + + start_balance = 100.0 + withdrawal_amount = 200.0 + account = Bank::Account.new({id: 1337, balance: start_balance}) + + # Another proc! This test expects something to be printed + # to the terminal, using 'must_output'. /.+/ is a regular + # expression matching one or more characters - as long as + # anything at all is printed out the test will pass. + proc { + account.withdraw(withdrawal_amount) + }.must_output(/.+/) + + end + + it "Doesn't modify the balance if the account would go negative" do + + start_balance = 100.0 + withdrawal_amount = 200.0 + account = Bank::Account.new({id: 1337, balance: 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 "Allows the balance to go to 0" do + + account = Bank::Account.new({id: 1337, balance: 100.0}) + updated_balance = account.withdraw(account.balance) + updated_balance.must_equal 0 + account.balance.must_equal 0 + end + + it "Requires a positive withdrawal amount" do + skip + start_balance = 100.0 + withdrawal_amount = -25.0 + account = Bank::Account.new({id: 1337, balance: start_balance}) + + proc { + account.withdraw(withdrawal_amount) + }.must_raise ArgumentError + end + end + # describe "Account#deposit" do # it "Increases the balance" do # @@ -142,43 +147,44 @@ # end # end # end - -# 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! - # Useful checks might include: - # - Account.all returns an array - Bank::Account.all.class.must_equal Array - # - Everything in the array is an Account - # - The number of accounts is correct - #Bank::Account.all.length.must_equal 12 - # - 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 - - xdescribe "Account.find" do - it "Returns an account that exists" do - - # TODO: Your test code here! - end - - it "Can find the first account from the CSV" do - - # TODO: Your test code here! - 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 - end -end +# +# # TODO: change 'xdescribe' to 'describe' to run these tests +# xdescribe "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 +# Bank::Account.all.class.must_equal Array +# # - Everything in the array is an Account +# Bank::Account.all.must_be_instance_of Account.class +# # - The number of accounts is correct +# #Bank::Account.all.length.must_equal 12 +# # - 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 +# +# xdescribe "Account.find" do +# it "Returns an account that exists" do +# +# # TODO: Your test code here! +# end +# +# it "Can find the first account from the CSV" do +# +# # TODO: Your test code here! +# 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 +# end + end From 3c8be930a2de1cffbefda20c7432550010f3969d Mon Sep 17 00:00:00 2001 From: ashtn Date: Thu, 23 Feb 2017 07:15:45 -0800 Subject: [PATCH 10/48] All of wave 1 is refactored for account hash --- specs/account_spec.rb | 80 +++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index e146e2e4..2fac8f57 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -99,7 +99,7 @@ end it "Requires a positive withdrawal amount" do - skip + start_balance = 100.0 withdrawal_amount = -25.0 account = Bank::Account.new({id: 1337, balance: start_balance}) @@ -110,44 +110,44 @@ end end -# describe "Account#deposit" do -# it "Increases the balance" do -# -# start_balance = 100.0 -# deposit_amount = 25.0 -# account = Bank::Account.new(1337, start_balance) -# -# account.deposit(deposit_amount) -# -# expected_balance = start_balance + deposit_amount -# account.balance.must_equal expected_balance -# end -# -# it "Returns the modified balance" do -# -# start_balance = 100.0 -# deposit_amount = 25.0 -# account = Bank::Account.new(1337, start_balance) -# -# updated_balance = account.deposit(deposit_amount) -# -# expected_balance = start_balance + deposit_amount -# updated_balance.must_equal expected_balance -# end -# -# it "Requires a positive deposit amount" do -# -# start_balance = 100.0 -# deposit_amount = -25.0 -# account = Bank::Account.new(1337, start_balance) -# -# proc { -# account.deposit(deposit_amount) -# }.must_raise ArgumentError -# end -# end -# end -# + describe "Account#deposit" do + it "Increases the balance" do + + start_balance = 100.0 + deposit_amount = 25.0 + account = Bank::Account.new({id: 1337, balance: start_balance}) + + account.deposit(deposit_amount) + + expected_balance = start_balance + deposit_amount + account.balance.must_equal expected_balance + end + + it "Returns the modified balance" do + + start_balance = 100.0 + deposit_amount = 25.0 + account = Bank::Account.new({id: 1337, balance: start_balance}) + + updated_balance = account.deposit(deposit_amount) + + expected_balance = start_balance + deposit_amount + updated_balance.must_equal expected_balance + end + + it "Requires a positive deposit amount" do + + start_balance = 100.0 + deposit_amount = -25.0 + account = Bank::Account.new({id: 1337, balance: start_balance}) + + proc { + account.deposit(deposit_amount) + }.must_raise ArgumentError + end + end +end + # # TODO: change 'xdescribe' to 'describe' to run these tests # xdescribe "Wave 2" do # describe "Account.all" do @@ -187,4 +187,4 @@ # # TODO: Your test code here! # end # end - end +# end From 711fc665327d6b64ddff7facc6eee73ca0377313 Mon Sep 17 00:00:00 2001 From: ashtn Date: Thu, 23 Feb 2017 07:34:27 -0800 Subject: [PATCH 11/48] 5 of 6 .all assertions passed --- specs/account_spec.rb | 93 +++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 2fac8f57..555bd452 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -5,7 +5,7 @@ -describe "Wave 1" do +xdescribe "Wave 1" do describe "Account#initialize" do it "Takes an ID and an initial balance" do #this is one test case with 4 assertions @@ -37,7 +37,7 @@ end end - describe "Account#withdraw" do + xdescribe "Account#withdraw" do it "Reduces the balance" do start_balance = 100.0 withdrawal_amount = 25.0 @@ -110,7 +110,7 @@ end end - describe "Account#deposit" do + xdescribe "Account#deposit" do it "Increases the balance" do start_balance = 100.0 @@ -136,7 +136,7 @@ end it "Requires a positive deposit amount" do - + start_balance = 100.0 deposit_amount = -25.0 account = Bank::Account.new({id: 1337, balance: start_balance}) @@ -148,43 +148,48 @@ end end -# # TODO: change 'xdescribe' to 'describe' to run these tests -# xdescribe "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 -# Bank::Account.all.class.must_equal Array -# # - Everything in the array is an Account -# Bank::Account.all.must_be_instance_of Account.class -# # - The number of accounts is correct -# #Bank::Account.all.length.must_equal 12 -# # - 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 -# -# xdescribe "Account.find" do -# it "Returns an account that exists" do -# -# # TODO: Your test code here! -# end -# -# it "Can find the first account from the CSV" do -# -# # TODO: Your test code here! -# 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 -# end -# end +# 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! + # Useful checks might include: + # - Account.all returns an array + Bank::Account.all.class.must_equal Array + # - Everything in the array is an Account + #Bank::Account.new.must_be_instance_of Account.class + # - The number of accounts is correct + Bank::Account.all.length.must_equal 12 + # - The ID and balance of the first and last + # accounts match what's in the CSV file + Bank::Account.all[0][0].must_equal "1212" + Bank::Account.all[0][1].must_equal 1235667 + Bank::Account.all[11][0].must_equal "15156" + Bank::Account.all[11][1].must_equal 4356772 + + # Feel free to split this into multiple tests if needed + end + end + + xdescribe "Account.find" do + it "Returns an account that exists" do + + # TODO: Your test code here! + end + + it "Can find the first account from the CSV" do + + # TODO: Your test code here! + 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 + end +end From 60e056090d3403f35c913ae2b7abb617b6889912 Mon Sep 17 00:00:00 2001 From: ashtn Date: Thu, 23 Feb 2017 07:51:35 -0800 Subject: [PATCH 12/48] Started Account.find - code and test are broken though --- lib/account.rb | 43 +++++++++++++++++++++++++++---------------- specs/account_spec.rb | 13 +++++++------ 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 5c085ac6..93dd4127 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -9,26 +9,14 @@ class Account attr_reader :id attr_accessor :balance - def self.all - accounts = [] - CSV.read("support/accounts.csv").each do |row| - account = { - id: row[0], - balance: row[1], - opendatetime: row[2] - } - accounts << Account.new(account) - end - end def initialize(account_hash) @id = account_hash[:id] - @balance = account_hash[:balance] + @balance = account_hash[:balance].to_f @opendatetime = account_hash[:opendatetime] - - if @balance.to_i >= 0 + if @balance >= 0 @balance = @balance else raise ArgumentError.new "Account balance should not start with a negative number" @@ -36,7 +24,28 @@ def initialize(account_hash) end #end of initialize + def self.all + accounts = [] + CSV.read("support/accounts.csv").each do |row| + account = { + id: row[0], + balance: row[1], + opendatetime: row[2] + } + accounts << Account.new(account) + end + end + + def self.find(account_info) + self.all do |account| + if account.include? account_info + print true + else + print false + end + end + end def withdraw(withdrawal_amount) if withdrawal_amount < 0 @@ -66,6 +75,8 @@ def deposit(deposit_amount) end #end of module #puts Bank::Account.all.class -# new_account = Bank::Account.new(id: 1212, balance: 1235667, opendatetime: "1999-03-27 11:30:09 -0800") -# puts new_account + # new_account = Bank::Account.new(id: 1212, balance: 1235667, opendatetime: "1999-03-27 11:30:09 -0800") + # puts new_account.id + # puts Bank::Account.all.id # puts "These are all the Bank accounts: #{Bank::Account.all}" +Bank::Account.find(id: "1213") diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 555bd452..62aedecd 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -163,32 +163,33 @@ # - The ID and balance of the first and last # accounts match what's in the CSV file Bank::Account.all[0][0].must_equal "1212" - Bank::Account.all[0][1].must_equal 1235667 + Bank::Account.all[0][1].must_equal "1235667" Bank::Account.all[11][0].must_equal "15156" - Bank::Account.all[11][1].must_equal 4356772 + Bank::Account.all[11][1].must_equal "4356772" # Feel free to split this into multiple tests if needed end end - xdescribe "Account.find" do + describe "Account.find" do it "Returns an account that exists" do # TODO: Your test code here! + Bank::Account.find("1213").must_equal true end it "Can find the first account from the CSV" do - + skip # TODO: Your test code here! end it "Can find the last account from the CSV" do - + skip # TODO: Your test code here! end it "Raises an error for an account that doesn't exist" do - + skip # TODO: Your test code here! end end From fff6b5917a37add9a962ff5cc524940dcf4311c5 Mon Sep 17 00:00:00 2001 From: ashtn Date: Thu, 23 Feb 2017 10:20:29 -0800 Subject: [PATCH 13/48] Added before and @accounts to specs, 2 assertions in wave 2 pass --- specs/account_spec.rb | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 62aedecd..1d195c53 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -151,27 +151,35 @@ # TODO: change 'xdescribe' to 'describe' to run these tests describe "Wave 2" do describe "Account.all" do + +before do + @accounts = Bank::Account.all +end + it "Returns an array of all accounts" do # TODO: Your test code here! # Useful checks might include: # - Account.all returns an array - Bank::Account.all.class.must_equal Array + #Bank::Account.all.class.must_equal Array + @accounts.class.must_equal Array # - Everything in the array is an Account - #Bank::Account.new.must_be_instance_of Account.class + @accounts.must_be_instance_of Account + #@accounts.new.must_be_instance_of Account.class # - The number of accounts is correct - Bank::Account.all.length.must_equal 12 + #Bank::Account.all.length.must_equal 12 + @accounts.length.must_equal CSV.read("support/accounts.csv").count # - The ID and balance of the first and last # accounts match what's in the CSV file - Bank::Account.all[0][0].must_equal "1212" - Bank::Account.all[0][1].must_equal "1235667" - Bank::Account.all[11][0].must_equal "15156" - Bank::Account.all[11][1].must_equal "4356772" + #Bank::Account.all[0][0].must_equal "1212" + #Bank::Account.all[0][1].must_equal "1235667" + #Bank::Account.all[11][0].must_equal "15156" + #Bank::Account.all[11][1].must_equal "4356772" # Feel free to split this into multiple tests if needed end end - describe "Account.find" do + xdescribe "Account.find" do it "Returns an account that exists" do # TODO: Your test code here! From 3198a9d850e94c52ea93c337446d77e3c8ee790a Mon Sep 17 00:00:00 2001 From: ashtn Date: Thu, 23 Feb 2017 18:08:34 -0800 Subject: [PATCH 14/48] .find works in .rb file yayyyy --- lib/account.rb | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 93dd4127..93b6648c 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,21 +1,26 @@ require 'csv' +require 'pry' + module Bank class Account - attr_reader :id - attr_accessor :balance + + + + attr_accessor :balance, :id def initialize(account_hash) - @id = account_hash[:id] - @balance = account_hash[:balance].to_f + @id = account_hash[:id].to_i + @balance = account_hash[:balance].to_i #currently this will assign a negaitve number @opendatetime = account_hash[:opendatetime] +#method open_account assign to instance v. if @balance >= 0 @balance = @balance else @@ -24,6 +29,8 @@ def initialize(account_hash) end #end of initialize + +### look into class var. or other way to save accounts def self.all accounts = [] CSV.read("support/accounts.csv").each do |row| @@ -33,18 +40,17 @@ def self.all opendatetime: row[2] } - accounts << Account.new(account) + accounts << Bank::Account.new(account) end + return accounts end - def self.find(account_info) - self.all do |account| - if account.include? account_info - print true - else - print false - end - end + def self.find(id) + + account = Bank::Account.all.find {|row| row.id == id } + binding.pry + return account + end def withdraw(withdrawal_amount) @@ -79,4 +85,4 @@ def deposit(deposit_amount) # puts new_account.id # puts Bank::Account.all.id # puts "These are all the Bank accounts: #{Bank::Account.all}" -Bank::Account.find(id: "1213") +puts Bank::Account.find(1213) From d8a3da01a7aecf25b7e918d1b0d22a65ffeaaa8b Mon Sep 17 00:00:00 2001 From: ashtn Date: Thu, 23 Feb 2017 18:54:53 -0800 Subject: [PATCH 15/48] Whooo return an account that exits, thanks chris --- specs/account_spec.rb | 336 ++++++++++++++++++++++-------------------- 1 file changed, 176 insertions(+), 160 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 1d195c53..84d12352 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -5,185 +5,201 @@ -xdescribe "Wave 1" do - describe "Account#initialize" do - it "Takes an ID and an initial balance" do #this is one test case with 4 assertions +# describe "Wave 1" do +# describe "Account#initialize" do +# it "Takes an ID and an initial balance" do #this is one test case with 4 assertions +# +# account = Bank::Account.new({id: 1337, balance: 100.00}) +# +# account.must_respond_to :id +# account.id.must_equal 1337 +# +# account.must_respond_to :balance +# account.balance.must_equal 100.00 +# end +# +# it "Raises an ArgumentError when created with a negative balance" do +# +# +# # Note: we haven't talked about procs yet. You can think +# # of them like blocks that sit by themselves. +# # This code checks that, when the proc is executed, it +# # raises an ArgumentError. +# proc { +# Bank::Account.new({id: 1337, balance: -100.0}) +# }.must_raise ArgumentError +# end +# +# it "Can be created with a balance of 0" do +# +# # If this raises, the test will fail. No 'must's needed! +# Bank::Account.new({id: 1337, balance: 0}) +# end +# end +# +# describe "Account#withdraw" do +# it "Reduces the balance" do +# start_balance = 100.0 +# withdrawal_amount = 25.0 +# account = Bank::Account.new({id: 1337, balance: start_balance}) +# +# account.withdraw(withdrawal_amount) +# +# expected_balance = start_balance - withdrawal_amount +# account.balance.must_equal expected_balance +# end +# +# it "Returns the modified balance" do +# +# start_balance = 100.0 +# withdrawal_amount = 25.0 +# account = Bank::Account.new({id: 1337, balance: start_balance}) +# +# updated_balance = account.withdraw(withdrawal_amount) +# +# expected_balance = start_balance - withdrawal_amount +# updated_balance.must_equal expected_balance +# end +# +# it "Outputs a warning if the account would go negative" do +# +# start_balance = 100.0 +# withdrawal_amount = 200.0 +# account = Bank::Account.new({id: 1337, balance: start_balance}) +# +# # Another proc! This test expects something to be printed +# # to the terminal, using 'must_output'. /.+/ is a regular +# # expression matching one or more characters - as long as +# # anything at all is printed out the test will pass. +# proc { +# account.withdraw(withdrawal_amount) +# }.must_output(/.+/) +# +# end +# +# it "Doesn't modify the balance if the account would go negative" do +# +# start_balance = 100.0 +# withdrawal_amount = 200.0 +# account = Bank::Account.new({id: 1337, balance: 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 "Allows the balance to go to 0" do +# +# account = Bank::Account.new({id: 1337, balance: 100.0}) +# updated_balance = account.withdraw(account.balance) +# updated_balance.must_equal 0 +# account.balance.must_equal 0 +# end +# +# it "Requires a positive withdrawal amount" do +# +# start_balance = 100.0 +# withdrawal_amount = -25.0 +# account = Bank::Account.new({id: 1337, balance: start_balance}) +# +# proc { +# account.withdraw(withdrawal_amount) +# }.must_raise ArgumentError +# end +# end +# +# describe "Account#deposit" do +# it "Increases the balance" do +# +# start_balance = 100.0 +# deposit_amount = 25.0 +# account = Bank::Account.new({id: 1337, balance: start_balance}) +# +# account.deposit(deposit_amount) +# +# expected_balance = start_balance + deposit_amount +# account.balance.must_equal expected_balance +# end +# +# it "Returns the modified balance" do +# +# start_balance = 100.0 +# deposit_amount = 25.0 +# account = Bank::Account.new({id: 1337, balance: start_balance}) +# +# updated_balance = account.deposit(deposit_amount) +# +# expected_balance = start_balance + deposit_amount +# updated_balance.must_equal expected_balance +# end +# +# it "Requires a positive deposit amount" do +# +# start_balance = 100.0 +# deposit_amount = -25.0 +# account = Bank::Account.new({id: 1337, balance: start_balance}) +# +# proc { +# account.deposit(deposit_amount) +# }.must_raise ArgumentError +# end +# end +# end - account = Bank::Account.new({id: 1337, balance: 100.00}) - - account.must_respond_to :id - #account.id.must_equal id - - account.must_respond_to :balance - #account.balance.must_equal balance - end - - it "Raises an ArgumentError when created with a negative balance" do - - - # Note: we haven't talked about procs yet. You can think - # of them like blocks that sit by themselves. - # This code checks that, when the proc is executed, it - # raises an ArgumentError. - proc { - Bank::Account.new({id: 1337, balance: -100.0}) - }.must_raise ArgumentError - end - - it "Can be created with a balance of 0" do - - # If this raises, the test will fail. No 'must's needed! - Bank::Account.new({id: 1337, balance: 0}) - end - end - - xdescribe "Account#withdraw" do - it "Reduces the balance" do - start_balance = 100.0 - withdrawal_amount = 25.0 - account = Bank::Account.new({id: 1337, balance: start_balance}) - - account.withdraw(withdrawal_amount) - - expected_balance = start_balance - withdrawal_amount - account.balance.must_equal expected_balance - end - - it "Returns the modified balance" do - skip - start_balance = 100.0 - withdrawal_amount = 25.0 - account = Bank::Account.new({id: 1337, balance: start_balance}) - - updated_balance = account.withdraw(withdrawal_amount) - - expected_balance = start_balance - withdrawal_amount - updated_balance.must_equal expected_balance - end - - it "Outputs a warning if the account would go negative" do - - start_balance = 100.0 - withdrawal_amount = 200.0 - account = Bank::Account.new({id: 1337, balance: start_balance}) - - # Another proc! This test expects something to be printed - # to the terminal, using 'must_output'. /.+/ is a regular - # expression matching one or more characters - as long as - # anything at all is printed out the test will pass. - proc { - account.withdraw(withdrawal_amount) - }.must_output(/.+/) +# TODO: change 'xdescribe' to 'describe' to run these tests +describe "Wave 2" do + describe "Account.all" do + before do + @accounts = Bank::Account.all end - it "Doesn't modify the balance if the account would go negative" do - - start_balance = 100.0 - withdrawal_amount = 200.0 - account = Bank::Account.new({id: 1337, balance: 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 + it "Account.all returns an array" do + @accounts.class.must_equal Array end - it "Allows the balance to go to 0" do + # it "Everything in the array is an Account" do + # + # @accounts.each do |account| + # account.must_be_instance_of Bank::Account + # + # #@accounts.must_be_instance_of Account + # #@accounts.new.must_be_instance_of Account.class + # end + # end - account = Bank::Account.new({id: 1337, balance: 100.0}) - updated_balance = account.withdraw(account.balance) - updated_balance.must_equal 0 - account.balance.must_equal 0 + it "The number of accounts is correct" do + #Bank::Account.all.length.must_equal 12 + @accounts.length.must_equal CSV.read("support/accounts.csv").count end - it "Requires a positive withdrawal amount" do + it "the ID and balance of the first and last accounts match what's in the CSV file" do + @accounts[0].id.must_equal 1212 + @accounts[0].balance.must_equal 1235667 + @accounts[11].id.must_equal 15156 + @accounts[11].balance.must_equal 4356772 - start_balance = 100.0 - withdrawal_amount = -25.0 - account = Bank::Account.new({id: 1337, balance: start_balance}) - - proc { - account.withdraw(withdrawal_amount) - }.must_raise ArgumentError + # Feel free to split this into multiple tests if needed end end - xdescribe "Account#deposit" do - it "Increases the balance" do - - start_balance = 100.0 - deposit_amount = 25.0 - account = Bank::Account.new({id: 1337, balance: start_balance}) - - account.deposit(deposit_amount) - - expected_balance = start_balance + deposit_amount - account.balance.must_equal expected_balance - end - - it "Returns the modified balance" do - - start_balance = 100.0 - deposit_amount = 25.0 - account = Bank::Account.new({id: 1337, balance: start_balance}) + describe "Account.find" do - updated_balance = account.deposit(deposit_amount) - - expected_balance = start_balance + deposit_amount - updated_balance.must_equal expected_balance - end - - it "Requires a positive deposit amount" do - - start_balance = 100.0 - deposit_amount = -25.0 - account = Bank::Account.new({id: 1337, balance: start_balance}) - - proc { - account.deposit(deposit_amount) - }.must_raise ArgumentError + before do + @accounts = Bank::Account.all end - end -end -# TODO: change 'xdescribe' to 'describe' to run these tests -describe "Wave 2" do - describe "Account.all" do - -before do - @accounts = Bank::Account.all -end - - it "Returns an array of all accounts" do - # TODO: Your test code here! - # Useful checks might include: - # - Account.all returns an array - #Bank::Account.all.class.must_equal Array - @accounts.class.must_equal Array - # - Everything in the array is an Account - @accounts.must_be_instance_of Account - #@accounts.new.must_be_instance_of Account.class - # - The number of accounts is correct - #Bank::Account.all.length.must_equal 12 - @accounts.length.must_equal CSV.read("support/accounts.csv").count - # - The ID and balance of the first and last - # accounts match what's in the CSV file - #Bank::Account.all[0][0].must_equal "1212" - #Bank::Account.all[0][1].must_equal "1235667" - #Bank::Account.all[11][0].must_equal "15156" - #Bank::Account.all[11][1].must_equal "4356772" + it "Returns an account that exists" do - # Feel free to split this into multiple tests if needed - end - end + account = Bank::Account.find(15155) - xdescribe "Account.find" do - it "Returns an account that exists" do + account.must_be_instance_of Bank::Account + account.id.must_equal 15155 + account.balance.must_equal 999999 + account.opendatetime.must_equal "1990-06-10 13:13:13 -0800" - # TODO: Your test code here! - Bank::Account.find("1213").must_equal true end it "Can find the first account from the CSV" do From 02c15ad539d4c21ef37f8d493c5c20016ea14cbf Mon Sep 17 00:00:00 2001 From: ashtn Date: Thu, 23 Feb 2017 19:19:06 -0800 Subject: [PATCH 16/48] Wave 2 complete --- lib/account.rb | 37 +++++++++++++++++++++---------------- specs/account_spec.rb | 22 +++++++++++++++------- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 93b6648c..b2482f2a 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -11,16 +11,16 @@ class Account - attr_accessor :balance, :id + attr_accessor :balance, :id, :opendatetime def initialize(account_hash) - @id = account_hash[:id].to_i - @balance = account_hash[:balance].to_i #currently this will assign a negaitve number - @opendatetime = account_hash[:opendatetime] + @id = account_hash[:id].to_i + @balance = account_hash[:balance].to_i #currently this will assign a negaitve number + @opendatetime = account_hash[:opendatetime] -#method open_account assign to instance v. + #method open_account assign to instance v. if @balance >= 0 @balance = @balance else @@ -30,27 +30,32 @@ def initialize(account_hash) end #end of initialize -### look into class var. or other way to save accounts + ### look into class var. or other way to save accounts def self.all accounts = [] CSV.read("support/accounts.csv").each do |row| - account = { - id: row[0], - balance: row[1], - opendatetime: row[2] - } + account = { + id: row[0], + balance: row[1], + opendatetime: row[2] + } - accounts << Bank::Account.new(account) + accounts << Bank::Account.new(account) end return accounts end def self.find(id) - account = Bank::Account.all.find {|row| row.id == id } - binding.pry - return account + accounts = Bank::Account.all + accounts.find do |account| + + if account.id == id + return account + end + end + raise ArgumentError.new "#{id} returned no results" end def withdraw(withdrawal_amount) @@ -85,4 +90,4 @@ def deposit(deposit_amount) # puts new_account.id # puts Bank::Account.all.id # puts "These are all the Bank accounts: #{Bank::Account.all}" -puts Bank::Account.find(1213) +#print Bank::Account.find(15115) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 84d12352..0d7f5411 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -203,18 +203,26 @@ end it "Can find the first account from the CSV" do - skip - # TODO: Your test code here! + account = Bank::Account.find(1212) + + account.must_be_instance_of Bank::Account + account.id.must_equal 1212 + account.balance.must_equal 1235667 + account.opendatetime.must_equal "1999-03-27 11:30:09 -0800" + end it "Can find the last account from the CSV" do - skip - # TODO: Your test code here! - end + account = Bank::Account.find(15156) + account.must_be_instance_of Bank::Account + account.id.must_equal 15156 + account.balance.must_equal 4356772 + account.opendatetime.must_equal "1994-11-17 14:04:56 -0800" + end + it "Raises an error for an account that doesn't exist" do - skip - # TODO: Your test code here! + proc {Bank::Account.find(15115)}.must_raise ArgumentError end end end From feecde50a66822b688ff49064acf3e13aaf06277 Mon Sep 17 00:00:00 2001 From: ashtn Date: Thu, 23 Feb 2017 19:21:26 -0800 Subject: [PATCH 17/48] specs uncommented out --- specs/account_spec.rb | 288 +++++++++++++++++++++--------------------- 1 file changed, 144 insertions(+), 144 deletions(-) diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 0d7f5411..4e9bf871 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -5,148 +5,148 @@ -# describe "Wave 1" do -# describe "Account#initialize" do -# it "Takes an ID and an initial balance" do #this is one test case with 4 assertions -# -# account = Bank::Account.new({id: 1337, balance: 100.00}) -# -# account.must_respond_to :id -# account.id.must_equal 1337 -# -# account.must_respond_to :balance -# account.balance.must_equal 100.00 -# end -# -# it "Raises an ArgumentError when created with a negative balance" do -# -# -# # Note: we haven't talked about procs yet. You can think -# # of them like blocks that sit by themselves. -# # This code checks that, when the proc is executed, it -# # raises an ArgumentError. -# proc { -# Bank::Account.new({id: 1337, balance: -100.0}) -# }.must_raise ArgumentError -# end -# -# it "Can be created with a balance of 0" do -# -# # If this raises, the test will fail. No 'must's needed! -# Bank::Account.new({id: 1337, balance: 0}) -# end -# end -# -# describe "Account#withdraw" do -# it "Reduces the balance" do -# start_balance = 100.0 -# withdrawal_amount = 25.0 -# account = Bank::Account.new({id: 1337, balance: start_balance}) -# -# account.withdraw(withdrawal_amount) -# -# expected_balance = start_balance - withdrawal_amount -# account.balance.must_equal expected_balance -# end -# -# it "Returns the modified balance" do -# -# start_balance = 100.0 -# withdrawal_amount = 25.0 -# account = Bank::Account.new({id: 1337, balance: start_balance}) -# -# updated_balance = account.withdraw(withdrawal_amount) -# -# expected_balance = start_balance - withdrawal_amount -# updated_balance.must_equal expected_balance -# end -# -# it "Outputs a warning if the account would go negative" do -# -# start_balance = 100.0 -# withdrawal_amount = 200.0 -# account = Bank::Account.new({id: 1337, balance: start_balance}) -# -# # Another proc! This test expects something to be printed -# # to the terminal, using 'must_output'. /.+/ is a regular -# # expression matching one or more characters - as long as -# # anything at all is printed out the test will pass. -# proc { -# account.withdraw(withdrawal_amount) -# }.must_output(/.+/) -# -# end -# -# it "Doesn't modify the balance if the account would go negative" do -# -# start_balance = 100.0 -# withdrawal_amount = 200.0 -# account = Bank::Account.new({id: 1337, balance: 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 "Allows the balance to go to 0" do -# -# account = Bank::Account.new({id: 1337, balance: 100.0}) -# updated_balance = account.withdraw(account.balance) -# updated_balance.must_equal 0 -# account.balance.must_equal 0 -# end -# -# it "Requires a positive withdrawal amount" do -# -# start_balance = 100.0 -# withdrawal_amount = -25.0 -# account = Bank::Account.new({id: 1337, balance: start_balance}) -# -# proc { -# account.withdraw(withdrawal_amount) -# }.must_raise ArgumentError -# end -# end -# -# describe "Account#deposit" do -# it "Increases the balance" do -# -# start_balance = 100.0 -# deposit_amount = 25.0 -# account = Bank::Account.new({id: 1337, balance: start_balance}) -# -# account.deposit(deposit_amount) -# -# expected_balance = start_balance + deposit_amount -# account.balance.must_equal expected_balance -# end -# -# it "Returns the modified balance" do -# -# start_balance = 100.0 -# deposit_amount = 25.0 -# account = Bank::Account.new({id: 1337, balance: start_balance}) -# -# updated_balance = account.deposit(deposit_amount) -# -# expected_balance = start_balance + deposit_amount -# updated_balance.must_equal expected_balance -# end -# -# it "Requires a positive deposit amount" do -# -# start_balance = 100.0 -# deposit_amount = -25.0 -# account = Bank::Account.new({id: 1337, balance: start_balance}) -# -# proc { -# account.deposit(deposit_amount) -# }.must_raise ArgumentError -# end -# end -# end +describe "Wave 1" do + describe "Account#initialize" do + it "Takes an ID and an initial balance" do #this is one test case with 4 assertions + + account = Bank::Account.new({id: 1337, balance: 100.00}) + + account.must_respond_to :id + account.id.must_equal 1337 + + account.must_respond_to :balance + account.balance.must_equal 100.00 + end + + it "Raises an ArgumentError when created with a negative balance" do + + + # Note: we haven't talked about procs yet. You can think + # of them like blocks that sit by themselves. + # This code checks that, when the proc is executed, it + # raises an ArgumentError. + proc { + Bank::Account.new({id: 1337, balance: -100.0}) + }.must_raise ArgumentError + end + + it "Can be created with a balance of 0" do + + # If this raises, the test will fail. No 'must's needed! + Bank::Account.new({id: 1337, balance: 0}) + end + end + + describe "Account#withdraw" do + it "Reduces the balance" do + start_balance = 100.0 + withdrawal_amount = 25.0 + account = Bank::Account.new({id: 1337, balance: start_balance}) + + account.withdraw(withdrawal_amount) + + expected_balance = start_balance - withdrawal_amount + account.balance.must_equal expected_balance + end + + it "Returns the modified balance" do + + start_balance = 100.0 + withdrawal_amount = 25.0 + account = Bank::Account.new({id: 1337, balance: start_balance}) + + updated_balance = account.withdraw(withdrawal_amount) + + expected_balance = start_balance - withdrawal_amount + updated_balance.must_equal expected_balance + end + + it "Outputs a warning if the account would go negative" do + + start_balance = 100.0 + withdrawal_amount = 200.0 + account = Bank::Account.new({id: 1337, balance: start_balance}) + + # Another proc! This test expects something to be printed + # to the terminal, using 'must_output'. /.+/ is a regular + # expression matching one or more characters - as long as + # anything at all is printed out the test will pass. + proc { + account.withdraw(withdrawal_amount) + }.must_output(/.+/) + + end + + it "Doesn't modify the balance if the account would go negative" do + + start_balance = 100.0 + withdrawal_amount = 200.0 + account = Bank::Account.new({id: 1337, balance: 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 "Allows the balance to go to 0" do + + account = Bank::Account.new({id: 1337, balance: 100.0}) + updated_balance = account.withdraw(account.balance) + updated_balance.must_equal 0 + account.balance.must_equal 0 + end + + it "Requires a positive withdrawal amount" do + + start_balance = 100.0 + withdrawal_amount = -25.0 + account = Bank::Account.new({id: 1337, balance: start_balance}) + + proc { + account.withdraw(withdrawal_amount) + }.must_raise ArgumentError + end + end + + describe "Account#deposit" do + it "Increases the balance" do + + start_balance = 100.0 + deposit_amount = 25.0 + account = Bank::Account.new({id: 1337, balance: start_balance}) + + account.deposit(deposit_amount) + + expected_balance = start_balance + deposit_amount + account.balance.must_equal expected_balance + end + + it "Returns the modified balance" do + + start_balance = 100.0 + deposit_amount = 25.0 + account = Bank::Account.new({id: 1337, balance: start_balance}) + + updated_balance = account.deposit(deposit_amount) + + expected_balance = start_balance + deposit_amount + updated_balance.must_equal expected_balance + end + + it "Requires a positive deposit amount" do + + start_balance = 100.0 + deposit_amount = -25.0 + account = Bank::Account.new({id: 1337, balance: start_balance}) + + proc { + account.deposit(deposit_amount) + }.must_raise ArgumentError + end + end +end # TODO: change 'xdescribe' to 'describe' to run these tests describe "Wave 2" do @@ -220,9 +220,9 @@ account.balance.must_equal 4356772 account.opendatetime.must_equal "1994-11-17 14:04:56 -0800" end - + it "Raises an error for an account that doesn't exist" do - proc {Bank::Account.find(15115)}.must_raise ArgumentError + proc { Bank::Account.find(15115) }.must_raise ArgumentError end end end From 732ff2de3ce4d8777373f1e053ffdb6370666b3e Mon Sep 17 00:00:00 2001 From: ashtn Date: Thu, 23 Feb 2017 23:20:24 -0800 Subject: [PATCH 18/48] Created Savings and Checking class stubs --- lib/account.rb | 3 +++ lib/checking.rb | 11 +++++++++++ lib/savings.rb | 10 ++++++++++ 3 files changed, 24 insertions(+) create mode 100644 lib/checking.rb create mode 100644 lib/savings.rb diff --git a/lib/account.rb b/lib/account.rb index b2482f2a..200cb301 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -10,6 +10,7 @@ class Account + @@accounts = Bank::Account.all attr_accessor :balance, :id, :opendatetime @@ -20,6 +21,7 @@ def initialize(account_hash) @balance = account_hash[:balance].to_i #currently this will assign a negaitve number @opendatetime = account_hash[:opendatetime] + #method open_account assign to instance v. if @balance >= 0 @balance = @balance @@ -91,3 +93,4 @@ def deposit(deposit_amount) # puts Bank::Account.all.id # puts "These are all the Bank accounts: #{Bank::Account.all}" #print Bank::Account.find(15115) +print @@accounts diff --git a/lib/checking.rb b/lib/checking.rb new file mode 100644 index 00000000..d56d756b --- /dev/null +++ b/lib/checking.rb @@ -0,0 +1,11 @@ + +require 'csv' +require 'pry' +require_relative 'account.rb' + + +module Bank + class Checking < Account + + end +end diff --git a/lib/savings.rb b/lib/savings.rb new file mode 100644 index 00000000..1924172c --- /dev/null +++ b/lib/savings.rb @@ -0,0 +1,10 @@ +require 'csv' +require 'pry' +require_relative 'account.rb' + + +module Bank + class Savings < Account + + end +end From c40b4d5df7df0eb85cec6feaf9e7344958599247 Mon Sep 17 00:00:00 2001 From: ashtn Date: Thu, 23 Feb 2017 23:31:59 -0800 Subject: [PATCH 19/48] refactored spec to account for hash, first test passed --- lib/checking.rb | 10 ++++++++-- specs/checking_account_spec.rb | 12 ++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/checking.rb b/lib/checking.rb index d56d756b..59387eaa 100644 --- a/lib/checking.rb +++ b/lib/checking.rb @@ -5,7 +5,13 @@ module Bank - class Checking < Account + class CheckingAccount < Account + + attr_accessor + + def initialize(account_hash) + super + end end -end +end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 7f95339e..36d9a6c0 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' # Because a CheckingAccount is a kind # of Account, and we've already tested a bunch of functionality @@ -11,16 +11,16 @@ # 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 - account = Bank::CheckingAccount.new(12345, 100.0) + account = Bank::CheckingAccount.new({id: 12345, balance: 100.0}) account.must_be_kind_of Bank::Account end end - describe "#withdraw" do + xdescribe "#withdraw" do it "Applies a $1 fee each time" do # TODO: Your test code here! end @@ -30,7 +30,7 @@ end end - describe "#withdraw_using_check" do + xdescribe "#withdraw_using_check" do it "Reduces the balance" do # TODO: Your test code here! end @@ -64,7 +64,7 @@ end end - describe "#reset_checks" do + xdescribe "#reset_checks" do it "Can be called without error" do # TODO: Your test code here! end From d4af7a6a1dc78dceaa73d4934c622b43e5055f3d Mon Sep 17 00:00:00 2001 From: ashtn Date: Thu, 23 Feb 2017 23:35:02 -0800 Subject: [PATCH 20/48] passed first savings account test --- lib/savings.rb | 8 +++++++- specs/savings_account_spec.rb | 10 +++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/savings.rb b/lib/savings.rb index 1924172c..42dc6228 100644 --- a/lib/savings.rb +++ b/lib/savings.rb @@ -4,7 +4,13 @@ module Bank - class Savings < Account + class SavingsAccount < Account + + attr_accessor + + def initialize(account_hash) + super + end end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 3f4d1e4a..c380b3d1 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' # Because a SavingsAccount is a kind # of Account, and we've already tested a bunch of functionality @@ -11,11 +11,11 @@ # 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 - account = Bank::SavingsAccount.new(12345, 100.0) + account = Bank::SavingsAccount.new({id: 12345, balance: 100.0}) account.must_be_kind_of Bank::Account end @@ -24,7 +24,7 @@ end end - describe "#withdraw" do + xdescribe "#withdraw" do it "Applies a $2 fee each time" do # TODO: Your test code here! end @@ -42,7 +42,7 @@ end end - describe "#add_interest" do + xdescribe "#add_interest" do it "Returns the interest calculated" do # TODO: Your test code here! end From e63333ca980bb2288066ce4d0d1ae5913f94dfe3 Mon Sep 17 00:00:00 2001 From: ashtn Date: Thu, 23 Feb 2017 23:46:14 -0800 Subject: [PATCH 21/48] Withdraw test writted for checking account --- specs/checking_account_spec.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 36d9a6c0..90fb70e0 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -12,17 +12,21 @@ # TODO: change 'xdescribe' to 'describe' to run these tests describe "CheckingAccount" do + before do + @account = Bank::CheckingAccount.new({id: 12345, balance: 100.0}) + end + describe "#initialize" do # Check that a CheckingAccount is in fact a kind of account it "Is a kind of Account" do - account = Bank::CheckingAccount.new({id: 12345, balance: 100.0}) - account.must_be_kind_of Bank::Account + + @account.must_be_kind_of Bank::Account end end - xdescribe "#withdraw" do + describe "#withdraw" do it "Applies a $1 fee each time" do - # TODO: Your test code here! + @account.withdraw(20).must_equal 79 end it "Doesn't modify the balance if the fee would put it negative" do From b34ced5ce81a19df97ff7e2e7a56602d5e097e5f Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 00:01:19 -0800 Subject: [PATCH 22/48] Withdraw applies 1 dollar fee in checking --- lib/checking.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/checking.rb b/lib/checking.rb index 59387eaa..1b621b74 100644 --- a/lib/checking.rb +++ b/lib/checking.rb @@ -7,11 +7,22 @@ module Bank class CheckingAccount < Account - attr_accessor + #attr_accessor :balance - def initialize(account_hash) + def initialize(account) super end + def withdraw(amount) + + if @balance - (amount + 1) < 0 + raise ArgumentError.new "Insufficient Funds" + end + + @balance -= (amount + 1) + return @balance + + end + end end From 7eec7edca1a63c13866cae6e56eaf423b7a44fd3 Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 00:15:11 -0800 Subject: [PATCH 23/48] Balance is not modified on attempted overdraft in checking --- lib/checking.rb | 11 ++++++----- specs/checking_account_spec.rb | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/checking.rb b/lib/checking.rb index 1b621b74..194279cb 100644 --- a/lib/checking.rb +++ b/lib/checking.rb @@ -15,13 +15,14 @@ def initialize(account) def withdraw(amount) - if @balance - (amount + 1) < 0 - raise ArgumentError.new "Insufficient Funds" + if @balance - (amount + 1) < 1 + print "Insufficient Funds" + @balnace = @balance + else + @balance -= (amount + 1) + return @balance end - @balance -= (amount + 1) - return @balance - end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 90fb70e0..61561f22 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -30,7 +30,7 @@ end it "Doesn't modify the balance if the fee would put it negative" do - # TODO: Your test code here! + @account.withdraw(110).must_equal 100 end end From 654a604e4575b623fa760ea8b552b1d333ba0cd9 Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 00:23:01 -0800 Subject: [PATCH 24/48] Savings account starting balance less than 10 raises error --- lib/savings.rb | 15 +++++++++++++-- specs/savings_account_spec.rb | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/savings.rb b/lib/savings.rb index 42dc6228..69d35776 100644 --- a/lib/savings.rb +++ b/lib/savings.rb @@ -8,8 +8,19 @@ class SavingsAccount < Account attr_accessor - def initialize(account_hash) - super + def initialize(account) + + @id = account[:id].to_i + @balance = account[:balance].to_i + @opendatetime = account[:opendatetime] + + if @balance >= 10 + @balance = @balance + else + raise ArgumentError.new "Savings Accounts must have an Initial Balance of $10" + end + + end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index c380b3d1..977bf3b4 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -20,7 +20,7 @@ end it "Requires an initial balance of at least $10" do - # TODO: Your test code here! + proc { Bank::SavingsAccount.new({balance: 5})}.must_raise ArgumentError end end From 8920e59d3f4ce4b93e6a2a6e70ee18efb6094622 Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 00:30:53 -0800 Subject: [PATCH 25/48] Savings Withdaw applies 2 dollar fee --- lib/savings.rb | 13 ++++++++++++- specs/savings_account_spec.rb | 7 ++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/savings.rb b/lib/savings.rb index 69d35776..469f5d3b 100644 --- a/lib/savings.rb +++ b/lib/savings.rb @@ -20,8 +20,19 @@ def initialize(account) raise ArgumentError.new "Savings Accounts must have an Initial Balance of $10" end - end + def withdraw(amount) + + if @balance - (amount + 2) < 10 + @balance = @balance + puts "Insufficient Funds" + else + @balance -= (amount + 2) + return @balance + end + + end + end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 977bf3b4..5289ec34 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -25,8 +25,13 @@ end xdescribe "#withdraw" do + + before do + @account = Bank:SavingsAccount.new ({balance: 100}) + end + it "Applies a $2 fee each time" do - # TODO: Your test code here! + @account.withdraw(20).must_equal 88 end it "Outputs a warning if the balance would go below $10" do From 79d1cadb2717525320e5982e409ec08c3713bff8 Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 00:32:33 -0800 Subject: [PATCH 26/48] Outputs warning at attempted overdraft --- specs/savings_account_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 5289ec34..4b05791e 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -35,7 +35,7 @@ end it "Outputs a warning if the balance would go below $10" do - # TODO: Your test code here! + proc {account.withdraw(110)}.must_raise ArgumentError end it "Doesn't modify the balance if it would go below $10" do From bc499cd050d959fa6b3586c0ae099b014d6ba183 Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 00:53:17 -0800 Subject: [PATCH 27/48] Savings withdraw applies 2 dollar fee --- lib/savings.rb | 11 +++++------ specs/savings_account_spec.rb | 12 +++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/savings.rb b/lib/savings.rb index 469f5d3b..6f1b41c0 100644 --- a/lib/savings.rb +++ b/lib/savings.rb @@ -24,15 +24,14 @@ def initialize(account) def withdraw(amount) - if @balance - (amount + 2) < 10 - @balance = @balance + if @balance - (amount + 2) < 10 + #@balance = @balance puts "Insufficient Funds" else - @balance -= (amount + 2) - return @balance + @balance = (@balance - (amount + 2)) + 10 + #return @balance end - end - + end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 4b05791e..526bbf17 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -20,26 +20,28 @@ end it "Requires an initial balance of at least $10" do - proc { Bank::SavingsAccount.new({balance: 5})}.must_raise ArgumentError + proc { Bank::SavingsAccount.new({id: 555555, balance: 5}) }.must_raise ArgumentError end end - xdescribe "#withdraw" do + describe "#withdraw" do before do - @account = Bank:SavingsAccount.new ({balance: 100}) + @account = Bank::SavingsAccount.new({balance: 100}) end it "Applies a $2 fee each time" do + @account.withdraw(20).must_equal 88 end it "Outputs a warning if the balance would go below $10" do - proc {account.withdraw(110)}.must_raise ArgumentError + skip + proc {@account.withdraw(110)}.must_raise ArgumentError end it "Doesn't modify the balance if it would go below $10" do - # TODO: Your test code here! + end it "Doesn't modify the balance if the fee would put it below $10" do From 3f36b436964f9ec75d88e8fc53173592932ce7cd Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 00:57:18 -0800 Subject: [PATCH 28/48] savings outputs warning message on attempted overdraft --- specs/savings_account_spec.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 526bbf17..5dc15c4c 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -31,13 +31,14 @@ end it "Applies a $2 fee each time" do - + @account.withdraw(20).must_equal 88 end it "Outputs a warning if the balance would go below $10" do - skip - proc {@account.withdraw(110)}.must_raise ArgumentError + + proc { @account.withdraw(110) }.must_output(/.+/) + end it "Doesn't modify the balance if it would go below $10" do From 553a1bcd1074e31b7ee2dd4ee47af088115e5397 Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 01:02:10 -0800 Subject: [PATCH 29/48] savings doesnt modify balance at attempted over draft --- specs/savings_account_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 5dc15c4c..188bf1b8 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -38,11 +38,10 @@ it "Outputs a warning if the balance would go below $10" do proc { @account.withdraw(110) }.must_output(/.+/) - end it "Doesn't modify the balance if it would go below $10" do - + @account.withdraw(200).must_equal 100 end it "Doesn't modify the balance if the fee would put it below $10" do From a50dacbd402f6c2ad07f457b39263f20bfa88286 Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 01:03:45 -0800 Subject: [PATCH 30/48] savings fee, will no modify or overdraft account --- specs/savings_account_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 188bf1b8..77f1d128 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -45,7 +45,7 @@ end it "Doesn't modify the balance if the fee would put it below $10" do - # TODO: Your test code here! + @account.withdraw(100).must_equal 100 end end From c354abac45fe3d057c51ea26c9c0e14e6c18af05 Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 01:27:27 -0800 Subject: [PATCH 31/48] check_withdraw reduces balance --- lib/checking.rb | 22 +++++++++++++++++++++- specs/checking_account_spec.rb | 22 +++++++++++++--------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/lib/checking.rb b/lib/checking.rb index 194279cb..d17412e5 100644 --- a/lib/checking.rb +++ b/lib/checking.rb @@ -7,10 +7,11 @@ module Bank class CheckingAccount < Account - #attr_accessor :balance + attr_accessor :balance, :checks def initialize(account) super + @checks = 3 end def withdraw(amount) @@ -25,5 +26,24 @@ def withdraw(amount) end + def check_withdraw(amount) + + check_fee = 0 + + if @checks < 1 + check_fee = 2 + end + + + if @balance - (amount + check_fee) < 10 + print "Insufficient Funds" + @balnace = @balance + else + @balance = @balance - (amount + check_fee) + return @balance + end + + end + end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 61561f22..e3060787 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -34,36 +34,40 @@ end end - xdescribe "#withdraw_using_check" do + describe "#check_withdraw" do + before do + @account = Bank::CheckingAccount.new({balance: 100}) + end + it "Reduces the balance" do - # TODO: Your test code here! + @account.check_withdraw(20).must_equal 80 end - it "Returns the modified balance" do + it "Returns the modified balance" do skip # TODO: Your test code here! end - it "Allows the balance to go down to -$10" do + it "Allows the balance to go down to -$10" do skip # TODO: Your test code here! end - it "Outputs a warning if the account would go below -$10" do + it "Outputs a warning if the account would go below -$10" do skip # TODO: Your test code here! end - it "Doesn't modify the balance if the account would go below -$10" do + it "Doesn't modify the balance if the account would go below -$10" do skip # TODO: Your test code here! end - it "Requires a positive withdrawal amount" do + it "Requires a positive withdrawal amount" do skip # TODO: Your test code here! end - it "Allows 3 free uses" do + it "Allows 3 free uses" do skip # TODO: Your test code here! end - it "Applies a $2 fee after the third use" do + it "Applies a $2 fee after the third use" do skip # TODO: Your test code here! end end From a8ed7ebb0facbe6dae821a92751a12c794a90816 Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 01:31:26 -0800 Subject: [PATCH 32/48] check_withdraw returns modified balance --- specs/checking_account_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index e3060787..aa4fa09d 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -40,11 +40,11 @@ end it "Reduces the balance" do - @account.check_withdraw(20).must_equal 80 + @account.check_withdraw(20).must_be :<, 100 end - it "Returns the modified balance" do skip - # TODO: Your test code here! + it "Returns the modified balance" do + @account.check_withdraw(50).must_equal 50 end it "Allows the balance to go down to -$10" do skip From fc915f239637f0e98ff27a61b1c2fcf281c4597e Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 01:39:15 -0800 Subject: [PATCH 33/48] check_withdraw allows balance to reach -10 --- specs/checking_account_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index aa4fa09d..4c17d520 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -43,12 +43,12 @@ @account.check_withdraw(20).must_be :<, 100 end - it "Returns the modified balance" do + it "Returns the modified balance" do @account.check_withdraw(50).must_equal 50 end - it "Allows the balance to go down to -$10" do skip - # TODO: Your test code here! + it "Allows the balance to go down to -$10" do + @account.check_withdraw(110).must_equal (-10) end it "Outputs a warning if the account would go below -$10" do skip From 5f754b45f7013e33a537e6231fa75580e3859b88 Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 01:40:04 -0800 Subject: [PATCH 34/48] edit to check_withdraw method to allow balance to reach -10 --- lib/checking.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checking.rb b/lib/checking.rb index d17412e5..d097ab70 100644 --- a/lib/checking.rb +++ b/lib/checking.rb @@ -35,7 +35,7 @@ def check_withdraw(amount) end - if @balance - (amount + check_fee) < 10 + if @balance - (amount + check_fee) < (-10) print "Insufficient Funds" @balnace = @balance else From 9229fee70965cddf0faba527d2c3a3b35d3d1cdd Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 01:43:51 -0800 Subject: [PATCH 35/48] test commit with git add . --- lib/account.rb | 19 ++++++++++--------- lib/savings.rb | 4 ++-- specs/account_spec.rb | 4 ++-- specs/checking_account_spec.rb | 4 ++-- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 200cb301..711e7758 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -10,9 +10,10 @@ class Account - @@accounts = Bank::Account.all - attr_accessor :balance, :id, :opendatetime + + + attr_accessor :balance, :id, :opendatetime, :accounts def initialize(account_hash) @@ -20,7 +21,7 @@ def initialize(account_hash) @id = account_hash[:id].to_i @balance = account_hash[:balance].to_i #currently this will assign a negaitve number @opendatetime = account_hash[:opendatetime] - + #@accounts = Bank::Account.all #method open_account assign to instance v. if @balance >= 0 @@ -60,15 +61,15 @@ def self.find(id) raise ArgumentError.new "#{id} returned no results" end - def withdraw(withdrawal_amount) - if withdrawal_amount < 0 + def withdraw(amount) + if amount < 0 raise ArgumentError.new "Withdrawal amount cannot be negative number" else - if @balance < withdrawal_amount + if @balance < amount print "Your account is going to be overdrawn" @balance = @balance - elsif @balance >= withdrawal_amount - return @balance -= withdrawal_amount + elsif @balance >= amount + return @balance -= amount end end @@ -93,4 +94,4 @@ def deposit(deposit_amount) # puts Bank::Account.all.id # puts "These are all the Bank accounts: #{Bank::Account.all}" #print Bank::Account.find(15115) -print @@accounts +#puts @accounts diff --git a/lib/savings.rb b/lib/savings.rb index 6f1b41c0..6091bd06 100644 --- a/lib/savings.rb +++ b/lib/savings.rb @@ -25,11 +25,11 @@ def initialize(account) def withdraw(amount) if @balance - (amount + 2) < 10 - #@balance = @balance puts "Insufficient Funds" + return @balance else @balance = (@balance - (amount + 2)) + 10 - #return @balance + return @balance end end diff --git a/specs/account_spec.rb b/specs/account_spec.rb index 4e9bf871..f0415886 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -5,7 +5,7 @@ -describe "Wave 1" do +xdescribe "Wave 1" do describe "Account#initialize" do it "Takes an ID and an initial balance" do #this is one test case with 4 assertions @@ -149,7 +149,7 @@ end # TODO: change 'xdescribe' to 'describe' to run these tests -describe "Wave 2" do +xdescribe "Wave 2" do describe "Account.all" do before do diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 4c17d520..3eb37de6 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -51,8 +51,8 @@ @account.check_withdraw(110).must_equal (-10) end - it "Outputs a warning if the account would go below -$10" do skip - # TODO: Your test code here! + it "Outputs a warning if the account would go below -$10" do + proc { @account.check_withdraw(200) }.must_output(/.+/) end it "Doesn't modify the balance if the account would go below -$10" do skip From 446e26c458485b00444acbd2f1073ba61215094b Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 01:45:40 -0800 Subject: [PATCH 36/48] checking account doesnt modify account in attempted overdraft --- specs/checking_account_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 3eb37de6..d22cd802 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -51,12 +51,12 @@ @account.check_withdraw(110).must_equal (-10) end - it "Outputs a warning if the account would go below -$10" do + it "Outputs a warning if the account would go below -$10" do proc { @account.check_withdraw(200) }.must_output(/.+/) end - it "Doesn't modify the balance if the account would go below -$10" do skip - # TODO: Your test code here! + it "Doesn't modify the balance if the account would go below -$10" do + @account.check_withdraw(200).must_equal 100 end it "Requires a positive withdrawal amount" do skip From 6497ef843f335063bc8f752538a68d4b361c2d18 Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 01:50:57 -0800 Subject: [PATCH 37/48] check_withdraw requires postive number --- specs/checking_account_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index d22cd802..957872e1 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -55,12 +55,12 @@ proc { @account.check_withdraw(200) }.must_output(/.+/) end - it "Doesn't modify the balance if the account would go below -$10" do + it "Doesn't modify the balance if the account would go below -$10" do @account.check_withdraw(200).must_equal 100 end - it "Requires a positive withdrawal amount" do skip - # TODO: Your test code here! + it "Requires a positive withdrawal amount" do + @account.check_withdraw(-100).must_equal 100 end it "Allows 3 free uses" do skip From 42093a00db8768804648c7c4720fc48928984a00 Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 01:55:30 -0800 Subject: [PATCH 38/48] check_withdraw allow 3 free uses --- specs/checking_account_spec.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 957872e1..29fd41c5 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -60,11 +60,15 @@ end it "Requires a positive withdrawal amount" do - @account.check_withdraw(-100).must_equal 100 + @account.check_withdraw(-100).must_equal 100 end - it "Allows 3 free uses" do skip - # TODO: Your test code here! + it "Allows 3 free uses" do + @account.check_withdraw(20).must_equal 80 + @account.check_withdraw(20).must_equal 60 + @account.check_withdraw(20).must_equal 40 + @account.check_withdraw(20).must_equal 18 + end it "Applies a $2 fee after the third use" do skip From 0e8124091d3b0d899f7cd5b223e2425fa5b29d66 Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 01:58:05 -0800 Subject: [PATCH 39/48] check_withdraw method passed all tests --- specs/checking_account_spec.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 29fd41c5..6e0ef35f 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -63,7 +63,7 @@ @account.check_withdraw(-100).must_equal 100 end - it "Allows 3 free uses" do + it "Allows 3 free uses" do @account.check_withdraw(20).must_equal 80 @account.check_withdraw(20).must_equal 60 @account.check_withdraw(20).must_equal 40 @@ -71,8 +71,12 @@ end - it "Applies a $2 fee after the third use" do skip - # TODO: Your test code here! + it "Applies a $2 fee after the third use" do + @account.check_withdraw(20).must_equal 80 + @account.check_withdraw(20).must_equal 60 + @account.check_withdraw(20).must_equal 40 + @account.check_withdraw(20).must_equal 18 + @account.check_withdraw(20).must_equal (-4) end end From fa9c1b49062e7787a294585ccb8363202307fbfa Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 01:58:48 -0800 Subject: [PATCH 40/48] forgot to add checking.rb --- lib/checking.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/checking.rb b/lib/checking.rb index d097ab70..0f68a77a 100644 --- a/lib/checking.rb +++ b/lib/checking.rb @@ -27,6 +27,10 @@ def withdraw(amount) end def check_withdraw(amount) + if amount < 0 + print "Cannot enter negative amount" + return @balance + end check_fee = 0 @@ -40,6 +44,7 @@ def check_withdraw(amount) @balnace = @balance else @balance = @balance - (amount + check_fee) + @checks -= 1 return @balance end From 86050bdb8cbe0df22c2a04daaa8e677b9d5694a5 Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 02:10:57 -0800 Subject: [PATCH 41/48] Specs for Checking_account subclass have all passed --- lib/checking.rb | 4 ++++ specs/checking_account_spec.rb | 33 +++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/lib/checking.rb b/lib/checking.rb index 0f68a77a..54c803c7 100644 --- a/lib/checking.rb +++ b/lib/checking.rb @@ -50,5 +50,9 @@ def check_withdraw(amount) end +def reset_checks + @checks = 3 +end + end end diff --git a/specs/checking_account_spec.rb b/specs/checking_account_spec.rb index 6e0ef35f..932829d7 100644 --- a/specs/checking_account_spec.rb +++ b/specs/checking_account_spec.rb @@ -80,17 +80,42 @@ end end - xdescribe "#reset_checks" do + describe "#reset_checks" do + + before do + @account = Bank::CheckingAccount.new({balance: 100}) + end + it "Can be called without error" do - # TODO: Your test code here! + @account.reset_checks.must_equal 3 end it "Makes the next three checks free if less than 3 checks had been used" do - # TODO: Your test code here! + @account.check_withdraw(20).must_equal 80 + @account.check_withdraw(20).must_equal 60 + @account.checks.must_equal (1) + @account.reset_checks + @account.checks.must_equal 3 + @account.check_withdraw(20).must_equal 40 + @account.check_withdraw(20).must_equal 20 + @account.check_withdraw(20).must_equal 0 + @account.check_withdraw(8).must_equal (-10) end it "Makes the next three checks free if more than 3 checks had been used" do - # TODO: Your test code here! + + @account.check_withdraw(20).must_equal 80 + @account.check_withdraw(20).must_equal 60 + @account.check_withdraw(20).must_equal 40 + @account.check_withdraw(20).must_equal 18 + @account.checks.must_equal (-1) + @account.reset_checks + @account.checks.must_equal 3 + @account.deposit(102) + @account.check_withdraw(20).must_equal 100 + @account.check_withdraw(20).must_equal 80 + @account.check_withdraw(20).must_equal 60 + @account.check_withdraw(20).must_equal 38 end end end From b09c465c7bfb0c1e9685f53fc54a36458120522b Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 02:19:23 -0800 Subject: [PATCH 42/48] add_interest returns calculated interst --- lib/savings.rb | 8 ++++++++ specs/savings_account_spec.rb | 9 +++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/savings.rb b/lib/savings.rb index 6091bd06..470c9c42 100644 --- a/lib/savings.rb +++ b/lib/savings.rb @@ -31,7 +31,15 @@ def withdraw(amount) @balance = (@balance - (amount + 2)) + 10 return @balance end + end +def add_interest(rate) + interest = @balance * (rate/100) + @balance += interest + return interest +end + + end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 77f1d128..9e268f75 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -49,9 +49,14 @@ end end - xdescribe "#add_interest" do + describe "#add_interest" do + + before do + @account = Bank::SavingsAccount.new({balance: 10000}) + end + it "Returns the interest calculated" do - # TODO: Your test code here! + @account.add_interest(0.25).must_equal 25 end it "Updates the balance with calculated interest" do From 2170655167112ed1e1794c7051aa4131f3ca4eb5 Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 02:21:02 -0800 Subject: [PATCH 43/48] add_interest updates balance with interest --- specs/savings_account_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index 9e268f75..fa8bbb16 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -60,7 +60,8 @@ end it "Updates the balance with calculated interest" do - # TODO: Your test code here! + @account.add_interest(0.25) + @account.balance.must_equal 10025 end it "Requires a positive rate" do From 84b39330e2b08cdab9826a5e1fa6bbf0d9569b83 Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 02:24:53 -0800 Subject: [PATCH 44/48] all tests are complete for savings sub class --- lib/savings.rb | 15 ++++++++++----- specs/savings_account_spec.rb | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/savings.rb b/lib/savings.rb index 470c9c42..eb1e1531 100644 --- a/lib/savings.rb +++ b/lib/savings.rb @@ -34,11 +34,16 @@ def withdraw(amount) end -def add_interest(rate) - interest = @balance * (rate/100) - @balance += interest - return interest -end + def add_interest(rate) + if rate < 0 + print "We do not accept negative rates" + return @balance + else + interest = @balance * (rate/100) + @balance += interest + return interest + end + end end diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index fa8bbb16..eb581332 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -61,11 +61,11 @@ it "Updates the balance with calculated interest" do @account.add_interest(0.25) - @account.balance.must_equal 10025 + @account.balance.must_equal 10025 end it "Requires a positive rate" do - # TODO: Your test code here! + @account.add_interest(-1).must_equal 10000 end end end From 71347e6eae610f2e52ef739dd342cb96260d5d3e Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 13:46:24 -0800 Subject: [PATCH 45/48] Fixed savings withdraw false pass --- lib/savings.rb | 13 ++++++------- specs/savings_account_spec.rb | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/savings.rb b/lib/savings.rb index eb1e1531..e2d47f86 100644 --- a/lib/savings.rb +++ b/lib/savings.rb @@ -6,7 +6,7 @@ module Bank class SavingsAccount < Account - attr_accessor + attr_accessor :balance def initialize(account) @@ -22,18 +22,17 @@ def initialize(account) end - def withdraw(amount) + def withdraw(amount) #this one is weird - can figue out how to override the parent - if @balance - (amount + 2) < 10 + if (@balance - (amount + 2) ) < 10 puts "Insufficient Funds" return @balance - else - @balance = (@balance - (amount + 2)) + 10 - return @balance end - + super + return @balance - 2 end + def add_interest(rate) if rate < 0 print "We do not accept negative rates" diff --git a/specs/savings_account_spec.rb b/specs/savings_account_spec.rb index eb581332..f9913b64 100644 --- a/specs/savings_account_spec.rb +++ b/specs/savings_account_spec.rb @@ -32,7 +32,7 @@ it "Applies a $2 fee each time" do - @account.withdraw(20).must_equal 88 + @account.withdraw(20).must_equal 78 end it "Outputs a warning if the balance would go below $10" do From 45590b369cbab219d9e6a7910563e91d4c092c76 Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 15:30:39 -0800 Subject: [PATCH 46/48] refactored account initialize --- lib/account.rb | 75 +++++++++++++++++++++++-------------------------- lib/checking.rb | 25 +++++++++-------- 2 files changed, 49 insertions(+), 51 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 711e7758..1013756d 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -8,60 +8,63 @@ module Bank class Account + attr_accessor :balance + attr_accessor :id, :opendatetime#, :accounts - - - - - attr_accessor :balance, :id, :opendatetime, :accounts - - + @@accounts = nil def initialize(account_hash) @id = account_hash[:id].to_i - @balance = account_hash[:balance].to_i #currently this will assign a negaitve number + @balance = account_hash[:balance].to_i @opendatetime = account_hash[:opendatetime] - #@accounts = Bank::Account.all - #method open_account assign to instance v. - if @balance >= 0 - @balance = @balance - else - raise ArgumentError.new "Account balance should not start with a negative number" - end + raise ArgumentError.new "Account balance should not start with a negative number" if @balance < 0 + @balance = @balance end #end of initialize - ### look into class var. or other way to save accounts def self.all - accounts = [] - CSV.read("support/accounts.csv").each do |row| - account = { - id: row[0], - balance: row[1], - opendatetime: row[2] - } - - accounts << Bank::Account.new(account) + + if @@accounts == nil + + @@accounts = [] + + CSV.read("support/accounts.csv").each do |row| + account = { + id: row[0], + balance: row[1], + opendatetime: row[2] + } + + @@accounts << Bank::Account.new(account) + + end end - return accounts + return @@accounts + end #end self.all + + + def self.accounts + @@accounts = @@accounts end - def self.find(id) - accounts = Bank::Account.all + def self.find(id) - accounts.find do |account| + @@accounts.find do |account| if account.id == id return account end end + raise ArgumentError.new "#{id} returned no results" - end + end #end self.find + def withdraw(amount) + if amount < 0 raise ArgumentError.new "Withdrawal amount cannot be negative number" else @@ -72,26 +75,18 @@ def withdraw(amount) return @balance -= amount end end - end #end of withdraw method def deposit(deposit_amount) + if deposit_amount < 0 raise ArgumentError.new "Deposit amount cannot be negative number" else @balance += deposit_amount end - end #end of deposit method + end #end of class end #end of module - -#puts Bank::Account.all.class - # new_account = Bank::Account.new(id: 1212, balance: 1235667, opendatetime: "1999-03-27 11:30:09 -0800") - # puts new_account.id - # puts Bank::Account.all.id -# puts "These are all the Bank accounts: #{Bank::Account.all}" -#print Bank::Account.find(15115) -#puts @accounts diff --git a/lib/checking.rb b/lib/checking.rb index 54c803c7..d3afb61d 100644 --- a/lib/checking.rb +++ b/lib/checking.rb @@ -7,29 +7,31 @@ module Bank class CheckingAccount < Account - attr_accessor :balance, :checks + attr_accessor :checks def initialize(account) super @checks = 3 end + def withdraw(amount) if @balance - (amount + 1) < 1 print "Insufficient Funds" - @balnace = @balance - else - @balance -= (amount + 1) - return @balance + return @balnace = @balance end + super + return @balance -= 1 end + def check_withdraw(amount) + if amount < 0 - print "Cannot enter negative amount" - return @balance + print "Cannot enter negative amount" + return @balance end check_fee = 0 @@ -38,7 +40,6 @@ def check_withdraw(amount) check_fee = 2 end - if @balance - (amount + check_fee) < (-10) print "Insufficient Funds" @balnace = @balance @@ -50,9 +51,11 @@ def check_withdraw(amount) end -def reset_checks - @checks = 3 -end + + def reset_checks + @checks = 3 + end + end end From 630917397c55af5ca1b33e945cef119827f89acb Mon Sep 17 00:00:00 2001 From: ashtn Date: Fri, 24 Feb 2017 15:32:15 -0800 Subject: [PATCH 47/48] refactored savings.rb --- lib/savings.rb | 21 +++++++++------------ specs/account_spec.rb | 4 ++-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/savings.rb b/lib/savings.rb index e2d47f86..20de3a95 100644 --- a/lib/savings.rb +++ b/lib/savings.rb @@ -6,23 +6,14 @@ module Bank class SavingsAccount < Account - attr_accessor :balance - def initialize(account) - @id = account[:id].to_i - @balance = account[:balance].to_i - @opendatetime = account[:opendatetime] - - if @balance >= 10 - @balance = @balance - else - raise ArgumentError.new "Savings Accounts must have an Initial Balance of $10" - end + raise ArgumentError.new "Savings Accounts must have an Initial Balance of $10" if account[:balance] < 10 + super end - def withdraw(amount) #this one is weird - can figue out how to override the parent + def withdraw(amount) if (@balance - (amount + 2) ) < 10 puts "Insufficient Funds" @@ -30,10 +21,12 @@ def withdraw(amount) #this one is weird - can figue out how to override the pare end super return @balance - 2 + end def add_interest(rate) + if rate < 0 print "We do not accept negative rates" return @balance @@ -42,8 +35,12 @@ def add_interest(rate) @balance += interest return interest end + end end end + +new_account = Bank::SavingsAccount.new({balance: 10}) +puts new_account.balance diff --git a/specs/account_spec.rb b/specs/account_spec.rb index f0415886..4e9bf871 100644 --- a/specs/account_spec.rb +++ b/specs/account_spec.rb @@ -5,7 +5,7 @@ -xdescribe "Wave 1" do +describe "Wave 1" do describe "Account#initialize" do it "Takes an ID and an initial balance" do #this is one test case with 4 assertions @@ -149,7 +149,7 @@ end # TODO: change 'xdescribe' to 'describe' to run these tests -xdescribe "Wave 2" do +describe "Wave 2" do describe "Account.all" do before do From 5d1990b6b349589287557ee51c5199b4eaaf5081 Mon Sep 17 00:00:00 2001 From: Ashtn Date: Sun, 5 Mar 2017 19:27:06 -0800 Subject: [PATCH 48/48] checking if github is linked --- .DS_Store | Bin 0 -> 6148 bytes lib/account.rb | 7 +++---- specs/account_spec.rb | 4 +--- specs/checking_account_spec.rb | 6 ++++-- specs/savings_account_spec.rb | 8 ++------ specs/spec_helper.rb | 10 ++++++++++ 6 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 .DS_Store create mode 100644 specs/spec_helper.rb diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..55f61042d5efd2d51645c16433adabda7b1f6426 GIT binary patch literal 6148 zcmeH~!EVz)5Qb-)lsZ(19FWqZFO@h%C~Xm?LP#d0haQj+L2v-n+ObQmy51;uh-e7% zg?DHlfj8j|cn}@{{@GoS8S2CJ{L(to56yE-=2% zWx8YL7{P>K3_aa1tLhNiD?!7z!lywmwEmTL9o8!Jwu;WTbJ@A^k_($D>ToOS)t z8+8_kQDFR+QYL?VKX?^Kll|tMr!vj`IE_Z7@VBqyG?bIB9H(KX`g!i>N61w-+Hba| z)6Jc>yS4dn)^?}c+nu(1f9t_)<~XhOjmLWjCm&CzpJt!W)F??{W>a?C=x;fPV;Fqs zkJ3b@@6p214!yuUcnqS4Ae2xv&q%ZoQzqF!{4PDA9zBEd+*x5SzEm=nDWf6!A5d25 z`^V*xSM(W_SX7?F3Mh@iX-JYrl+Tk=@AFydeFnH|X6DUyR*qC)qPgz!JDp1Vp{p?{zUGv$ie_ wj@McjA