I would like to test a helper method using Minitest (minitest-rails
) - but the helper method depends on current_user
, a Devise helper method available to controllers and view.
app/helpers/application_helper.rb
def user_is_admin? # want to test
current_user && current_user.admin?
end
test/helpers/application_helper_test.rb
require 'test_helper'
class ApplicationHelperTest < ActionView::TestCase
test 'user is admin method' do
assert user_is_admin? # but current_user is undefined
end
end
Note that I am able to test other helper methods that do not rely on current_user
.