Skip to content

Commit

Permalink
Merge pull request #418 from murny/refactor-sitemap-tests
Browse files Browse the repository at this point in the history
Move sitemap tests into integration and remove setup and repeated get…
  • Loading branch information
mbarnett authored Jan 31, 2018
2 parents 0a812a6 + 0a75315 commit 8762341
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ GEM
mustermann (1.0.1)
mysql2 (0.4.10)
nio4r (2.1.0)
nokogiri (1.8.1)
nokogiri (1.8.2)
mini_portile2 (~> 2.3.0)
om (3.1.1)
activemodel
Expand Down
5 changes: 1 addition & 4 deletions app/views/profile/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<% page_title(@user.name) %>

<div class="mb-3">
<h1><%= @user.name %></h1>
</div>
<h1 class="mb-3"><%= @user.name %></h1>

<dl class="row">
<dt class="col-sm-3"><%= t('admin.users.created') %></dt>
Expand All @@ -14,7 +12,6 @@
<dd class="col-sm-9">
<%= @user.email %>
</dd>

</dl>

<%= render partial: 'user_items',
Expand Down
2 changes: 1 addition & 1 deletion app/views/sitemap/collections.xml.builder
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cache 'sitemap', expires_in: 24.hours do
@collections.each do |collection|
xml.url do
xml.loc community_collection_url(collection.community, collection)
xml.lastmod collection.updated_at
xml.lastmod collection.updated_at.utc.iso8601
xml.changefreq 'weekly'
xml.priority 1
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/sitemap/communities.xml.builder
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cache 'sitemap', expires_in: 24.hours do
@communities.each do |community|
xml.url do
xml.loc community_url(community)
xml.lastmod community.updated_at
xml.lastmod community.updated_at.utc.iso8601
xml.changefreq 'weekly'
xml.priority 1
end
Expand Down
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,59 +98,50 @@ 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
assert_select 'lastmod', @collection.updated_at.utc.iso8601
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
assert_select 'lastmod', @community.updated_at.utc.iso8601
end
end

Expand Down

0 comments on commit 8762341

Please sign in to comment.