Ruby on Rails functional test with Devise authentication

前端 未结 3 1774
深忆病人
深忆病人 2021-02-06 02:57

I\'m searching for a solution for a weird problem. I have a controller, that needs authentication (with the devise gem). I added the Devise TestHelpers but i can\'t get it worki

3条回答
  •  别跟我提以往
    2021-02-06 03:22

    This took me some time to figure out but it turns out the answer is really simple.

    The point is that, in your fixtures file (users.yml), you need to make sure the user is 'confirmed' (assuming that you specified "confirmable" in your User model). So, for instance, put this in your users.yml:

    user_one:
      confirmed_at: 2015/01/01
    

    That's all, no need to specify other fields (email, encrypted password, etc).

    Now in your controller test (e.g. in 'setup' or in 'before') you simply code:

    sign_in users(:user_one)
    

    And then it should just work!

提交回复
热议问题