Skip to content

Commit 2e77870

Browse files
committed
gem with classic mode loads class unexpectedly
Output: before_configuration application.rb loaded before_initialize default_protect_from_forgery is true, expected: false config/initializers loaded ActiveSupport.on_load(:before_initialize) runs at the end of before_initialize after_initialize default_protect_from_forgery is false, expected: false ActiveSupport.on_load(:after_initialize) runs at the end of after_initialize
1 parent c4fcf48 commit 2e77870

4 files changed

Lines changed: 74 additions & 0 deletions

File tree

‎Gemfile‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ end
2525

2626
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
2727
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
28+
29+
gem 'wechat', '~> 0.12.0' # classic mode
30+
# gem 'wechat', '~> 0.13.0' # zeitwerk mode

‎Gemfile.lock‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,31 @@ GEM
6060
minitest (>= 5.1)
6161
tzinfo (~> 2.0)
6262
zeitwerk (~> 2.3)
63+
addressable (2.7.0)
64+
public_suffix (>= 2.0.2, < 5.0)
6365
builder (3.2.4)
6466
byebug (11.1.3)
6567
concurrent-ruby (1.1.8)
6668
crass (1.0.6)
69+
domain_name (0.5.20190701)
70+
unf (>= 0.0.5, < 1.0.0)
6771
erubi (1.10.0)
6872
ffi (1.14.2)
73+
ffi-compiler (1.0.1)
74+
ffi (>= 1.0.0)
75+
rake
6976
globalid (0.4.2)
7077
activesupport (>= 4.2.0)
78+
http (4.4.1)
79+
addressable (~> 2.3)
80+
http-cookie (~> 1.0)
81+
http-form_data (~> 2.2)
82+
http-parser (~> 1.2.0)
83+
http-cookie (1.0.3)
84+
domain_name (~> 0.5)
85+
http-form_data (2.3.0)
86+
http-parser (1.2.3)
87+
ffi-compiler (>= 1.0, < 2.0)
7188
i18n (1.8.9)
7289
concurrent-ruby (~> 1.0)
7390
listen (3.4.1)
@@ -89,6 +106,7 @@ GEM
89106
nokogiri (1.11.1)
90107
mini_portile2 (~> 2.5.0)
91108
racc (~> 1.4)
109+
public_suffix (4.0.6)
92110
puma (5.2.2)
93111
nio4r (~> 2.0)
94112
racc (1.5.2)
@@ -125,6 +143,7 @@ GEM
125143
rb-fsevent (0.10.4)
126144
rb-inotify (0.10.1)
127145
ffi (~> 1.0)
146+
rexml (3.2.4)
128147
sass-rails (6.0.0)
129148
sassc-rails (~> 2.1, >= 2.1.1)
130149
sassc (2.4.0)
@@ -147,9 +166,18 @@ GEM
147166
tilt (2.0.10)
148167
tzinfo (2.0.4)
149168
concurrent-ruby (~> 1.0)
169+
unf (0.1.4)
170+
unf_ext
171+
unf_ext (0.0.7.7)
150172
websocket-driver (0.7.3)
151173
websocket-extensions (>= 0.1.0)
152174
websocket-extensions (0.1.5)
175+
wechat (0.12.2)
176+
activesupport (>= 3.2, < 7)
177+
http (>= 1.0.4, < 5)
178+
nokogiri (>= 1.6.0)
179+
rexml
180+
thor
153181
zeitwerk (2.4.2)
154182

155183
PLATFORMS
@@ -163,6 +191,7 @@ DEPENDENCIES
163191
sass-rails (>= 6)
164192
sqlite3 (~> 1.4)
165193
tzinfo-data
194+
wechat (~> 0.12.0)
166195

167196
RUBY VERSION
168197
ruby 2.6.5p114

‎config/application.rb‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77
require "active_record/railtie"
88
# require "active_storage/engine"
99
require "action_controller/railtie"
10+
11+
ActionController::Railtie.initializer "puts default_protect_from_forgery when ActionController::Base is loaded" do
12+
ActiveSupport.on_load(:action_controller_base) do
13+
puts "default_protect_from_forgery is #{Rails.application.config.action_controller.default_protect_from_forgery}, expected: false"
14+
end
15+
end
16+
17+
ActionController::Railtie.initializer "puts default_protect_from_forgery when application is initialized" do
18+
ActiveSupport.on_load(:after_initialize) do
19+
puts "default_protect_from_forgery is #{Rails.application.config.action_controller.default_protect_from_forgery}, expected: false"
20+
end
21+
end
22+
1023
# require "action_mailer/railtie"
1124
# require "action_mailbox/engine"
1225
# require "action_text/engine"
@@ -34,5 +47,31 @@ class Application < Rails::Application
3447

3548
# Don't generate system test files.
3649
config.generators.system_tests = nil
50+
51+
config.before_configuration do
52+
puts "before_configuration"
53+
end
54+
55+
config.before_initialize do
56+
puts "before_initialize"
57+
end
58+
59+
config.after_initialize do
60+
puts "after_initialize"
61+
end
62+
63+
initializer "before_initialize hook" do |app|
64+
ActiveSupport.on_load(:before_initialize) do
65+
puts "ActiveSupport.on_load(:before_initialize) runs at the end of before_initialize"
66+
end
67+
end
68+
69+
initializer "after_initialize hook" do |app|
70+
ActiveSupport.on_load(:after_initialize) do
71+
puts "ActiveSupport.on_load(:after_initialize) runs at the end of after_initialize"
72+
end
73+
end
74+
75+
puts "application.rb loaded"
3776
end
3877
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Rails.application.config.action_controller.default_protect_from_forgery = false
2+
3+
puts 'config/initializers loaded'

0 commit comments

Comments
 (0)