开发者

Devise and Declarative Authorization Functional testing problems

开发者 https://www.devze.com 2023-02-03 20:41 出处:网络
I am having awful trouble getting functional tests to work when using devise and declarative authorization. I can use the devise test helpers to sign_in a user and then the current_user variable is po

I am having awful trouble getting functional tests to work when using devise and declarative authorization. I can use the devise test helpers to sign_in a user and then the current_user variable is populated in the controller. But as soon as I use the post_wi开发者_JS百科th test helper for declarative authorization the current_user becomes nil.

Can anybody point me at an example of how to write functional tests when using devise and declarative authorization together?

Thanks


I had the same problem. You can't use declarative authorizations testhelper such as post_with in functional tests with devise.

For functional test you mus use the devise testhelper such as sign_in and sign_out. I've wrote a helper which uses the devise test helper methods for functional tests:

def test_with_user(user, &block)
  begin
    sign_in :user, users(user)
    yield
  ensure
    sign_out :user
  end
end

This helper i use in the following way:

test_with_user(:max) do
  get :new
  assert_response :success
end

Hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消