Skip to content

Commit

Permalink
Move sitemap tests into integration and remove setup and repeated get…
Browse files Browse the repository at this point in the history
… requests
  • Loading branch information
murny committed Jan 31, 2018
1 parent 0a812a6 commit 9d48c58
Showing 1 changed file with 16 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'test_helper'
require 'open-uri'

class SitemapTest < ActionDispatch::IntegrationTest

Expand Down Expand Up @@ -54,15 +53,13 @@ def before_all
end

context 'sitemap index' do
setup do
get sitemapindex_url
end
should 'be valid sitemapindex xml' do
get sitemapindex_url

schema = Nokogiri::XML::Schema(File.open(file_fixture('siteindex.xsd')))
document = Nokogiri::XML(@response.body)
assert_empty schema.validate(document)
end
should 'show sitemap for each of communities, collections, items and thesis' do

assert_select 'sitemap', 4
assert_select 'loc', /sitemap-items.xml/
assert_select 'loc', /sitemap-theses.xml/
Expand All @@ -72,24 +69,22 @@ def before_all
end

context 'items sitemap' do
setup do
get items_sitemap_url
end
should 'be valid sitemap xml' do
get items_sitemap_url

schema = Nokogiri::XML::Schema(File.open(file_fixture('sitemap.xsd')))
document = Nokogiri::XML(@response.body)
assert_empty schema.validate(document)
end
should 'show url, last modified date, change frequency, priority and type' do

assert_select 'url' do
assert_select 'loc'
assert_select 'lastmod'
assert_select 'changefreq'
assert_select 'priority'
assert_select 'rs|md[type=?]', 'text/html'
end
end
should 'show public item attributes' do

# show public item attributes
assert_select 'loc', item_url(@item)
assert_select 'lastmod', @item.updated_at.to_s
@item.file_sets.first.unlock_and_fetch_ldp_object do |uo|
Expand All @@ -103,57 +98,48 @@ def before_all
assert_select 'rs|ln[length=?]', uo.original_file.size.to_s
assert_select 'rs|ln[type=?]', uo.original_file.mime_type.to_s
end
end

should 'not show private items' do
# not show private items
assert_select 'url', count: 2
assert_select 'loc', { count: 0, text: item_url(@private_item) }, 'private items shant appear in the sitemap'
assert_select 'loc', { count: 0, text: item_url(@private_item) }, 'private items should not appear in the sitemap'
end
end

context 'collections sitemap' do
setup do
get collections_sitemap_url
end
should 'be valid sitemap xml' do
get collections_sitemap_url

schema = Nokogiri::XML::Schema(File.open(file_fixture('sitemap.xsd')))
document = Nokogiri::XML(@response.body)
assert_empty schema.validate(document)
end
should 'show url, last modified date, change frequency and priority' do

assert_select 'url' do
assert_select 'loc'
assert_select 'lastmod'
assert_select 'changefreq'
assert_select 'priority'
end
end
should 'show location and last modified' do

assert_select 'loc', community_collection_url(@collection.community, @collection)
assert_select 'lastmod', @collection.updated_at.to_s
end
end

context 'communities sitemap' do
setup do
get communities_sitemap_url
end
should 'be valid sitemap xml' do
get communities_sitemap_url

schema = Nokogiri::XML::Schema(File.open(file_fixture('sitemap.xsd')))
document = Nokogiri::XML(@response.body)
assert_empty schema.validate(document)
end
should 'show url, last modified date, change frequency and priority' do

assert_select 'url' do
assert_select 'loc'
assert_select 'lastmod'
assert_select 'changefreq'
assert_select 'priority'
end
end
should 'show location and last modified' do

assert_select 'loc', community_url(@community)
assert_select 'lastmod', @community.updated_at.to_s
end
Expand Down

0 comments on commit 9d48c58

Please sign in to comment.