【发布时间】:2021-12-01 06:28:18
【问题描述】:
我在我的 Rails 应用程序中创建了一个 LeadIndex 视图,该视图基于我的 Lead 模型。运行我的测试套件 (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>]
在开发模式下一切正常。
【问题讨论】:
-
你有点缺乏细节,请看How to Ask。特别是您需要以文本形式发布实际查询、表定义 (ddl)、示例数据和预期结果 - 无图像。
-
我已经更新了原帖。希望这可以帮助。似乎它必须是一个 Rspec 配置问题。因为它似乎在开发中运行良好。
标签: postgresql activerecord rspec rspec-rails ruby-on-rails-6