2009-10-28 60 views
0

儘管創建管理用戶會話,但我無法訪問需要管理員用戶的集成測試中的網址。我的測試在302錯誤上失敗。集成測試Authlogic before_filter:require_admin_user問題

class NewsItemsController < ApplicationController 
    before_filter :require_admin_user, :except => [:show, :index, :feed] 

    etc... 

end 

--test/inetgration/admin_stories.rb -- 

require 'test_helper' 

class AdminStoriesTest < ActionController::IntegrationTest 

    fixtures :all 
    setup :activate_authlogic 

    # if user is an admin he can create a new news_item 
    def test_creating_a_news_item 
     assert UserSession.create(users(:admin)) 
     get "news_items/new" 
     assert_response :success 
     #etc... 
    end 
end 

我得在test.log中的以下內容:

Unable to load roles_user, underlying cause no such file to load -- roles_user 

我的燈具文件名爲roles_users.yml你所期望的 - 所以不知道應該如何解決這個...

+0

你有roles_user模式? – 2009-10-28 16:00:15

+0

不,我有角色和用戶之間的habtm關聯 – Carmen 2009-10-28 16:28:13

回答

0

我認爲新的操作重定向到登錄屏幕。

這是因爲你還沒有登錄嘗試:

get "news_items/new", {}, { 'user_id' => 0 } 

或什麼的用戶ID實際上是。

第一個散列是請求散列,第二個散列是會話散列。

+0

得到「news_items/new」,{},{'user_id'=>'1'} 沒有幫助 - 仍然得到302錯誤 – Carmen 2009-10-28 15:16:47

+0

事實上,這是爲restful_authentication – 2009-10-28 15:59:33

0

您可能還需要在您的課堂中包含Authlogic :: TestCase。從我的應用程序(rspec,但相同的想法)

describe InvitationsController do 
    include Authlogic::TestCase 
    setup :activate_authlogic 

    describe 'sending invitations' do 
    ......... 

您的應用程序是否需要激活用戶?如果是這樣,這個用戶?

如果這沒有幫助。也許粘貼一些調試輸出,也許檢查創建的用戶。

+0

我已將test.log錯誤添加爲編輯 – Carmen 2009-10-28 15:43:35

0

我在集成測試中也遇到Authlogic問題,下面的修復(從this post)對我來說是一個成功的解決方法。

替換:

assert UserSession.create(users(:admin)) 

有了:

post 'user_session', :user_session => {:email => '[email protected]', :password => 'password'}