【发布时间】:2016-02-02 00:16:41
【问题描述】:
所以我有一个 Request 模型(我知道这是一个糟糕的名字),以及 2 个单继承模型 TenantRequest 和 PropertyRequest。现在我有所有 3 个的固定装置。所以我为我的 requests_controller 和我的tenant_requests_controller 编写了功能控制器测试,它们都工作正常。但由于某种原因,我的 property_controller 测试显示每个设置都出现以下错误:
1) Error:
PropertyRequestsControllerTest#test_should_get_edit:
ActiveRecord::RecordNotFound: Couldn't find Request with 'id'=298486374
test/controllers/property_requests_controller_test.rb:12:in `block in <class:PropertyRequestsControllerTest>'
这是tenant_requests.yml:
one:
title: This is the title of the tenant request
body: This is the body
user: regular
email: jim@retail.com
type: TenantRequest
contact_name: Jim
这是我的 property_request.yml:
one:
title: This is the title of the property request
body: This is the body for property
user: broker
email: sue@broker.com
type: PropertyRequest
contact_name: Sue
budget: 1234
city: New York
region: Manhattan
created_at: now
updated_at: now
status: open
company: Walmart
contact_position: Boss
contact_phone: 555-555-5555
squarefeet: 12345
broker: true
parking: true
onsite_tour: true
part_of_town: Downtown
time_to_reach: 7pm
budget: 1234
这里是property_requests_controller_test:
require 'test_helper'
class PropertyRequestsControllerTest < ActionController::TestCase
setup do
@regular = users(:jim)
@broker = users(:sue)
@analyst = users(:kev)
@admin = users(:lin)
sign_in :user, @analyst
@myrequest = property_requests(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:requests)
end
test "should get new" do
get :new
assert_response :success
end
test "should create request successfully" do
assert_difference('Request.count') do
post :create, request: { contact_name: 'Sue', body: 'this is the body', email: 'sue@broker.com', title: 'newly created property request', type: 'PropertyRequest' }
end
assert_redirected_to property_request_path(PropertyRequest.last)
end
如果您需要更多信息,请告诉我,我可以添加。谢谢,
【问题讨论】:
-
在此处包含不起作用的测试代码,
-
@ArupRakshit 我在上面添加了测试,谢谢
-
添加失败的测试、控制器和相关路由。
-
@DaveSchweisguth 如果在
@myrequest = property_requests(:one)行设置失败,甚至不会触及路由和控制器 -
错误消息指出它发生在
test_should_get_edit,你能把它也包括进去吗?如果您可以隔离它会更好(例如,尝试在仅包含相关方法的最小项目中获得相同的错误)。您可能会在此过程中发现问题本身。
标签: ruby-on-rails ruby ruby-on-rails-4 testing fixtures