O'Reilly logo

The Cucumber Book, 2nd Edition by Steve Tooke, Aslak Hellesoy, Matt Wynne

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reading and Writing to the Database

When we modified the Account earlier, we made it write out each transaction message as amount,account_number. The TransactionProcessor needs the account_number to find an account in the database and update its balance:

 require_relative ​'transaction_queue'
 require_relative ​'account'
 
 transaction_queue = TransactionQueue.new
 
 puts ​"transaction processor ready"
 loop​ ​do
  transaction_queue.read ​do​ |message|
  sleep 1
» transaction_amount, number = message.split(​/,/​)
» account = Account.find_by_number!(number.strip)
» new_balance = account.balance + transaction_amount.to_i
» account.balance = new_balance
» account.save
 end
 end

However, looking at ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required