Closed EmmaB closed 4 years ago
Seem related to https://github.com/rails/rails/pull/37632
Yep, I suspect we need to revise camelize
usage in the framework, or document potential mismatches, or restrict the inflector interface....
@EmmaB thanks for reporting this. I have moved it to https://github.com/rails/rails/issues/38399 since Zeitwerk itself is fine, it is really an issue in the Rails integration.
@fxn I still have this issue.
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
gem "activesupport", "6.0.3"
gem "zeitwerk"
end
require "active_support"
require "active_support/core_ext/object/blank"
require "minitest/autorun"
require "zeitwerk"
class BugTest < Minitest::Test
def test_acronym_override_1
# In rails projects, I use `Rails.autoloaders.main.inflector.inflect`
Zeitwerk::Loader.new.inflector.inflect(
"ai_template_controller" => "AITemplateController"
)
assert_equal("AITemplateController", ActiveSupport::Inflector.camelize("ai_template_controller"))
assert_equal("Taiwan", ActiveSupport::Inflector.titleize("taiwan"))
end
# def test_acronym_override_2
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.acronym("AI")
# end
# Zeitwerk::Loader.new.inflector.inflect(
# "ai_template_controller" => "AiTemplateController"
# )
# assert_equal("AiTemplateController", ActiveSupport::Inflector.camelize("ai_template_controller"))
# assert_equal("Taiwan", ActiveSupport::Inflector.titleize("taiwan"))
# end
end
@kmlrj hmmm, what do you mean? That test does not show a bug, it is working as expected.
A new Zeitwerk loader uses its own inflector. And that inflector does not use Active Support. Zeitwerk does not have Active Support as a gem dependency.
In Rails applications, Rails itself changes the default inflector of the autolaoders with one that uses AS. If you want things to match, you need to configure Active Support as explained in the guide.
Hello, and thanks for Zeitwerk and all the great docs!
We have an issue where Rails internals are not honouring inflector overrides. Here's a test-app.zip illustrating the issue, but here are the relevant bits:
And here's how the inflections initializer looks, as per the docs:
Here's the error on starting a server:
The server starts fine if you add this to the initializer:
but this causes issues when, for instance, we need to
titleize
a string ("Taiwan", for instance).We think it's a reasonable expectation that Rails should honour the explicit inflectors overrides, without needing to have a global ActiveSupport inflector as well. Do you think a bug, or is it how it's meant to work?
Just before I posted this issue, I noticed this comment in the
rails new
generatedinitializer.rb
file, just above the ActiveSupport::Inflector bit:# need these for when active support needs to inflect, such as on helper class names.
So maybe this is a known issue, or not considered an issue? Or could it be more of a bug in the Rails
titleize
method? Any thoughts on how you'd work around this clash would be fantastic.