Skip to content

Instantly share code, notes, and snippets.

@rgm
Last active August 29, 2015 14:21
Show Gist options
  • Save rgm/7fe2e3cd8088df03edbf to your computer and use it in GitHub Desktop.
Save rgm/7fe2e3cd8088df03edbf to your computer and use it in GitHub Desktop.
require 'test_helper'
class PermanentRedirectTest < ActionDispatch::IntegrationTest
# in all cases, no matter how byzantine the setup, the goals are:
# 1. get new episodes without the user having to re-subscribe
# 2. don't fire out duped episodes if we can help it.
test "gentlemanly df-style itunes redirect" do
podcast = create_itunes_redirected_podcast \
old: "http://oldfeed.example.org/",
new: "http://newfeed.example.org"
a = Account.new
a.subscribe_to "http://oldfeed.example.org/"
assert a.subscribed_to? "http://oldfeed.example.org"
podcast.start_redirecting!
refute a.subscribed_to? "http://oldfeed.example.org"
assert a.subscribed_to? "http://newfeed.example.org"
# maybe keep old if podcasts immutable?
maybe_moved_event = a.event_stream.filter "podcast:moved"
refute_nil maybe_moved_event
old_count = a.event_stream.filter "episode:published"
podcast.publish_new_episode!
new_count = a.event_stream.filter "episode:published"
assert_equal new_count, old_count + 1
end
test "301 for first-ever fetch" do
# relatively easy, no existing state to manage
skip
podcast = create_301_redirected_podcast \
old: "http://oldfeed.example.org/",
new: "http://newfeed.example.org"
podcast.start_redirecting!
a = Account.new
a.subscribe_to "http://oldfeed.example.org/"
assert a.subscribed_to? "http://newfeed.example.org"
# ensure new subscribers with old info are OK too
b = Account.new
b.subscribe_to "http://oldfeed.example.org/"
assert b.subscribed_to? "http://newfeed.example.org"
end
test "301 to existing podcast with existing subscribers" do
# this is the Myke tests a new feed before officially 301'ing scenario
skip
old_feed = create_podcast "http://oldfeed.example.org/"
new_feed = create_podcast "http://newfeed.example.org/"
anon = Account.new
anon.subscribe_to "http://oldfeed.example.org/"
assert a.subscribed_to? "http://oldfeed.example.org"
old_feed.publish_new_episode!
myke = Account.new
myke = subscribe_to "http://newfeed.example.org/"
assert myke.subscribed_to? "http://newfeed.example.org"
new_feed.publish_new_episode!
old_feed.start_301_redirecting_to! new_feed
refute anon.subscribed_to? "http://oldfeed.example.org"
assert anon.subscribed_to? "http://newfeed.example.org"
assert_equal 2, anon.event_stream.filter("episode:published").count
assert_equal 1, myke.event_stream.filter("episode:published").count
new_feed.publish_new_episode!
assert_equal 3, anon.event_stream.filter("episode:published").count
assert_equal 2, myke.event_stream.filter("episode:published").count
end
test "301 with existing subscribers to not-already-existing podcast" do
# hopefully the common case
old_feed = create_podcast "http://oldfeed.example.org/"
anon = Account.new
anon.subscribe_to "http://oldfeed.example.org/"
assert a.subscribed_to? "http://oldfeed.example.org"
old_feed.publish_new_episode!
assert_equal 1, anon.event_stream.filter("episode:published").count
new_feed = create_podcast "http://newfeed.example.org/"
old_feed.start_301_redirecting_to! new_feed
refute anon.subscribed_to? "http://oldfeed.example.org"
assert anon.subscribed_to? "http://newfeed.example.org"
# THINK what happens if old guids are already in new feed?
new_feed.publish_new_episode!
assert_equal 2, anon.event_stream.filter("episode:published").count
end
test "crazy hijacking 301 attempt" do
skip
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment