Rspec 数据库视图为空

Rspec DB View Is Empty

我在 Rails 应用程序中创建了一个 LeadIndex 视图,该视图基于我的 Lead 模型。当 运行 我的测试套件 (Rspec) 时,table(数据库视图)被识别,但 returns 是 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 子句来显示仅具有与我的开发数据库对象匹配的 ID 的结果。

因此,当测试环境为其对象生成随机 ID 时,WHERE 子句会过滤掉所有对象,因为没有 ID 的确切编号与我的开发数据库 ID 匹配..

太棒了!经验教训。