Skip to content

Commit

Permalink
Merge pull request #2618 from MushroomObserver/try-loading-all-config…
Browse files Browse the repository at this point in the history
…-7.1-defaults

Get some defaults/deprecations ready for Rails 7.2
  • Loading branch information
nimmolo authored Jan 3, 2025
2 parents af2dd34 + 094566c commit 528c2de
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 26 deletions.
37 changes: 21 additions & 16 deletions app/helpers/namings_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ def your_vote_html(naming, vote)
# N+1: should not be checking permission here
# N+1: vote is naming.users_vote, so should be an instance of Vote.
# NamingsController#index iteration over namings in table_row
# This could be a form with model: vote so it can has an id, sent in url
# rubocop:disable Metrics/MethodLength
# This may be a form_with(model: vote) so it gets an id, sent in url
def naming_vote_form(naming, vote, context: "blank")
vote_id = vote&.id
method = vote_id ? :patch : :post
Expand All @@ -262,25 +261,13 @@ def naming_vote_form(naming, vote, context: "blank")
else
Vote.confidence_menu
end
localizations = {
lose_changes: :show_namings_lose_changes.l.tr("\n", " "),
saving: :show_namings_saving.l
}.to_json

form_with(
model: vote,
url: naming_vote_form_commit_url(naming, vote), method: method,
id: "naming_vote_form_#{naming.id}",
class: "naming-vote-form d-inline-block float-right float-sm-none",
data: { turbo: true, controller: "naming-vote", naming_id: naming.id,
localization: localizations }
) do |fv|
form_with(**naming_vote_form_args(naming, vote, method)) do |fv|
[
fv.select(:value, menu, {},
{ class: "form-control w-100",
id: "vote_value_#{naming.id}",
data: { naming_vote_target: "select",
localization: localizations,
action: "naming-vote#sendVote" } }),
hidden_field_tag(:context, context),
tag.noscript do
Expand All @@ -291,10 +278,28 @@ def naming_vote_form(naming, vote, context: "blank")
].safe_join
end
end
# rubocop:enable Metrics/MethodLength

private

def naming_vote_form_args(naming, vote, method)
args = {
url: naming_vote_form_commit_url(naming, vote), method: method,
id: "naming_vote_form_#{naming.id}",
class: "naming-vote-form d-inline-block float-right float-sm-none",
data: { turbo: true, controller: "naming-vote", naming_id: naming.id,
localization: naming_vote_form_localizations }
}
args = args.merge(model: vote) if vote
args
end

def naming_vote_form_localizations
{
lose_changes: :show_namings_lose_changes.l.tr("\n", " "),
saving: :show_namings_saving.l
}.to_json
end

# form can commit to update or create
def naming_vote_form_commit_url(naming, vote)
if vote&.id
Expand Down
3 changes: 2 additions & 1 deletion app/models/inat_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class InatImport < ApplicationRecord

belongs_to :user

serialize :log, type: Array
serialize :log, type: Array, coder: YAML

def add_response_error(error)
response_errors << "#{error.class.name}: #{error.message}\n"
save
Expand Down
2 changes: 1 addition & 1 deletion app/models/naming.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Naming < AbstractModel
belongs_to :user
has_many :votes, dependent: :destroy

serialize :reasons
serialize :reasons, coder: YAML

before_save :did_name_change?
before_save :enforce_default_reasons
Expand Down
2 changes: 1 addition & 1 deletion app/models/observation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ def saved_change_to_place?
# Notes are exported as shown, except that the intial "Notes:" caption is
# omitted, and any markup is stripped from the keys.

serialize :notes
serialize :notes, coder: YAML

# value of observation.notes if there are no notes
def self.no_notes
Expand Down
6 changes: 3 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class User < AbstractModel # rubocop:disable Metrics/ClassLength
belongs_to :license # user's default license
belongs_to :location # primary location

serialize :content_filter, type: Hash
serialize :content_filter, type: Hash, coder: YAML

##############################################################################
#
Expand All @@ -344,8 +344,8 @@ class User < AbstractModel # rubocop:disable Metrics/ClassLength

# This causes the data structures in these fields to be serialized
# automatically with YAML and stored as plain old text strings.
serialize :bonuses
serialize :alert
serialize :bonuses, coder: YAML
serialize :alert, coder: YAML

scope :by_contribution, lambda {
order(contribution: :desc, name: :asc, login: :asc)
Expand Down
6 changes: 3 additions & 3 deletions app/models/user_stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ class UserStats < ApplicationRecord

# This causes the data structures in these fields to be serialized
# automatically with YAML and stored as plain old text strings.
serialize :languages, type: Hash
serialize :bonuses
serialize :checklist, type: Hash
serialize :languages, type: Hash, coder: YAML
serialize :bonuses, coder: YAML
serialize :checklist, type: Hash, coder: YAML

ALL_FIELDS = {
name_description_authors: { weight: 100 },
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Application < Rails::Application

# Uncomment this after migrating to all recommended default configs for 7.1
# config/initializers/new_framework_defaults_7_1.rb
# config.load_defaults = 7.1
# config.load_defaults(7.1)

# Set Time.zone default to the specified zone and
# make Active Record auto-convert to this zone.
Expand Down

0 comments on commit 528c2de

Please sign in to comment.