tab/spec/models/transaction_spec.rb

39 lines
1,023 B
Ruby
Raw Normal View History

2015-09-08 11:44:40 +02:00
# == Schema Information
#
# Table name: transactions
#
# id :integer not null, primary key
# debtor_id :integer not null
# creditor_id :integer not null
2015-09-09 12:50:39 +02:00
# issuer_id :integer not null
# issuer_type :string not null
2015-09-08 11:44:40 +02:00
# amount :integer default(0), not null
# message :string
# created_at :datetime not null
# updated_at :datetime not null
#
require 'rails_helper'
RSpec.describe Transaction, type: :model do
2015-09-08 14:00:11 +02:00
it "has a valid factory" do
expect(create(:transaction)).to be_valid
end
describe "cache" do
before :each do
@user = create(:user)
end
it "should update creditor cache" do
trans = build(:transaction, creditor: @user, amount: 10)
expect {trans.save!}.to change {@user.balance}.by(10)
end
it "should update debtor cache" do
trans = build(:transaction, debtor: @user, amount: 10)
expect {trans.save!}.to change {@user.balance}.by(-10)
end
end
2015-09-08 11:30:11 +02:00
end