Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `cache' for nil:NilClass after upgrading to rails 4.2.5.1

Tags:

While upgrading from rails 4.2.5 to the recently released 4.2.5.1, I have encountered this error. This error exists only for specs with a before_filter that render an invalid status, such as render file: "public/422", status: :unauthorized. I get this error for both ruby-2.2.2 and ruby-2.3.0

The error exists in the action_view resolver method, implying the @cache value is nil. However, in the initialize method it should be instantiated: @cache = Cache.new

I am still working on a reproducible sample, but am so far lost as to how @cache could be nil.

These are the config variables set in my test.rb environment

config.cache_classes = true
config.eager_load = false

config.serve_static_files   = true
config.static_cache_control = 'public, max-age=3600'

config.consider_all_requests_local       = true
config.action_controller.perform_caching = false

config.action_dispatch.show_exceptions = false
config.action_controller.allow_forgery_protection = false  

config.action_mailer.default_url_options = {
  :host => '127.0.0.1',
  :port => 3000
}

config.action_mailer.delivery_method = :test
config.active_support.test_order = :random
config.active_support.deprecation = :stderr

Stack Trace:

1) UserController validates user
 Failure/Error: put :update, { id: user.id  }
 NoMethodError:
   undefined method `cache' for nil:NilClass
 # ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/template/resolver.rb:151:in `cached'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/template/resolver.rb:121:in `find_all_anywhere'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/path_set.rb:68:in `block (2 levels) in _find_all'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/path_set.rb:66:in `each'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/path_set.rb:66:in `block in _find_all'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/path_set.rb:65:in `each'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/path_set.rb:65:in `_find_all'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/path_set.rb:50:in `find_file'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/lookup_context.rb:126:in `find_file'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/abstract_renderer.rb:18:in `find_file'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/template_renderer.rb:32:in `block in determine_template'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/lookup_context.rb:147:in `with_fallbacks'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/abstract_renderer.rb:18:in `with_fallbacks'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/template_renderer.rb:32:in `determine_template'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/template_renderer.rb:8:in `render'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/renderer.rb:42:in `render_template'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/renderer.rb:23:in `render'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/rendering.rb:100:in `_render_template'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/streaming.rb:217:in `_render_template'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/rendering.rb:83:in `render_to_body'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/rendering.rb:32:in `render_to_body'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/renderers.rb:37:in `render_to_body'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/abstract_controller/rendering.rb:25:in `render'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/rendering.rb:16:in `render'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
 # ~/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.5.1/lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
 # ~/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
 # ~/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.5.1/lib/active_support/core_ext/benchmark.rb:12:in `ms'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/instrumentation.rb:44:in `block in render'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
 # ~/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.5.1/lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
 # ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/instrumentation.rb:43:in `render'
like image 516
Austin Avatar asked Jan 26 '16 19:01

Austin


1 Answers

This is an rspec/rspec-rails issue.

You can upgrade to rspec-rails-3.4.1 to fix it. Unless you've hard-coded the version of rspec-rails in your Gemfile, running:

bundle update rspec-rails rspec

should fix the problem.

like image 66
infused Avatar answered Oct 08 '22 17:10

infused