【发布时间】:2016-04-03 18:30:21
【问题描述】:
型号:payment.rb
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 []>
而且看起来 [] 表示甚至没有找到任何记录?
任何帮助都将不胜感激!
【问题讨论】:
标签: ruby-on-rails rspec