“Could not find a valid mapping for #” only on second and successive tests

后端 未结 9 1984
花落未央
花落未央 2020-12-28 13:28

I\'m trying to write a request test that asserts that the proper links appear on the application layout depending in whether a user is logged in or out. FWIW, I\'m using Dev

9条回答
  •  无人及你
    2020-12-28 14:25

    For future readers: I received same error, but for a different reason.

    Our app had multiple user models where one derived from the other

    For arguments sake:

    class SimpleUser
    
    class User < SimpleUser
    

    In my controller I used a reference to SimpleUser (the parent class), but Devise was configured to use User (the child class).

    During an invocation of Devise::Mapping.find_scope! it does .is_a? comparison against the object reference and the configured class.

    Since my reference was a SimpleUser, and the configured class was User, the .is_a? fails because the comparison was asking if the Parent class is_a? Child class, which is always false.

    Hope that helps someone else.

提交回复
热议问题