Unit testing a polymorphic association with fixtures

前端 未结 1 1717
南旧
南旧 2021-02-20 13:34

I\'m getting this error message:

ERROR[\"test_profile_display\", UsersProfileTest, 2.569931] test_profile_display#UsersProfileTest (2.57s)
NoMethodError:                 


        
1条回答
  •  无人共我
    2021-02-20 14:13

    Change characters.yml to be

    character_bazley:
      sociable: bazley (User)
    

    instead of

    character_bazley:
      sociable: bazley (user)
    

    Note it is User and not user. The keyword used here User will tell that the sociable_type is of User class.

    Ref:

    http://ruby-journal.com/rails/define-fixtures-with-polymorphic-association/ http://api.rubyonrails.org/v3.2.8/classes/ActiveRecord/Fixtures.html#label-Polymorphic+belongs_to

    0 讨论(0)
提交回复
热议问题