From ef9611d745d007823aa00a1b6223f9ee1d82aca8 Mon Sep 17 00:00:00 2001 From: Molly Struve Date: Fri, 14 Feb 2020 14:17:52 -0500 Subject: [PATCH] Create DataUpdateScript to Index all Tags (#6078) [deploy] --- .../20200214171607_index_tags_to_elasticsearch.rb | 9 +++++++++ .../index_tags_to_elasticsearch_spec.rb | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 lib/data_update_scripts/20200214171607_index_tags_to_elasticsearch.rb create mode 100644 spec/lib/data_update_scripts/index_tags_to_elasticsearch_spec.rb diff --git a/lib/data_update_scripts/20200214171607_index_tags_to_elasticsearch.rb b/lib/data_update_scripts/20200214171607_index_tags_to_elasticsearch.rb new file mode 100644 index 000000000..c5428d8e4 --- /dev/null +++ b/lib/data_update_scripts/20200214171607_index_tags_to_elasticsearch.rb @@ -0,0 +1,9 @@ +module DataUpdateScripts + class IndexTagsToElasticsearch + def run + # Choose to do inline so development envs are ready + # immediately after this is run + Tag.find_each(&:index_to_elasticsearch_inline) + end + end +end diff --git a/spec/lib/data_update_scripts/index_tags_to_elasticsearch_spec.rb b/spec/lib/data_update_scripts/index_tags_to_elasticsearch_spec.rb new file mode 100644 index 000000000..29b1cf546 --- /dev/null +++ b/spec/lib/data_update_scripts/index_tags_to_elasticsearch_spec.rb @@ -0,0 +1,11 @@ +require "rails_helper" +require Rails.root.join("lib/data_update_scripts/20200214171607_index_tags_to_elasticsearch.rb") + +describe DataUpdateScripts::IndexTagsToElasticsearch, elasticsearch: true do + it "indexes tags to Elasticsearch" do + tag = FactoryBot.create(:tag) + expect { tag.elasticsearch_doc }.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound) + described_class.new.run + expect(tag.elasticsearch_doc).not_to be_nil + end +end