-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@controller in Sweeper is set to nil when running rspec controller test #31
Comments
I’ve just run into this issue too – with Rails 5.0.1, git version of this gem and standard minitest. Proposed hot fix works for me. To add some more details, the error I hit was:
Although this is an example of a failing controller test, I get failures for model tests as well. My sweeper’s code: class ProposalSweeper < ActionController::Caching::Sweeper
observe Proposal
def after_save(record)
expire_page :controller => 'proposals', :action => %w[ index new ]
end
end |
I just run into this issue too. I use Rails 4.2.8. @controller is nil.
|
I have the same issue but in my running application (not RSpec) with rails 5.1.4. In my controller: class FormulasController < ApplicationController
...
caches_action :index
cache_sweeper :formulas_sweeper, only: :index
def index
...
end
end And my Sweeper class: class FormulasSweeper < ActionController::Caching::Sweeper
observe Import
def after_update(import)
expire_action controller: 'formulas', action: 'index'
end
end The Sweeper is running and failing with: NoMethodError: undefined method `expire_action' for #<FormulasSweeper:0x00000004e935f0 @controller=nil>
from app/sweepers/formulas_sweeper.rb:6:in `after_update'
from (irb):2 @nnattawat's fixUpdating my Sweeper as following: class FormulasSweeper < ActionController::Caching::Sweeper
observe Import
def after_update(import)
@controller ||= ActionController::Base.new
expire_action controller: 'formulas', action: 'index'
end
end Makes the code fail with: NoMethodError: undefined method `host' for nil:NilClass
from app/sweepers/formulas_sweeper.rb:7:in `after_update'
from (irb):2 This is due to the fact that |
I was getting undefined for |
I am in the process of upgrading rails 3.2 to 4.1.8. So, I add the gem to make the app running without changing any code. The observer and sweeper actually works fine when I did manual test. However, when I run rspec test, I got missing method error and @controller was nil.
I need to add @controller ||= ActionController::Base.new in my sweeper for the hot fix.
The text was updated successfully, but these errors were encountered: