【发布时间】:2014-04-10 20:04:19
【问题描述】:
我正在使用清扫器清除片段缓存,并且在开发过程中一切正常,但我在我们的规范中收到错误
2) Admin - Categories #index displays all categories
Failure/Error: create_basic_category_set
NoMethodError:
undefined method `expire_fragment' for #<NavigationSweeper:0x007fdc01a10970 @controller=nil>
# ./app/sweepers/navigation_sweeper.rb:5:in `after_save'
# ./spec/support/utilities.rb:21:in `create_basic_category_set'
# ./spec/features/admin/categories_spec.rb:5:in `block (2 levels) in <top (required)>'
这是扫地机
class NavigationSweeper < ActionController::Caching::Sweeper
observe Category, Product, Series
def after_save(record)
expire_fragment 'navigation'
end
end
这就是我在控制器中使用它的地方
class Admin::CategoriesController < Admin::BaseController
before_filter :set_up_nav_array
cache_sweeper :navigation_sweeper, only: [ :destroy, :update, :create, :update_positions ]
def index
@roots = Category.roots
end
这是规范中失败的地方(多个实例)
pickers = FactoryGirl.create(:category, :name => "Pickers")
有人知道为什么它可能找不到该方法吗?
【问题讨论】:
-
我认为这可能与 FactoryGirl 创建对象的方式有关
-
我能够通过将 - NavigationSweeper.any_instance.stub(:expire_fragment) 放入 it 块中来通过测试,但必须有更好的方法
标签: ruby-on-rails rspec observers sweeper