Skip to content

Commit

Permalink
SRCH-48 index sitemaps upon creation (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
MothOnMars authored Oct 12, 2018
1 parent 4b53bb1 commit b7a4de3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/models/sitemap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 13 additions & 1 deletion spec/models/sitemap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit b7a4de3

Please sign in to comment.