functinal testing, sign_in test helper

45 views
Skip to first unread message

Pablo Rodriguez

unread,
May 9, 2012, 4:55:10 PM5/9/12
to Devise
I have this Users::SessionsController, for Devise

class Users::SessionsController < Devise::SessionsController
include ApplicationHelper

after_filter :set_company_id,:only =>[ :new, :create ]
after_filter :clear_company_id, :only =>[:destroy]

def set_company_id
if current_user && current_user.company
set_company_in_cookie(Array(current_user.company.id))
end
end

def clear_company_id
cookies.delete(:company_id)
end
end

require 'test_helper'

Then in my Test I have this... Im using Devise so I use sign_in @user
to log into the system, sign_in should be over
Users::SessionsController then the after_filter must be called and
set_company_in_cookie(Array(current_user.company.id)) be called, this
helper set company id in session.. but do not happend so then in the
view when I try to get the value from session I get nil.. what Im
doing wrong ? thanks

class WorkordersControllerTest < ActionController::TestCase
setup do
@user = FactoryGirl.create(:gustavo_de_antonio)
end

test "should get index" do
sign_in @user
get :index
assert_response :success
assert_template :index
end

end

Carlos Antonio da Silva

unread,
May 10, 2012, 8:37:26 AM5/10/12
to plataforma...@googlegroups.com
Does this work when you manually test? Are just the automated tests that are failing?

-- 
At.
Carlos Antonio

On Wednesday, May 9, 2012 at 5:55 PM, Pablo Rodriguez wrote:

assert_response

Pablo Rodriguez

unread,
May 14, 2012, 7:54:43 AM5/14/12
to plataforma...@googlegroups.com
Yes it work when I use the application with a navigator, after login I need to put user's company id in the session... is there any better aproach for that ?
seems like when I run the Functional test the  Users::SessionsController 's filters are not been called, the class is loaded , I put msg in the class and see the msg in logs but the 
filters methods are never called...
do you suggest to use other aproach for this ?

thanks for your response
Reply all
Reply to author
Forward
0 new messages