Skip to content

Commit d8cc02a

Browse files
committed
Rails 7.1: Enable configuration for 7.1
One model needed changing: that callback is run in another order (now: in declared order). One test needed to not require code on its own.
1 parent b6700a4 commit d8cc02a

File tree

4 files changed

+37
-62
lines changed

4 files changed

+37
-62
lines changed

app/models/contact.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ class Contact < ApplicationRecord
55
validates :name, :surname, :email, presence: true
66

77
before_create :set_token
8-
after_commit :subscribe_to_mailing_list, if: proc { |c| c.mailing_list_consent }
98
after_commit :unsubscribe_from_mailing_list, if: proc { |c| !c.mailing_list_consent }
9+
after_commit :subscribe_to_mailing_list, if: proc { |c| c.mailing_list_consent }
1010

1111
def subscribe_to_mailing_list
1212
mailing_list.subscribe(email, name, surname)

config/application.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ class Application < Rails::Application
2424
# Initialize configuration defaults for originally generated Rails version.
2525
config.load_defaults 7.0
2626

27-
config.add_autoload_paths_to_load_path = false
28-
27+
config.add_autoload_paths_to_load_path = false # false is 7.1 default, true is 7.0 default
28+
# TODO: When we have deployed Rails 7.1, we can uncomment this next line.
29+
# config.active_support.cache_format_version = 7.1
2930

3031
config.autoload_lib(ignore: %w(assets tasks))
3132

config/initializers/new_framework_defaults_7_1.rb

Lines changed: 33 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,23 @@
99
# Read the Guide for Upgrading Ruby on Rails for more info on each option.
1010
# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html
1111

12-
###
13-
# No longer add autoloaded paths into `$LOAD_PATH`. This means that you won't be able
14-
# to manually require files that are managed by the autoloader, which you shouldn't do anyway.
15-
#
16-
# This will reduce the size of the load path, making `require` faster if you don't use bootsnap, or reduce the size
17-
# of the bootsnap cache if you use it.
18-
#
19-
# To set this configuration, add the following line to `config/application.rb` (NOT this file):
20-
# config.add_autoload_paths_to_load_path = false
21-
2212
###
2313
# Remove the default X-Download-Options headers since it is used only by Internet Explorer.
2414
# If you need to support Internet Explorer, add back `"X-Download-Options" => "noopen"`.
2515
#++
26-
# Rails.application.config.action_dispatch.default_headers = {
27-
# "X-Frame-Options" => "SAMEORIGIN",
28-
# "X-XSS-Protection" => "0",
29-
# "X-Content-Type-Options" => "nosniff",
30-
# "X-Permitted-Cross-Domain-Policies" => "none",
31-
# "Referrer-Policy" => "strict-origin-when-cross-origin"
32-
# }
16+
Rails.application.config.action_dispatch.default_headers = {
17+
"X-Frame-Options" => "SAMEORIGIN",
18+
"X-XSS-Protection" => "0",
19+
"X-Content-Type-Options" => "nosniff",
20+
"X-Permitted-Cross-Domain-Policies" => "none",
21+
"Referrer-Policy" => "strict-origin-when-cross-origin"
22+
}
3323

3424
###
3525
# Do not treat an `ActionController::Parameters` instance
3626
# as equal to an equivalent `Hash` by default.
3727
#++
38-
# Rails.application.config.action_controller.allow_deprecated_parameters_hash_equality = false
28+
Rails.application.config.action_controller.allow_deprecated_parameters_hash_equality = false
3929

4030
###
4131
# Active Record Encryption now uses SHA-256 as its hash digest algorithm.
@@ -56,7 +46,7 @@
5646
# 3. If you don't currently have data encrypted with Active Record encryption, you can disable this setting to
5747
# configure the default behavior starting 7.1+:
5848
#++
59-
# Rails.application.config.active_record.encryption.support_sha1_for_non_deterministic_encryption = false
49+
Rails.application.config.active_record.encryption.support_sha1_for_non_deterministic_encryption = false
6050

6151
###
6252
# No longer run after_commit callbacks on the first of multiple Active Record
@@ -65,7 +55,7 @@
6555
# state which matches what was committed to the database, typically the last
6656
# instance to save.
6757
#++
68-
# Rails.application.config.active_record.run_commit_callbacks_on_first_saved_instances_in_transaction = false
58+
Rails.application.config.active_record.run_commit_callbacks_on_first_saved_instances_in_transaction = false
6959

7060
###
7161
# Configures SQLite with a strict strings mode, which disables double-quoted string literals.
@@ -76,12 +66,12 @@
7666
# For example, it is possible to create an index for a non existing column.
7767
# See https://www.sqlite.org/quirks.html#double_quoted_string_literals_are_accepted for more details.
7868
#++
79-
# Rails.application.config.active_record.sqlite3_adapter_strict_strings_by_default = true
69+
Rails.application.config.active_record.sqlite3_adapter_strict_strings_by_default = true
8070

8171
###
8272
# Disable deprecated singular associations names.
8373
#++
84-
# Rails.application.config.active_record.allow_deprecated_singular_associations_name = false
74+
Rails.application.config.active_record.allow_deprecated_singular_associations_name = false
8575

8676
###
8777
# Enable the Active Job `BigDecimal` argument serializer, which guarantees
@@ -93,22 +83,22 @@
9383
# serializer. Therefore, this setting should only be enabled after all replicas
9484
# have been successfully upgraded to Rails 7.1.
9585
#++
96-
# Rails.application.config.active_job.use_big_decimal_serializer = true
86+
Rails.application.config.active_job.use_big_decimal_serializer = true
9787

9888
###
9989
# Specify if an `ArgumentError` should be raised if `Rails.cache` `fetch` or
10090
# `write` are given an invalid `expires_at` or `expires_in` time.
10191
# Options are `true`, and `false`. If `false`, the exception will be reported
10292
# as `handled` and logged instead.
10393
#++
104-
# Rails.application.config.active_support.raise_on_invalid_cache_expiration_time = true
94+
Rails.application.config.active_support.raise_on_invalid_cache_expiration_time = true
10595

10696
###
10797
# Specify whether Query Logs will format tags using the SQLCommenter format
10898
# (https://open-telemetry.github.io/opentelemetry-sqlcommenter/), or using the legacy format.
10999
# Options are `:legacy` and `:sqlcommenter`.
110100
#++
111-
# Rails.application.config.active_record.query_log_tags_format = :sqlcommenter
101+
Rails.application.config.active_record.query_log_tags_format = :sqlcommenter
112102

113103
###
114104
# Specify the default serializer used by `MessageEncryptor` and `MessageVerifier`
@@ -138,7 +128,7 @@
138128
# servers, first deploy without changing the serializer, then set the serializer
139129
# in a subsequent deploy.
140130
#++
141-
# Rails.application.config.active_support.message_serializer = :json_allow_marshal
131+
Rails.application.config.active_support.message_serializer = :json_allow_marshal
142132

143133
###
144134
# Enable a performance optimization that serializes message data and metadata
@@ -151,52 +141,52 @@
151141
# leave this optimization off on the first deploy, then enable it on a
152142
# subsequent deploy.
153143
#++
154-
# Rails.application.config.active_support.use_message_serializer_for_metadata = true
144+
Rails.application.config.active_support.use_message_serializer_for_metadata = true
155145

156146
###
157147
# Set the maximum size for Rails log files.
158148
#
159149
# `config.load_defaults 7.1` does not set this value for environments other than
160150
# development and test.
161151
#++
162-
# if Rails.env.local?
163-
# Rails.application.config.log_file_size = 100 * 1024 * 1024
164-
# end
152+
if Rails.env.local?
153+
Rails.application.config.log_file_size = 100 * 1024 * 1024
154+
end
165155

166156
###
167157
# Enable raising on assignment to attr_readonly attributes. The previous
168158
# behavior would allow assignment but silently not persist changes to the
169159
# database.
170160
#++
171-
# Rails.application.config.active_record.raise_on_assign_to_attr_readonly = true
161+
Rails.application.config.active_record.raise_on_assign_to_attr_readonly = true
172162

173163
###
174164
# Enable validating only parent-related columns for presence when the parent is mandatory.
175165
# The previous behavior was to validate the presence of the parent record, which performed an extra query
176166
# to get the parent every time the child record was updated, even when parent has not changed.
177167
#++
178-
# Rails.application.config.active_record.belongs_to_required_validates_foreign_key = false
168+
Rails.application.config.active_record.belongs_to_required_validates_foreign_key = false
179169

180170
###
181171
# Enable precompilation of `config.filter_parameters`. Precompilation can
182172
# improve filtering performance, depending on the quantity and types of filters.
183173
#++
184-
# Rails.application.config.precompile_filter_parameters = true
174+
Rails.application.config.precompile_filter_parameters = true
185175

186176
###
187177
# Enable before_committed! callbacks on all enrolled records in a transaction.
188178
# The previous behavior was to only run the callbacks on the first copy of a record
189179
# if there were multiple copies of the same record enrolled in the transaction.
190180
#++
191-
# Rails.application.config.active_record.before_committed_on_all_records = true
181+
Rails.application.config.active_record.before_committed_on_all_records = true
192182

193183
###
194184
# Disable automatic column serialization into YAML.
195185
# To keep the historic behavior, you can set it to `YAML`, however it is
196186
# recommended to explicitly define the serialization method for each column
197187
# rather than to rely on a global default.
198188
#++
199-
# Rails.application.config.active_record.default_column_serializer = nil
189+
Rails.application.config.active_record.default_column_serializer = nil
200190

201191
###
202192
# Enable a performance optimization that serializes Active Record models
@@ -207,39 +197,24 @@
207197
# leave this optimization off on the first deploy, then enable it on a
208198
# subsequent deploy.
209199
#++
210-
# Rails.application.config.active_record.marshalling_format_version = 7.1
200+
Rails.application.config.active_record.marshalling_format_version = 7.1
211201

212202
###
213203
# Run `after_commit` and `after_*_commit` callbacks in the order they are defined in a model.
214204
# This matches the behaviour of all other callbacks.
215205
# In previous versions of Rails, they ran in the inverse order.
216206
#++
217-
# Rails.application.config.active_record.run_after_transaction_callbacks_in_order_defined = true
207+
Rails.application.config.active_record.run_after_transaction_callbacks_in_order_defined = true
218208

219209
###
220210
# Whether a `transaction` block is committed or rolled back when exited via `return`, `break` or `throw`.
221211
#++
222-
# Rails.application.config.active_record.commit_transaction_on_non_local_return = true
212+
Rails.application.config.active_record.commit_transaction_on_non_local_return = true
223213

224214
###
225215
# Controls when to generate a value for <tt>has_secure_token</tt> declarations.
226216
#++
227-
# Rails.application.config.active_record.generate_secure_token_on = :initialize
228-
229-
###
230-
# ** Please read carefully, this must be configured in config/application.rb **
231-
#
232-
# Change the format of the cache entry.
233-
#
234-
# Changing this default means that all new cache entries added to the cache
235-
# will have a different format that is not supported by Rails 7.0
236-
# applications.
237-
#
238-
# Only change this value after your application is fully deployed to Rails 7.1
239-
# and you have no plans to rollback.
240-
# When you're ready to change format, add this to `config/application.rb` (NOT
241-
# this file):
242-
# config.active_support.cache_format_version = 7.1
217+
Rails.application.config.active_record.generate_secure_token_on = :initialize
243218

244219
###
245220
# Configure Action View to use HTML5 standards-compliant sanitizers when they are supported on your
@@ -250,7 +225,7 @@
250225
#
251226
# In previous versions of Rails, Action View always used `Rails::HTML4::Sanitizer` as its vendor.
252227
#++
253-
# Rails.application.config.action_view.sanitizer_vendor = Rails::HTML::Sanitizer.best_supported_vendor
228+
Rails.application.config.action_view.sanitizer_vendor = Rails::HTML::Sanitizer.best_supported_vendor
254229

255230
###
256231
# Configure Action Text to use an HTML5 standards-compliant sanitizer when it is supported on your
@@ -261,13 +236,13 @@
261236
#
262237
# In previous versions of Rails, Action Text always used `Rails::HTML4::Sanitizer` as its vendor.
263238
#++
264-
# Rails.application.config.action_text.sanitizer_vendor = Rails::HTML::Sanitizer.best_supported_vendor
239+
Rails.application.config.action_text.sanitizer_vendor = Rails::HTML::Sanitizer.best_supported_vendor
265240

266241
###
267242
# Configure the log level used by the DebugExceptions middleware when logging
268243
# uncaught exceptions during requests.
269244
#++
270-
# Rails.application.config.action_dispatch.debug_exception_log_level = :error
245+
Rails.application.config.action_dispatch.debug_exception_log_level = :error
271246

272247
###
273248
# Configure the test helpers in Action View, Action Dispatch, and rails-dom-testing to use HTML5
@@ -277,4 +252,4 @@
277252
#
278253
# In previous versions of Rails, these test helpers always used an HTML4 parser.
279254
#++
280-
# Rails.application.config.dom_testing_default_html_version = :html5
255+
Rails.application.config.dom_testing_default_html_version = :html5

spec/features/listing_events_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require 'spec_helper'
2-
require 'events_controller'
32

43
RSpec.feature 'event listing', type: :feature do
54
describe 'I can see the names and titles of events' do

0 commit comments

Comments
 (0)