我的 Active Record 中有一个 self.lookup 方法。我想要做的是使用 FactoryGirl 来测试该方法。当我调用类 Repurchase.lookup(d, lp) 时,它从数据库中提取种子数据而不是测试数据。
在回购活动记录中:
def self.lookup(division, loan)
end
在我的 RSpec 代码中:
rr = FactoryGirl.create(:repurchase, pricing_cat_id: nil, loan_id: 1)
puts rr.inspect
d = FactoryGirl.build(:division, id: 1)
lp = FactoryGirl.build(:loan, id: 1, pricing_cat_id: nil)
rv = Repurchase.lookup(d, lp)
#When I call this it goes against the database
#HOW TO DO THIS (rv = Repurchase.lookup(d, lp) against test data)?
rv.pricing_cat_id.should eql(nil)
rr = FactoryGirl.create(:repurchase, pricing_cat_id: 1, loan_id: nil)
puts rr.inspect
lp = FactoryGirl.build(:loan, id: nil, pricing_category_id: 1)
lp.pricing_cat_id.should eql(1)
rv = Repurchase.lookup(d, lp) #HOW TO DO THIS lookup call??
先感谢您