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