Clean Architecture on Rails - RubyConf Brasil 2015

01684ebe74590fa2d4c6f37e7a47c043?s=47 bezelga
September 19, 2015

Clean Architecture on Rails - RubyConf Brasil 2015

01684ebe74590fa2d4c6f37e7a47c043?s=128

bezelga

September 19, 2015
Tweet

Transcript

  1. 2.
  2. 10.
  3. 16.
  4. 17.
  5. 25.
  6. 26.
  7. 27.
  8. 28.
  9. 29.
  10. 35.
  11. 36.
  12. 38.
  13. 40.
  14. 41.
  15. 42.
  16. 43.
  17. 57.
  18. 59.

    context 'enough money to transfer' do it 'responds true' do

    expect(transfer).to be true end it 'debits the source account' do expect{ transfer }.to change{ source_account_balance }.by(- amount) end it 'credits the destination account' do expect{ transfer }.to change{ destination_account_balance }.by(amount) end end PRIMARY course
  19. 60.

    context 'not enough money to transfer' do it 'cancels the

    transfer and responds false' do expect(transfer).to be false end it 'does not change the accounts balance' do expect{ transfer }.to_not change{ source_account_balance } expect{ transfer }.to_not change{ destination_account_balance } end end EXCEPTION COURSE
  20. 61.

    FFF

  21. 70.

    module Core class TransferMoney def self.transfer_money(source_account_id:, destination_account_id:, amount:) balance =

    Core.get_balance(account_id: source_account_id) return false if balance < amount ActiveRecord::Base.transaction do Trade.create!(account_id: source_account_id, amount: -amount) Trade.create!(account_id: destination_account_id, amount: amount) end end end end core/transfer_money.rb
  22. 71.

  23. 72.
  24. 73.
  25. 82.
  26. 83.
  27. 84.
  28. 85.
  29. 86.
  30. 89.

    class TransferMoneyController < ApplicationController before_action :load_balance def create if Core.transfer_money(source_account_id:

    source_account_id, destination_account_id: destination_account_id, amount: amount) redirect_to new_transfer_money_path else flash[:error] = 'Not enough money on the source account' render :new end end private def load_balance @balance = Core.get_balance(account_id: current_account_id) end end
  31. 90.
  32. 97.

    a key, longstanding hallmark of a good program is that

    it separates what is stable from what changes in the interest of good maintenance. - Trygve Reenskaug
  33. 114.
  34. 119.
  35. 121.
  36. 129.

    Eric Evans Don’t try yo apply DDD to everything. Draw

    a context map and decide on where you will make a push for DDD and where you will not .
  37. 133.
  38. 136.
  39. 150.
  40. 151.
  41. 153.

    Developer #1 Developer #2 The Boss The Mastermind Tio Roberto

    Domain Father Advisor Presenter CAST TYRION LANNISTER Jon SNOW SHERKLOCKS’ BROTHER IVAR JACOBSON UNCLE BOB ERIC EVANS ROBERT DUVAL FABIANO BESELGA by @fbzga