-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support RSS feeds for specific topics (essentially combining current /feed
and /topic
functionality)
#430
base: master
Are you sure you want to change the base?
Support RSS feeds for specific topics (essentially combining current /feed
and /topic
functionality)
#430
Changes from all commits
ae128ff
4138f9f
bd39d68
1755cba
4de03ec
d639024
a4665d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"> | ||
<channel> | ||
<title>Changelog: <%= @topic_name %></title> | ||
<copyright>All rights reserved</copyright> | ||
<link><%= Routes.root_url(@conn, :index) %></link> | ||
<atom:link href="<%= Routes.feed_url(@conn, :news) %>" rel="self" type="application/rss+xml" /> | ||
<atom:link href="<%= Routes.root_url(@conn, :index) %>" rel="alternate" type="text/html" /> | ||
<language>en-us</language> | ||
<description><%= @topic_description %></description> | ||
<%= for item <- @items do %> | ||
<item> | ||
<%= render_item(item, assigns) %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This pattern matches to |
||
</item> | ||
<% end %> | ||
</channel> | ||
</rss> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,4 +140,93 @@ defmodule ChangelogWeb.FeedControllerTest do | |
refute conn.resp_body =~ p2.title | ||
assert conn.resp_body =~ p3.title | ||
end | ||
|
||
describe "Topic feed" do | ||
setup [:setup_topic_feed_tests] | ||
|
||
test "the topic feed", %{ | ||
conn: conn, | ||
topics: topics, | ||
news_items_with_topics: news_items_with_topics, | ||
posts_with_topics: posts_with_topics, | ||
podcast_episodes_with_topics: podcast_episodes_with_topics | ||
} do | ||
topic_slug = "rust" | ||
conn = get(conn, Routes.feed_path(conn, :topic, topic_slug)) | ||
|
||
assert conn.status == 200 | ||
assert valid_xml(conn) | ||
end | ||
|
||
test "the topic's news feed", %{ | ||
conn: conn, | ||
topics: topics, | ||
news_items_with_topics: news_items_with_topics, | ||
posts_with_topics: posts_with_topics, | ||
podcast_episodes_with_topics: podcast_episodes_with_topics | ||
} do | ||
topic_slug = "rust" | ||
conn = get(conn, Routes.feed_path(conn, :topic_news, topic_slug)) | ||
|
||
assert conn.status == 200 | ||
assert valid_xml(conn) | ||
end | ||
|
||
test "the topic's podcasts feed", %{ | ||
conn: conn, | ||
topics: topics, | ||
news_items_with_topics: news_items_with_topics, | ||
posts_with_topics: posts_with_topics, | ||
podcast_episodes_with_topics: podcast_episodes_with_topics | ||
} do | ||
topic_slug = "rust" | ||
conn = get(conn, Routes.feed_path(conn, :topic_podcasts, topic_slug)) | ||
|
||
assert conn.status == 200 | ||
assert valid_xml(conn) | ||
|
||
topic = topics[topic_slug] | ||
assert conn.resp_body =~ topic.name | ||
assert conn.resp_body =~ topic.description | ||
|
||
Enum.each(posts_with_topics, fn post_with_topic -> | ||
assert conn.resp_body =~ post_with_topic.post.title | ||
assert conn.resp_body =~ post_with_topic.post.body | ||
end) | ||
|
||
Enum.each(podcast_episodes_with_topics, fn podcast_episode_with_topic -> | ||
assert conn.resp_body =~ podcast_episode_with_topic.episode.title | ||
assert conn.resp_body =~ podcast_episode_with_topic.episode.summary | ||
end) | ||
end | ||
end | ||
|
||
defp setup_topic_feed_tests(context) do | ||
# Add some topics | ||
t1 = insert(:topic, slug: "rust", name: "Rust", description: "Rust is a systems programming language created by Mozilla.") | ||
# Create some news items | ||
ni1 = insert(:published_news_item, headline: "Rust is pretty cool", story: "Use it or lose it") | ||
# Associate those news items with topics | ||
nit1 = insert(:news_item_topic, topic: t1, news_item: ni1) | ||
|
||
# Add a post | ||
post1 = insert(:published_post, body: "Can you believe this Rust thing?!") | ||
pt1 = insert(:post_topic, post: post1, topic: t1) | ||
|
||
# Add a podcast | ||
pod1 = insert(:podcast, name: "Rust Crust", slug: "rustcrust", description: "Rust is neat") | ||
# Add a podcast episode | ||
e1 = insert(:published_episode, podcast: pod1) | ||
# Associate that episode with a topic | ||
et1 = insert(:episode_topic, episode: e1, topic: t1) | ||
|
||
%{ | ||
topics: %{ | ||
"rust" => t1 | ||
}, | ||
news_items_with_topics: [nit1], | ||
posts_with_topics: [pt1], | ||
podcast_episodes_with_topics: [et1] | ||
} | ||
end | ||
Comment on lines
+204
to
+231
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Currently trying to figure out why this test is failing. I think my test setup with the various |
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
render_topic(conn, topic, items)
🐛