From 6107f51b19ee1973006f56edb8253e59e3e77f26 Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Thu, 4 Jan 2018 20:19:38 -0400 Subject: [PATCH] Add specs for valid sitemap generation (#2219) --- spec/lib/tasks/sitemap_spec.rb | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 spec/lib/tasks/sitemap_spec.rb diff --git a/spec/lib/tasks/sitemap_spec.rb b/spec/lib/tasks/sitemap_spec.rb new file mode 100644 index 000000000..64de41447 --- /dev/null +++ b/spec/lib/tasks/sitemap_spec.rb @@ -0,0 +1,48 @@ +require 'rake' +require 'rails_helper' +Rails.application.load_tasks +Rake::Task.define_task(:environment) + +feature 'rake sitemap:create' do + before do + @file ||= Rails.root.join('public', 'sitemap.xml') + + # To avoid spec failures if file does not exist + # Useful on CI environments or if file was created + # previous to the specs (to ensure a clean state) + File.delete(@file) if File.exist?(@file) + + Rake::Task['sitemap:create'].reenable + Rake.application.invoke_task('sitemap:create') + end + + it 'generates a sitemap' do + expect(@file).to exist + end + + it 'generates a valid sitemap' do + sitemap = Nokogiri::XML(File.open(@file)) + expect(sitemap.errors).to be_empty + end + + it 'generates a sitemap with expected and valid URLs' do + sitemap = File.read(@file) + + # Static pages + expect(sitemap).to include(faq_path) + expect(sitemap).to include(more_info_path) + expect(sitemap).to include(how_to_use_path) + expect(sitemap).to include(page_path(id: 'general_terms')) + + # Dynamic URLs + expect(sitemap).to include(polls_path) + expect(sitemap).to include(budgets_path) + expect(sitemap).to include(debates_path) + expect(sitemap).to include(proposals_path) + expect(sitemap).to include(spending_proposals_path) + expect(sitemap).to include(legislation_processes_path) + + expect(sitemap).to have_content('0.7', count: 6) + expect(sitemap).to have_content('daily', count: 6) + end +end