From b7a4de335e4581c034b61046fb8e48e4f0203661 Mon Sep 17 00:00:00 2001 From: Martha Thompson <437455+MothOnMars@users.noreply.github.com> Date: Fri, 12 Oct 2018 12:11:23 -0700 Subject: [PATCH] SRCH-48 index sitemaps upon creation (#152) --- app/models/sitemap.rb | 2 ++ spec/models/sitemap_spec.rb | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/models/sitemap.rb b/app/models/sitemap.rb index 9e97a0d49c..302cdf1a93 100644 --- a/app/models/sitemap.rb +++ b/app/models/sitemap.rb @@ -7,6 +7,8 @@ class Sitemap < ActiveRecord::Base before_validation :set_searchgov_domain, on: :create + after_create { SitemapIndexerJob.perform_later(sitemap_url: url) } + validates_associated :searchgov_domain, on: :create validates_presence_of :searchgov_domain, on: :create diff --git a/spec/models/sitemap_spec.rb b/spec/models/sitemap_spec.rb index 205740b958..4d90f80b73 100644 --- a/spec/models/sitemap_spec.rb +++ b/spec/models/sitemap_spec.rb @@ -7,7 +7,10 @@ it { is_expected.to have_readonly_attribute(:url) } describe 'schema' do - it { is_expected.to have_db_column(:url).of_type(:string).with_options(null: false, limit: 2000) } + it do + is_expected.to have_db_column(:url).of_type(:string). + with_options(null: false, limit: 2000) + end end describe 'validations' do @@ -24,6 +27,15 @@ end end + describe 'lifecycle' do + describe 'on create' do + it 'is automatically indexed' do + expect(SitemapIndexerJob).to receive(:perform_later).with(sitemap_url: url) + Sitemap.create!(url: url) + end + end + end + it_should_behave_like 'a record with a fetchable url' it_should_behave_like 'a record that belongs to a searchgov_domain' end