Ruby On Rails 功能测试:具有多态模型的索引
我有一个名为 Address 的多态模型,我目前正在尝试为该模型和控制器编写一些基本功能测试。对于控制器来说,我不知道如何解决这个问题。例如,我有另一个名为 Patient 的模型,每个 Patient 都会有一个地址,所以我开始编写以下函数测试,但我不知道如何将“get”与嵌套多态资源一起使用。现在我可以在这里找到一些有关 Fixtures 的多态测试信息: http://api.rubyonrails.org /classes/Fixtures.html 但这无助于我对索引进行测试。非常感谢任何帮助,我在这里完全迷失了。
文件:测试/功能/addresses_controller_test.rb
require 'test_helper'
class AddressesControllerTest < ActionController::TestCase
setup do
@address = addresses(:of_patient)
@patient = patients(:one)
activate_authlogic
end
test "patient addresses index without user" do
get :index <<<<<<<<<<<< what goes here????
assert_redirected_to :login
end
end
I have a polymorphic model called Address, I am trying to currently write some basic function tests for this model and controller. For the controller I am at a loss on how to go about this. For example I have another model called Patient, each Patient will have an address, so i have started writing the following function test, but i have no idea how to use "get" with a nested polymorphic resource. Now I was able to find some polymorphic test information on Fixtures here: http://api.rubyonrails.org/classes/Fixtures.html
but this will not help me test against the index. Any help is much appreciated im at a total and complete loss here.
FILE: test/functional/addresses_controller_test.rb
require 'test_helper'
class AddressesControllerTest < ActionController::TestCase
setup do
@address = addresses(:of_patient)
@patient = patients(:one)
activate_authlogic
end
test "patient addresses index without user" do
get :index <<<<<<<<<<<< what goes here????
assert_redirected_to :login
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您的控制器按照我认为的方式设置:
那么测试可能如下所示:
需要记住的是,index 方法需要 Patient_id 来处理。
Assuming your controller is setup the way I think it might be:
Then the test will probably look like this:
The thing to keep in mind is that the index method needs the patient_id to process.