Monthly Archives: January 2015

Rails integration testing working with ldap login

Now, I have spent a long time trying to get this working and have only persisted because I know how important it is to get automated testing working.

My job is harder because all my controllers require authentication and authorisation and  get the impression that they’re not well-suited to unit testing. Okay, kinda makes sense.

Integration testing s where we test the path through an application, including login. gives some clues as to how to start with an application that needs a login but try as I did there’s no way I could get a test to login. No errors, just didn’t work. How very Rails.

My post_via_redirect call was,

post_via_redirect "/sessions/login", username: "username", password: "password"

But then  came across

which described the post_via_redirects as

post_via_redirect(?sessions?, {:user=>{:email=>, :password => user.password}})

so my integration test becomes,

require 'test_helper'
class UserFlowsTest < ActionDispatch::IntegrationTest
 fixtures :roles, :sessions, :application_types
test "login and browse site" 
get "/sessions/
 assert_response :success
post_via_redirect("/sessions/login", {:session => {username: "username", password
 assert_equal '/applications', path assert_equal 'Signed in successfully.', flash[:notice
get "/application_types/1"
 assert_response :success
 assert assigns(:application_types)

And it works.Such a simple difference and such a difference. The hardest thing I’ve yet to do in Rails. Now, how on earth do I unit test my controllers.