From becc7251d9fecd03b7761acfbfac0f9515060ea1 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Tue, 30 Jan 2024 10:37:38 -0600 Subject: [PATCH] Pass the class argument to serialize as a keyword The positional argument is deprecated and will be removed in rails 7.2 --- .../spotlight/blacklight_configuration.rb | 30 +++++++++++++------ app/models/spotlight/contact.rb | 7 +++-- app/models/spotlight/custom_field.rb | 6 +++- app/models/spotlight/custom_search_field.rb | 6 +++- app/models/spotlight/exhibit.rb | 7 +++-- app/models/spotlight/resource.rb | 6 +++- app/models/spotlight/search.rb | 8 +++-- app/models/spotlight/solr_document_sidecar.rb | 10 +++++-- 8 files changed, 60 insertions(+), 20 deletions(-) diff --git a/app/models/spotlight/blacklight_configuration.rb b/app/models/spotlight/blacklight_configuration.rb index 8c545f884a..77e6b4a65f 100644 --- a/app/models/spotlight/blacklight_configuration.rb +++ b/app/models/spotlight/blacklight_configuration.rb @@ -10,15 +10,27 @@ class BlacklightConfiguration < ActiveRecord::Base has_paper_trail belongs_to :exhibit, touch: true, optional: true - serialize :facet_fields, Hash, coder: YAML - serialize :index_fields, Hash, coder: YAML - serialize :search_fields, Hash, coder: YAML - serialize :sort_fields, Hash, coder: YAML - serialize :default_solr_params, Hash, coder: YAML - serialize :show, Hash, coder: YAML - serialize :index, Hash, coder: YAML - serialize :per_page, Array, coder: YAML - serialize :document_index_view_types, Array, coder: YAML + if Rails.version > '7' + serialize :facet_fields, Hash, coder: YAML + serialize :index_fields, Hash, coder: YAML + serialize :search_fields, Hash, coder: YAML + serialize :sort_fields, Hash, coder: YAML + serialize :default_solr_params, Hash, coder: YAML + serialize :show, Hash, coder: YAML + serialize :index, Hash, coder: YAML + serialize :per_page, Array, coder: YAML + serialize :document_index_view_types, Array, coder: YAML + else + serialize :facet_fields, type: Hash, coder: YAML + serialize :index_fields, type: Hash, coder: YAML + serialize :search_fields, type: Hash, coder: YAML + serialize :sort_fields, type: Hash, coder: YAML + serialize :default_solr_params, type: Hash, coder: YAML + serialize :show, type: Hash, coder: YAML + serialize :index, type: Hash, coder: YAML + serialize :per_page, type: Array, coder: YAML + serialize :document_index_view_types, type: Array, coder: YAML + end include Spotlight::BlacklightConfigurationDefaults diff --git a/app/models/spotlight/contact.rb b/app/models/spotlight/contact.rb index 13547cfc20..71fd693bdb 100644 --- a/app/models/spotlight/contact.rb +++ b/app/models/spotlight/contact.rb @@ -7,8 +7,11 @@ class Contact < ActiveRecord::Base belongs_to :exhibit, touch: true, optional: true scope :published, -> { where(show_in_sidebar: true) } default_scope { order('weight ASC') } - serialize :contact_info, Hash, coder: YAML - + if Rails.version > '7' + serialize :contact_info, Hash, coder: YAML + else + serialize :contact_info, type: Hash, coder: YAML + end extend FriendlyId friendly_id :name, use: %i[slugged scoped finders], scope: :exhibit diff --git a/app/models/spotlight/custom_field.rb b/app/models/spotlight/custom_field.rb index eecf4a3a55..12f8a53dbd 100644 --- a/app/models/spotlight/custom_field.rb +++ b/app/models/spotlight/custom_field.rb @@ -4,7 +4,11 @@ module Spotlight ## # Exhibit custom fields class CustomField < ActiveRecord::Base - serialize :configuration, Hash, coder: YAML + if Rails.version > '7' + serialize :configuration, Hash, coder: YAML + else + serialize :configuration, type: Hash, coder: YAML + end belongs_to :exhibit, optional: true extend FriendlyId diff --git a/app/models/spotlight/custom_search_field.rb b/app/models/spotlight/custom_search_field.rb index 86c2a4fb4f..8fd3450d7e 100644 --- a/app/models/spotlight/custom_search_field.rb +++ b/app/models/spotlight/custom_search_field.rb @@ -3,7 +3,11 @@ module Spotlight # Exhibit-specific custom search fields class CustomSearchField < ApplicationRecord - serialize :configuration, Hash, coder: YAML + if Rails.version > '7' + serialize :configuration, Hash, coder: YAML + else + serialize :configuration, type: Hash, coder: YAML + end belongs_to :exhibit def label=(label) diff --git a/app/models/spotlight/exhibit.rb b/app/models/spotlight/exhibit.rb index 51a248473f..5e5c847bb5 100644 --- a/app/models/spotlight/exhibit.rb +++ b/app/models/spotlight/exhibit.rb @@ -35,8 +35,11 @@ class Exhibit < ActiveRecord::Base acts_as_tagger acts_as_taggable delegate :blacklight_config, to: :blacklight_configuration - serialize :facets, Array, coder: YAML - + if Rails.version > '7' + serialize :facets, Array, coder: YAML + else + serialize :facets, type: Array, coder: YAML + end # NOTE: friendly id associations need to be 'destroy'ed to reap the slug history has_many :about_pages, -> { for_default_locale }, extend: FriendlyId::FinderMethods has_many :attachments, dependent: :destroy diff --git a/app/models/spotlight/resource.rb b/app/models/spotlight/resource.rb index 3cdce98268..9dd9f4ae13 100644 --- a/app/models/spotlight/resource.rb +++ b/app/models/spotlight/resource.rb @@ -25,7 +25,11 @@ class Resource < ActiveRecord::Base has_many :solr_document_sidecars has_many :events, as: :resource - serialize :data, Hash, coder: YAML + if Rails.version > '7' + serialize :data, Hash, coder: YAML + else + serialize :data, type: Hash, coder: YAML + end ## # Persist the record to the database, and trigger a reindex to solr diff --git a/app/models/spotlight/search.rb b/app/models/spotlight/search.rb index c53c02ddcc..9279177adb 100644 --- a/app/models/spotlight/search.rb +++ b/app/models/spotlight/search.rb @@ -17,9 +17,13 @@ class Search < ActiveRecord::Base accepts_nested_attributes_for :group_memberships accepts_nested_attributes_for :groups if defined?(Blacklight::SearchParamsYamlCoder) - serialize :query_params, Blacklight::SearchParamsYamlCoder, default: -> { {} } + serialize :query_params, coder: Blacklight::SearchParamsYamlCoder, default: -> { {} } else - serialize :query_params, Hash + if Rails.version > '7' # rubocop:disable Style/IfInsideElse + serialize :query_params, Hash + else + serialize :query_params, type: Hash + end end default_scope { order('weight ASC') } scope :published, -> { where(published: true) } diff --git a/app/models/spotlight/solr_document_sidecar.rb b/app/models/spotlight/solr_document_sidecar.rb index 7ef0ef0355..f99f183e95 100644 --- a/app/models/spotlight/solr_document_sidecar.rb +++ b/app/models/spotlight/solr_document_sidecar.rb @@ -11,8 +11,14 @@ class SolrDocumentSidecar < ActiveRecord::Base belongs_to :exhibit, optional: false belongs_to :resource, optional: true belongs_to :document, optional: false, polymorphic: true - serialize :data, Hash, coder: YAML - serialize :index_status, Hash, coder: YAML + + if Rails.version > '7' + serialize :data, Hash, coder: YAML + serialize :index_status, Hash, coder: YAML + else + serialize :data, type: Hash, coder: YAML + serialize :index_status, type: Hash, coder: YAML + end delegate :has_key?, :key?, to: :data