Last active
August 29, 2015 13:57
-
-
Save JoshCheek/9718479 to your computer and use it in GitHub Desktop.
How I'd do https://www.youtube.com/watch?v=UfALIVZc87c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_record' | |
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:' | |
ActiveRecord::Schema.define do | |
self.verbose = false | |
create_table(:invoices) { |t| t.float :amount } | |
end | |
class Invoice < ActiveRecord::Base | |
def self.total_outstanding | |
sum :amount | |
end | |
end | |
describe Invoice do | |
specify '.total_outstanding is the sum of the invoice amounts' do | |
expect(Invoice.total_outstanding).to eq 0 | |
Invoice.create! amount: 1 | |
expect(Invoice.total_outstanding).to eq 1 | |
Invoice.create! amount: 2.2 | |
expect(Invoice.total_outstanding).to eq 3.2 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment