Skip to content

Commit

Permalink
Add migration task for all_fields label
Browse files Browse the repository at this point in the history
refs #645
  • Loading branch information
hackartisan committed Oct 11, 2019
1 parent e25d7a9 commit 75b76fa
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/services/all_fields_label_migration.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions lib/tasks/migrate.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 32 additions & 0 deletions spec/services/all_fields_label_migration_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 75b76fa

Please sign in to comment.