Code Monkey home page Code Monkey logo

Comments (4)

xHire avatar xHire commented on September 27, 2024

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:

ProposalsControllerTest#test_listing_proposals:
NoMethodError: undefined method `expire_page' for #<ProposalSweeper:0x00560a65f14468 @controller=nil>
    app/models/proposal_sweeper.rb:6:in `after_save'
    test/controllers/proposals_controller_test.rb:62:in `block (2 levels) in <class:ProposalsControllerTest>'
    test/controllers/proposals_controller_test.rb:62:in `times'
    test/controllers/proposals_controller_test.rb:62:in `block in <class:ProposalsControllerTest>'

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

from rails-observers.

gracemdsol avatar gracemdsol commented on September 27, 2024

I just run into this issue too. I use Rails 4.2.8. @controller is nil.

NoMethodError:
       undefined method `expire_action' for #<TurnSweeper:0x007f92bc252af0 @controller=nil>
       Did you mean?  expire_cost_fragment
     # /Users/yazhou/.rvm/gems/ruby-2.4.0@gmc/gems/rails-observers-0.1.4/lib/rails/observers/action_controller/caching/sweeper.rb:57:in `method_missing'

from rails-observers.

zedtux avatar zedtux commented on September 27, 2024

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 fix

Updating 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 ActionController::UrlFor.url_options is expecting a request object which is nil in my case.

from rails-observers.

WesleyKapow avatar WesleyKapow commented on September 27, 2024

I was getting undefined for expire_page and the only thing that fixed it for me was changing it to ApplicationController.expire_page as mentioned here: #4 (comment)

from rails-observers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.