Skip to content
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

Rails 6.1 development.rb undefined method `year' for 1:Integer #37391

Closed
schneems opened this issue Oct 7, 2019 · 2 comments · Fixed by #39059
Closed

Rails 6.1 development.rb undefined method `year' for 1:Integer #37391

schneems opened this issue Oct 7, 2019 · 2 comments · Fixed by #39059

Comments

@schneems
Copy link
Member

schneems commented Oct 7, 2019

Steps to reproduce

git clone https://github.com/schneems/rails_61_boot_bug
cd rails_61_boot_bug
bundle install
rails c

There is a 1.year in the development.rb file, for some reason the activesupport core extensions aren't yet applied when this file (and other config files) are attempted to be loaded. You can see the commit that introduces the bug here schneems/rails_61_boot_bug@a3d207c

The only other modification I made was

Expected behavior

The app to boot into a console

Actual behavior

An error occurs:

	15: from /Users/rschneeman/.gem/ruby/2.6.5/bundler/gems/rails-921b55d300fe/railties/lib/rails/engine.rb:612:in `block in <class:Engine>'
	14: from /Users/rschneeman/.gem/ruby/2.6.5/bundler/gems/rails-921b55d300fe/railties/lib/rails/engine.rb:612:in `each'
	13: from /Users/rschneeman/.gem/ruby/2.6.5/bundler/gems/rails-921b55d300fe/railties/lib/rails/engine.rb:613:in `block (2 levels) in <class:Engine>'
	12: from /Users/rschneeman/.gem/ruby/2.6.5/bundler/gems/rails-921b55d300fe/activesupport/lib/active_support/dependencies.rb:324:in `require'
	11: from /Users/rschneeman/.gem/ruby/2.6.5/bundler/gems/rails-921b55d300fe/activesupport/lib/active_support/dependencies.rb:291:in `load_dependency'
	10: from /Users/rschneeman/.gem/ruby/2.6.5/bundler/gems/rails-921b55d300fe/activesupport/lib/active_support/dependencies.rb:324:in `block in require'
	 9: from /Users/rschneeman/.gem/ruby/2.6.5/gems/zeitwerk-2.1.10/lib/zeitwerk/kernel.rb:23:in `require'
	 8: from /Users/rschneeman/.gem/ruby/2.6.5/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
	 7: from /Users/rschneeman/.gem/ruby/2.6.5/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
	 6: from /Users/rschneeman/.gem/ruby/2.6.5/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
	 5: from /Users/rschneeman/.gem/ruby/2.6.5/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
	 4: from /Users/rschneeman/.gem/ruby/2.6.5/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
	 3: from /Users/rschneeman/Documents/projects/tmp/boot_bug/config/environments/development.rb:1:in `<main>'
	 2: from /Users/rschneeman/.gem/ruby/2.6.5/bundler/gems/rails-921b55d300fe/railties/lib/rails/railtie.rb:216:in `configure'
	 1: from /Users/rschneeman/.gem/ruby/2.6.5/bundler/gems/rails-921b55d300fe/railties/lib/rails/railtie.rb:216:in `instance_eval'
/Users/rschneeman/Documents/projects/tmp/boot_bug/config/environments/development.rb:63:in `block in <main>': undefined method `year' for 1:Integer (NoMethodError)

System configuration

Rails version: Master (SHA 921b55d)

Ruby version: 2.6.5

@santib
Copy link
Contributor

santib commented Oct 10, 2019

@schneems Thanks for the sample app and the reproduction steps, it was fun to troubleshoot this error 🤗

@santib
Copy link
Contributor

santib commented Nov 23, 2019

@schneems I opened a PR but seems like the solution wasn't good enough. Would you like to give me some directions on how should this be solved? I'd like to be able to use ActiveSupport in the config files without an explicit require when upgrading to Rails 6.

alexcameron89 added a commit to alexcameron89/awesome-controller that referenced this issue Apr 20, 2020
Related errors below.

== Test WrongScopeError

Error:
```
Failures:

  1) Posts API (Custom Controller) GET /posts returns a list of posts
     Failure/Error:
       raise WrongScopeError,
             "`#{name}` is not available from within an example (e.g. an " \
             "`it` block) or from constructs that run in the scope of an " \
             "example (e.g. `before`, `let`, etc). It is only available " \
             "on an example group (e.g. a `describe` or `context` block)."

       `name` is not available from within an example (e.g. an `it` block) or from constructs that run in the scope of an example (e.g. `before`, `let`, etc). It is only available on an example group (e.g. a `describe` or `context` block).
     # /Users/alexkitchens/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:742:in `method_missing'
     # /Users/alexkitchens/fun/journey/dependencies/rails/actionpack/lib/action_dispatch/testing/assertions/routing.rb:188:in `method_missing'
     # /Users/alexkitchens/fun/journey/dependencies/rails/actionpack/lib/action_dispatch/testing/integration.rb:422:in `method_missing'
     # /Users/alexkitchens/fun/journey/dependencies/rails/activerecord/lib/active_record/test_fixtures.rb:101:in `run_in_transaction?'
     # /Users/alexkitchens/fun/journey/dependencies/rails/activerecord/lib/active_record/test_fixtures.rb:115:in `setup_fixtures'
     # /Users/alexkitchens/fun/journey/dependencies/rails/activerecord/lib/active_record/test_fixtures.rb:8:in `before_setup'
     # /Users/alexkitchens/fun/journey/dependencies/rails/actionpack/lib/action_dispatch/testing/integration.rb:331:in `before_setup'
     # /Users/alexkitchens/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rspec-rails-3.8.2/lib/rspec/rails/adapters.rb:126:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
     # /Users/alexkitchens/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:447:in `instance_exec'
     # /Users/alexkitchens/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:447:in `instance_exec'
     # /Users/alexkitchens/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:373:in `execute_with'
     #
     #   Showing full backtrace because every line was filtered out.
     #   See docs for RSpec::Configuration#backtrace_exclusion_patterns and
     #   RSpec::Configuration#backtrace_inclusion_patterns for more information.
```

Bisect led to d4367eb72601f6e5bba3206443e9d141e9753af8

Issue opened here: rails/rails#37783
Fix in Rspec Rails here: rspec/rspec-rails#2215
The fix is not in a full release yet, so I've pinned to the latest beta release.

```
commit d4367eb72601f6e5bba3206443e9d141e9753af8
Author: Edouard CHIN <edouard.chin@shopify.com>
Date:   Thu Nov 21 18:39:54 2019 +0100

    Modify ActiveRecord::TestFixtures to not rely on AS::TestCase:

    - ### Problem

      If one wants to use ActiveRecord::TestFixtures it is mandatory for
      the test suite to inherit from `ActiveSupport::TestCase`.
      TestFixtures makes use of specific method from AS::TestCase
      (`file_fixture_path` and `method_name`).

      ### Solution

      This PR fixes that by not making use of method_name and file_fixture_path.
```

== Time Issue

Error:
```
Failure/Error: require File.expand_path('../../config/environment', __FILE__)

NoMethodError:
  undefined method `hour' for 1:Integer
Run options: include {:locations=>{"./spec/requests/api/posts_spec.rb"=>[10]}}
```

Bisect led to commit 12959dee0f19a8e050dd1236b031c2c690729905

Issue open at rails/rails#37391
guillec added a commit to network-for-good/nfg_ui that referenced this issue Sep 8, 2022
There seems to be a bug in the Rails 6.0 version that doesn't load
active_support/time in time for configuration files.

See rails/rails#37391

This commit requires 'active_support/time' in the test.rb file in order
to handle the 1.hour method call. We should be able to remove this
require statement in the future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants