-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Requesting the atom feed through Chrome gives us a HTML response. Instead we make a direct request and parse it using Ruby’s RSS library.
- Loading branch information
1 parent
2c7c9dc
commit cabafae
Showing
1 changed file
with
24 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,52 @@ | ||
require 'test_helper' | ||
|
||
require 'nokogiri/html' | ||
require 'open-uri' | ||
require 'rss' | ||
|
||
class TravelAdviceAtomFeed < ActionDispatch::IntegrationTest | ||
setup do | ||
setup_and_visit_travel_advice_atom_feed('full-country') | ||
setup_and_parse_travel_advice_atom_feed('full-country') | ||
@base_path = @content_item['base_path'] | ||
@updated_at = DateTime.parse(@content_item["public_updated_at"]).rfc3339 | ||
end | ||
|
||
test "it sets the alternative link correctly" do | ||
assert page.has_css?("feed>link[rel='alternate'][href$='#{@base_path}']") | ||
alternate_link = @feed.links.find { |link| link.rel == 'alternate' } | ||
assert alternate_link.href.ends_with?(@base_path) | ||
end | ||
|
||
test "it sets the entry's id to the url concatenated with updated_at" do | ||
id = page.find("feed>entry>id").text(:all) | ||
id = @feed.items.first.id.content | ||
assert id.end_with?("#{@base_path}##{@updated_at}") | ||
end | ||
|
||
test "it sets the entry's title correctly" do | ||
title = page.find("feed>entry>title").text(:all) | ||
title = @feed.items.first.title.content | ||
assert_equal title, @content_item['title'] | ||
end | ||
|
||
test "it sets the entry's summary correctly" do | ||
summary = page.find("feed>entry>summary").text(:all) | ||
assert_equal summary, @content_item['details']['change_description'].strip | ||
summary = Nokogiri::HTML::fragment(@feed.items.first.summary.content) | ||
assert_equal summary.text.strip, @content_item['details']['change_description'].strip | ||
end | ||
|
||
test "it sets the entry's updated correctly" do | ||
updated = page.find("feed>entry>updated").text(:all) | ||
updated = @feed.items.first.updated.content | ||
assert_equal updated, @updated_at | ||
end | ||
|
||
def setup_and_visit_travel_advice_atom_feed(name) | ||
example = get_content_example_by_schema_and_name('travel_advice', name) | ||
@content_item = example.tap do |item| | ||
content_store_has_item(item["base_path"], item.to_json) | ||
visit "#{item['base_path']}.atom" | ||
end | ||
def setup_and_parse_travel_advice_atom_feed(name) | ||
@content_item = get_content_example_by_schema_and_name('travel_advice', name) | ||
|
||
uri = URI::HTTP.build( | ||
host: Capybara.current_session.server.host, | ||
port: Capybara.current_session.server.port, | ||
path: "#{@content_item['base_path']}.atom" | ||
) | ||
|
||
content_store_has_item(@content_item["base_path"], @content_item.to_json) | ||
|
||
@feed = RSS::Parser.parse(uri.read) | ||
end | ||
end |