0

我正在尝试修复多态嵌套资源的默认测试并遇到很多问题。我敢打赌,有一个简单的解决方案,这个新手还没有搞定。任何帮助将一如既往地不胜感激。

我的模型:

class Member < ActiveRecord::Base
  has_many :names, as: :person
  has_many :dependents

 attr_accessible :active, :deleted
 end

 class Name < ActiveRecord::Base
   belongs_to :person, polymorphic: true

    attr_accessible :dob, :dod, :first, :gender, :last, :mi, :prefix, :relation, :suffix
 end

路线.rb:

  resources :dependents do
    resources :names 
  end

  resources :members do
   resources :names 
  end

示例测试:

 require 'test_helper'

class NamesControllerTest < ActionController::TestCase
 setup do
  @name = names(:one)
  @person = members(:one)
 end

test "should get edit" do
  get :edit, id: @name
   assert_response :success
 end
 end

我收到的错误:

3) 错误:test_should_get_edit(NamesControllerTest): ActionController::RoutingError: No route matches {:id=>"980190962", :person_id=>"980190962", :controller=>"names", :action=>"edit"} /usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:544:in raise_routing_error' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:540:inrescue in generate' /usr/local/rvm/gems /ruby-1.9.3-p392/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:532:in generate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:573:ingenerate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems /actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:569:in generate_extras' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:565:inextra_keys' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.13/lib/action_controller /test_case.rb:153:in assign_parameters' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:465:inprocess' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:49:inprocess' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:392:in获取'/Users/mkenney/hraccess/test/functional/names_controller_test.rb:43:in `block in'

如果我在非嵌套路由中添加回名称,这些错误就会运行。我如何告诉测试它是一个嵌套资源并且这与多态关系有什么关系,或者仅仅是让我失望的噪音?

提前感谢您可以为这个新手提供的任何帮助!

标记

4

1 回答 1

0

我需要添加 member_id 以获得我相信的正确路线:

test "should get edit" do
  get :edit, member_id: @person, id: @name
  assert_response :success
end
于 2013-07-24T16:41:01.387 回答