Make sure to rebuild index before testing when using ferret

Jan 发表于 2008-03-04 13:23:02

After beaten the bug in my acts_as_ferret model testcase, I think it's valuable to remind you: remember to do YourModel.rebuild_index before any tests related to ferret!!

Look at this:

 it "should be able to delete when no products related to it" do
    @brand.products.each do |product|
      product.brand = brands(:rollerblade)
      product.save
    end
    lambda {@brand.destroy}.should_not raise_error
    lambda {Brand.find(@brand.id)}.should raise_error
  end

  it "should be searchable" do
    Brand.rebuild_index
    Brand.find_by_contents("Rollerblade").should have(1).brands
    Brand.find_by_contents("good").should have(2).brands
    Brand.find_by_contents("Salomon").should have(2).brands
  end

In the first testcase, some brand maybe deleted, and acts_as_ferret will regenerate the index for you automatically. When the second testcase is run, although the fixtures will load again, the index has been modified and will NOT be revert to the original state as fixture, so you HAVE TO insert a Brand.rebuild_index line to ensure the index is synchoronized with the data in DB.

(note the running order of testcase is not guranteed by rspec)


收藏: QQ书签 del.icio.us 订阅: Google 抓虾

最新评论

发表评论

* 昵称

已经注册过? 请登录

新用户请先注册 以便能显示头像及追踪评论回复

Email
网址
* 评论
表情
 
 

分类小组论坛
杂谈, 娱乐、八卦, 文学、艺术, 体育, 旅游、同城, 象牙塔, 情感, 时尚、生活, 星座, 科技

请注意遵守中华人民共和国法律法规, 如威胁到本站生存, 将依法向有关部门报告, 同时本站的相关记录可能成为对您不利的证据.

相关法律法规
全国人大常委会关于维护互联网安全的决定
中华人民共和国计算机信息系统安全保护条例
中华人民共和国计算机信息网络国际联网管理暂行规定
计算机信息网络国际联网安全保护管理办法
计算机信息系统国际联网保密管理规定