diff --git a/app/services/all_fields_label_migration.rb b/app/services/all_fields_label_migration.rb new file mode 100644 index 00000000..2a732e96 --- /dev/null +++ b/app/services/all_fields_label_migration.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AllFieldsLabelMigration + def self.run + Spotlight::BlacklightConfiguration.all.each do |bc| + bc.search_fields["all_fields"][:label] = "Keyword" + bc.save + end + end +end diff --git a/lib/tasks/migrate.rake b/lib/tasks/migrate.rake index 1ff8170a..7b6ede1a 100644 --- a/lib/tasks/migrate.rake +++ b/lib/tasks/migrate.rake @@ -5,4 +5,9 @@ namespace :migrate do task date_sort: :environment do DateSortMigration.run end + + desc "Migrate all_fields search field label from Everything to Keyword" + task all_fields_label: :environment do + AllFieldsLabelMigration.run + end end diff --git a/spec/services/all_fields_label_migration_spec.rb b/spec/services/all_fields_label_migration_spec.rb new file mode 100644 index 00000000..c3d7d6a2 --- /dev/null +++ b/spec/services/all_fields_label_migration_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe AllFieldsLabelMigration do + # since code is changed; newly-generated exhibits will get the correct label; + # set them to the old label so we can test. + before do + FactoryBot.create(:exhibit) + FactoryBot.create(:exhibit) + Spotlight::BlacklightConfiguration.all.each do |bc| + bc.search_fields["all_fields"][:label] = "Everything" + bc.save + end + end + + it "changes the label for all_fields search field from Everything to Keyword" do + expect(exhibit_configs.flatten.uniq).to eq ["Everything"] + expect(browse_configs.flatten.uniq).to eq ["Everything"] + described_class.run + expect(exhibit_configs.flatten.uniq).to eq ["Keyword"] + expect(browse_configs.flatten.uniq).to eq ["Keyword"] + end + + def exhibit_configs + Spotlight::Exhibit.all.to_a.map { |e| e.blacklight_config.search_fields["all_fields"][:label] } + end + + def browse_configs + Spotlight::Exhibit.all.to_a.map { |e| e.searches.first.blacklight_config.search_fields["all_fields"][:label] } + end +end