Rspec DB View Is Empty



我在Rails应用程序中创建了一个基于Lead模型的LeadIndex视图。当运行我的测试套件(Rspec)时,表(db视图)被识别,但返回为LeadIndex::ActiveRecord_Relation的空[]Lead模型显示有对象存储在数据库中,但视图似乎没有拾取它。

例如:

Lead.all =>
[#<Lead:0x000000010a70a9a8
id: 850,
source: "Web",
user_id: nil,
created_at: Tue, 12 Oct 2021 18:48:32.505988000 UTC +00:00,
updated_at: Tue, 12 Oct 2021 18:48:32.521121000 UTC +00:00,
received_on: Tue, 12 Oct 2021 00:00:00.000000000 UTC +00:00,
assigned_on: Tue, 12 Oct 2021 00:00:00.000000000 UTC +00:00,
agency_id: 452,
person_id: 882,
age: 41,
status: "prospecting",
dnc: false,
last_contact_time: nil>]
LeadIndex.all  => [] # actual
LeadIndex.all => #expected
[#<LeadIndex:0x000000015221ed48
id: 850,
source: "Web",
user_id: nil,
created_at: Tue, 12 Oct 2021 18:48:32.505988000 UTC +00:00,
updated_at: Tue, 12 Oct 2021 18:48:32.521121000 UTC +00:00,
received_on: Tue, 12 Oct 2021 00:00:00.000000000 UTC +00:00,
assigned_on: Tue, 12 Oct 2021 00:00:00.000000000 UTC +00:00,
agency_id: 452,
person_id: 882,
age: 0,
status: "prospecting",
dnc: false,
last_contact_time: nil,
scheduled_time: nil,
name: "John Doe",
person_state: "TX",
number: "(555) 555-5555",
num_outbound_dials: 3,
last_activity: Tue, 12 Oct 2021 00:00:00.000000000 UTC +00:00,
agent_name: "Tom Cruise",
lang: "English",
next_dial_time: "morning">
irb(main):002:0>]

在开发模式下一切都很完美。

我就是个傻瓜。我觉得对我来说。在我的SQL查询中,我有一个where子句,只提供与我的开发DB对象匹配的ID的结果。

因此,当测试环境为其对象组成随机ID时,WHERE子句会过滤掉所有这些对象,因为没有ID与我的开发DB ID匹配的确切数字。

a big d'oh!教训。

最新更新