# Authlogic functional test problem

**URL:** <https://www.ruby-forum.com/t/authlogic-functional-test-problem/179447>\
**Category:** Rails\
**Created:** [November 25, 2009, 9:35am UTC](https://www.ruby-forum.com/t/authlogic-functional-test-problem/179447 "2009-11-25T09:35:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [November 25, 2009, 9:35am UTC](https://www.ruby-forum.com/t/authlogic-functional-test-problem/179447/1 "2009-11-25T09:35:18Z")

</div>

One of my tests looks like this…

require ‘test\_helper’

class ResortsControllerTest \< ActionController::TestCase

# other tests

def test\_destroy\_works\_when\_admin  
UserSession.create(users(:admin)) # logs a user in  
resort = Resort.first  
delete :destroy, :id =\> resort  
assert\_redirected\_to resorts\_url  
assert !Resort.exists?(resort.id)  
end

end

It works fine and passes when I do this

rake test:functionals TEST=test/functional/resorts\_controller\_test.rb

* * *

But when I do this (run it with my other tests)

rake

It fails, like this

1. Failure:  
test\_destroy\_works\_when\_admin(ResortsControllerTest)  
[/test/functional/resorts\_controller\_test.rb:104]:  
Expected response to be a redirect to [http://test.host/resorts](http://test.host/resorts) but was  
a redirect to [http://test.host/user\_sessions/new](http://test.host/user_sessions/new).

Here’s my test\_helper

ENV[“RAILS\_ENV”] = “test”  
require File.expand\_path(File.dirname( **FILE** ) +  
“/…/config/environment”)  
require ‘test\_help’  
require “authlogic/test\_case” # include at the top of test\_helper.rb

class ActiveSupport::TestCase

self.use\_transactional\_fixtures = true  
self.use\_instantiated\_fixtures = false  
fixtures :all

end

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [November 25, 2009, 10:18am UTC](https://www.ruby-forum.com/t/authlogic-functional-test-problem/179447/2 "2009-11-25T10:18:07Z")

</div>

Hi bingo bob

A guess is you are losing session somehow? What is the setup method  
(if any) for this test? Also would like to see the related controller  
code after that

Sijo

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [November 25, 2009, 10:38am UTC](https://www.ruby-forum.com/t/authlogic-functional-test-problem/179447/3 "2009-11-25T10:38:07Z")

</div>

Sorry for the copy and paste error, yes the setup should have been  
listed, the test code in question is as follows.

require ‘test\_helper’

class ResortsControllerTest \< ActionController::TestCase

setup :activate\_authlogic # run before tests are executed

# other tests

def test\_destroy\_works\_when\_admin  
UserSession.create(users(:admin)) # logs a user in  
resort = Resort.first  
delete :destroy, :id =\> resort  
assert\_redirected\_to resorts\_url  
assert !Resort.exists?(resort.id)  
end

end

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [November 25, 2009, 4:07pm UTC](https://www.ruby-forum.com/t/authlogic-functional-test-problem/179447/4 "2009-11-25T16:07:05Z")

</div>

Any ideas as to what I might be missing here?
