Skip to content

Fix Undefined Method cache on rails 4.2.5.1 / 4.1.14.1 #1533

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

Closed
wants to merge 2 commits into from

Conversation

fcheung
Copy link

@fcheung fcheung commented Jan 25, 2016

This should fix #1532

As of rails/rails@0c5c32aa7cea5ee1ea60
not all calls funnel through find_all - calls to

    render file: '...'

call find_all_anywhere
@bquorning
Copy link
Contributor

The related change on Rails 4.1 (rails/rails@be543e8) and 4.2 (rails/rails@0c5c32a).

This change does indeed seem to make my spec suite run again.

@jhawthorn
Copy link
Contributor

👍 This fixes ny test suite. Although perhaps we want to be calling original_path_set.find_all_anywhere instead when we are wrapping that method.

@fcheung
Copy link
Author

fcheung commented Jan 25, 2016

I think the 1.8.7 failures are down to the rails 3-2 branch having broken 1.8.7 support. Not sure about the nokogiri install failures

@fcheung
Copy link
Author

fcheung commented Jan 25, 2016

As far as I can see, find_all_anywhere isn't a method on PathSet - only on Resolver

@fables-tales
Copy link
Member

Hi @fcheung can you also provide a spec for this? Let me know if you need some help with that.

robbkidd added a commit to chef/supermarket that referenced this pull request Jan 26, 2016
…hod in Rails.

Rails 4.1.14.1 introducted a new method for finding render templates and
files. Rspec-rails implements these methods. Since the new method had not
been implemented in Rspec yet, I've added this temporary monkeypatch until
a new version of rspec-rails is release and we can upgrade to it.

See rspec/rspec-rails#1532 for discussion around
the issue. And rspec/rspec-rails#1533 for the
current PR open to resolve it in the gem.
@rochers
Copy link

rochers commented Jan 26, 2016

Also affecting my application's test suite after upgraded to Rails 4.2.5.1. Let me know if you need any help.

@fcheung
Copy link
Author

fcheung commented Jan 26, 2016

@samphippen I couldn't find any specs that cover the existing code, but the cucumber features seem to. I wrote

  Scenario: View specs can explicitly render files
    Given a file named "spec/views/widgets/widget.html.erb_spec.rb" with:
      """ruby
      require "rails_helper"

      RSpec.describe "rendering the widget template" do
        it "displays the widget" do
          assign(:widget, Widget.create!(:name => "slicer"))

          render :file => File.expand_path "widgets/widget.html.erb"

          expect(rendered).to match /slicer/
        end
      end
      """
    And a file named "app/views/widgets/widget.html.erb" with:
      """
      <h2><%= @widget.name %></h2>
      """
    When I run `rspec spec/views`
    Then the examples should all pass

But I can't get the existing testsuite to run, even before I make my changes:

export RAILS_VERSION=4.1-stable
bundle install --standalone --binstubs
./script/run_build

explodes with

/Users/fred/rspec-rails/bundle/ruby/2.3.0/bundler/gems/rails-7921ff8c21d1/activesupport/lib/active_support/test_case.rb:1:in `<top (required)>': undefined method `gem' for main:Object (NoMethodError)
    from /Users/fred/rspec-rails/bundle/ruby/2.3.0/bundler/gems/rails-7921ff8c21d1/activesupport/lib/active_support/dependencies.rb:247:in `require'
    from /Users/fred/rspec-rails/bundle/ruby/2.3.0/bundler/gems/rails-7921ff8c21d1/activesupport/lib/active_support/dependencies.rb:247:in `block in require'
    from /Users/fred/rspec-rails/bundle/ruby/2.3.0/bundler/gems/rails-7921ff8c21d1/activesupport/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /Users/fred/rspec-rails/bundle/ruby/2.3.0/bundler/gems/rails-7921ff8c21d1/activesupport/lib/active_support/dependencies.rb:247:in `require'
    from /Users/fred/rspec-rails/bundle/ruby/2.3.0/bundler/gems/rails-7921ff8c21d1/actionpack/lib/action_controller/test_case.rb:428:in `<module:ActionController>'

@fcheung
Copy link
Author

fcheung commented Jan 26, 2016

(ruby 2.3.0 on OS X)

@bquorning
Copy link
Contributor

Could it be a Ruby manager issue (rvm/rbenv/chruby)? It looks like the rubygems library is not loaded.

@bquorning
Copy link
Contributor

Found this:

# Don't allow rubygems to pollute what's loaded. Also, things boot faster
# without the extra load time of rubygems. Only works on MRI Ruby 1.9+
if is_mri_192_plus; then
export RUBYOPT="--disable=gem"
fi

@yujinakayama
Copy link
Member

I think the 1.8.7 failures are down to the rails 3-2 branch having broken 1.8.7 support.

Yeah, it's now fixed in 3-2-stable branch though not yet released.

rails/rails#23250

@fcheung
Copy link
Author

fcheung commented Jan 26, 2016

example feature is nonsense but I have at least got existing features running

@fcheung
Copy link
Author

fcheung commented Jan 26, 2016

@samphippen is the feature I added any good? Fails appropriately when I revert the change to view_rendering.rb

@fables-tales
Copy link
Member

@fcheung it's helpful! I'm not going to be able to give this my full attention until this afternoon, but @pixeltrix and I are going to push out a fix.

@fables-tales
Copy link
Member

Closing in favour of #1535

robbkidd added a commit to chef/supermarket that referenced this pull request Jan 26, 2016
* Add monkeypatch to Rspec suite to fix lacking test method for new method in Rails.

Rails 4.1.14.1 introducted a new method for finding render templates and
files. Rspec-rails implements these methods. Since the new method had not
been implemented in Rspec yet, I've added this temporary monkeypatch until
a new version of rspec-rails is released and we can upgrade to it.

See rspec/rspec-rails#1532 for discussion around
the issue. And rspec/rspec-rails#1533 for the
current PR open to resolve it in the gem.

* Change specs from testing a 404 template render to a 404 response code

Rspec-Rails 3.1.0 doesn't like testing the rendering of templates for
Rails 4.1.14.1 with Rails' introduction of some fixes to template paths.

In these tests for 404 responses, I've replaced the expectations of a certain
template rendering with expectations of 404 status code. May circle back
and add template rendering tests back in once Rails and rspec-rails get
along again.

* Bump phantomjs to get rid of deprecation warning.
leftathome pushed a commit to leftathome/supermarket that referenced this pull request Feb 22, 2016
* Add monkeypatch to Rspec suite to fix lacking test method for new method in Rails.

Rails 4.1.14.1 introducted a new method for finding render templates and
files. Rspec-rails implements these methods. Since the new method had not
been implemented in Rspec yet, I've added this temporary monkeypatch until
a new version of rspec-rails is released and we can upgrade to it.

See rspec/rspec-rails#1532 for discussion around
the issue. And rspec/rspec-rails#1533 for the
current PR open to resolve it in the gem.

* Change specs from testing a 404 template render to a 404 response code

Rspec-Rails 3.1.0 doesn't like testing the rendering of templates for
Rails 4.1.14.1 with Rails' introduction of some fixes to template paths.

In these tests for 404 responses, I've replaced the expectations of a certain
template rendering with expectations of 404 status code. May circle back
and add template rendering tests back in once Rails and rspec-rails get
along again.

* Bump phantomjs to get rid of deprecation warning.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undefined Method cache in Tests for Rails 4.2.5.1
6 participants