Comments (4)
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.
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.
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.
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)
- Observers not firing in feature/integration tests using Capybara HOT 2
- `config.active_record.observers` syntax broken in Rails 5? HOT 12
- undefined method add_observer when using Observer for Mailer from Rails Engine HOT 1
- NoMethodError: undefined method `instantiate_observers' for ActiveResource::Base:Class HOT 3
- The Rails app gets loading during migrations with registered observers. HOT 4
- ActiveRecord::Base.instantiate_observers does not get called HOT 5
- rubygems.org release ? HOT 1
- I cannot install the gem from gemfile. HOT 2
- Next release? HOT 9
- rails-observers 0.1.4 not present in rubygems.org HOT 1
- Observers no longer loaded in 0.1.4 HOT 4
- ActionController::Caching::Sweeper controller instance is not thread safe HOT 1
- Can't disable observers HOT 9
- Forced to use /models HOT 1
- Test fails with Rails 5.2.2. HOT 1
- Broken in rails engine testing environment HOT 4
- Realease for 5.2.3 HOT 5
- - HOT 1
- Observers are empty and cannot disable (version 0.1.5)
- Please release new gem version
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rails-observers.