0
モデル:payment.rbはActiveRecordの関係でRSpecのを渡すためにモデルを取得することはできません
class Payment < ActiveRecord::Base
belongs_to :loan
def self.previous_payments(id)
where(loan_id: id)
end
end
それが正しいloan_idを持っている場合、私がやろうとしていますすべては、必ず支払いが発見されたを作るためのテストである
テスト:
describe '#self.previous_payments' do
let(:loan) {Loan.create!(id: 1, funded_amount: 1000.0)}
let(:payment_one) {Payment.create!(amount: 100.0, loan_id: 1)}
let(:payment_test) {Payment.previous_payments(1)}
it 'retrieves all the payments made for a specific loan' do
expect(payment_test.first.loan_id).to eql(1)
end
end
しかし、私はこのエラーを取得しておいてください。
expected: 1
got: #<ActiveRecord::Relation []>
[]は、レコードが見つからないということですか?
ご協力いただければ幸いです。
Ahhh thanks a ton james00794!完璧に働いた。 "let"の代わりに "let!"を置くことについて決して想像していないでしょう。 – user3007294