I'm trying to fix the default tests for a polymorphic nested resource and running into lots of issues. I'm betting there is a simple solution that this newbie just hasn't wrapped his head around yet. Any help would be greatly appreciated as always.
My Models:
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
routes.rb:
resources :dependents do
resources :names
end
resources :members do
resources :names
end
Example Test:
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
Error I'm receiving:
3) Error: 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:ingenerate' /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:ingenerate_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:inassign_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:inget' /Users/mkenney/hraccess/test/functional/names_controller_test.rb:43:in `block in '
If I add back in the non-nested route to names these errors run. How do I tell the test that it is a nested resource and does this have anything to do with the polymorphic relationship, or is that just noise that is throwing me off?
Thanks in advance for any help you can offer this newbie!
Mark