开发者

Problem with Thinking Sphinx and Functional Tests

开发者 https://www.devze.com 2023-03-08 11:56 出处:网络
this is my test (with shoulda helpers): context \"searching from header\" do setup do Factory(:city, :name => \'Testing It\')

this is my test (with shoulda helpers):

  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

Everything works fine except the test always say the开发者_开发知识库 count of the results is 0, not 1.

I have debugged this code and when the request reaches the controller, the Sphinx indexes are completely empty, even with the explicit call of index for it.

Am I doing something wrong here?

Any help appreciated.


I found out the problem... even tho the insertion in the database is right before the ThinkingSphinx.index, with transactional fixtures, after the setup block the records get deleted.

The solution was adding to the test the following line:

self.use_transactional_fixtures = false

Hope this helps anyone with the same problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消