2011-05-24 84 views
0

這是我的測試(與早該傭工):問題與思考獅身人面像和功能測試

context "searching from header" do 
    setup do 
     Factory(:city, :name => 'Testing It') 
     ThinkingSphinx::Test.index 'city_core', 'city_delta' 
     ThinkingSphinx::Test.start 

     get :index, 
      :query => 'Testing It' 
    end 

    should respond_with(:success) 
    should assign_to(:results) 
    should "have one city on the result" do 
     assert_equal(assigns(:results).count, 1) 
     assert_kind_of(assigns(:results).first, City) 
    end 

    ThinkingSphinx::Test.stop 
    end 

,一切工作正常,除了測試總是說結果的計數爲0,而不是1

我調試了這段代碼,當請求到達控制器時,Sphinx索引完全是空的,即使對它進行了明確的索引調用。

我在這裏做錯了什麼?

任何幫助表示讚賞。

回答

1

我發現問題...即使在數據庫中的插入正好在事務性夾具ThinkingSphinx.index之前,在setup塊之後記錄被刪除。

溶液加入到測試以下行:

self.use_transactional_fixtures = false 

希望這有助於同樣的問題的人。