jeudi 22 janvier 2015

How can I authenticate a user for my controller tests with Devise and devise_ldap_authenticatable?

I'm attempting to run tests on my controllers in my Rails application; however, I am unable to get a user authenticated prior to testing. I am able to authenticate against Active Directory when accessing the site though. I have the following setup...


test_helper.rb



...
class ACtionController::TestCase
include Devise::TestHelpers
end
...


clubs_controller_test.rb



require 'test_helper'

class ClubsControllerTest < ActionController::TestCase

setup :initialize_club_base

test "should create club" do
assert_difference('Club.count') do
post :create, club: { ... }
end
assert_redirected_to club_path(assigns(:club))
end

private

def initialize_club_base
@club = clubs(:base)
end
end


Error



1) Failure:
ClubsControllerTest#test_should_create_club [/path/to/file...:20]:
"Club.count" didn't change by 1.
Expected: 2
Actual: 1


Now I believe I need to sign in a user in the "setup" section of the controller test... but since I'm relying on authentication through Active Directory can I do this? If so do I have to create a test user in Active Directory or is there a way around having to do that as it seems to not be an optimal solution having a fake user in the Active Directory.


Aucun commentaire:

Enregistrer un commentaire