Skip to content

Commit

Permalink
fixed that RSS caches weren't being expired [#3 state:resolved]
Browse files Browse the repository at this point in the history
  • Loading branch information
nakajima committed Jul 30, 2008
1 parent 85facf4 commit afe80b2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
2 changes: 2 additions & 0 deletions app/controllers/admin/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ def expire_post!
def expire_index!
expire_path('/index.html')
expire_path('/posts.html')
expire_path('/posts.rss')
expire_path('/posts')
expire_path("/#{@post.type.tableize}.html")
expire_path("/#{@post.type.tableize}.rss")
expire_path("/#{@post.type.tableize}")
end
end
3 changes: 3 additions & 0 deletions app/controllers/feeds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,16 @@ def refresh
def expire_index!
expire_path('/index.html')
expire_path('/posts.html')
expire_path('/posts.rss')
expire_path('/posts')
if request.symbolized_path_parameters[:action] != 'refresh'
expire_path("/#{@feed.class.entry_type}.html")
expire_path("/#{@feed.class.entry_type}.rss")
expire_path("/#{@feed.class.entry_type}")
else
%w(articles links pictures quotes snippets tweets).each do |entry_type|
expire_path("/#{entry_type}.html")
expire_path("/#{entry_type}.rss")
expire_path("/#{entry_type}")
end
end
Expand Down
30 changes: 18 additions & 12 deletions test/integration/caching_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def test_should_page_cache_snippets_index
end
end

def test_should_cache_posts_rss
assert_paths_cached('/posts.rss') do
get '/posts.rss'
end
end

# Show Caches

def test_should_page_cache_article_show_page
Expand Down Expand Up @@ -79,17 +85,17 @@ def test_should_expire_index
# Expiring main index

def test_should_expire_home_page_on_post_create
get_paths '/', '/posts/page/1', '/articles', '/articles/page/1'
assert_cache_expired('index.html', 'posts/', 'articles/', 'articles.html') do
get_paths '/', '/posts/page/1', '/articles', '/articles/page/1', '/posts.rss', '/articles.rss'
assert_cache_expired('index.html', 'posts/', 'articles/', 'articles.html', 'posts.rss', 'articles.rss') do
login_as :quentin
post '/admin/posts', :post => { :type => 'Article', :header => 'Something', :content => 'Something else' }
end
end

def test_should_expire_home_page_on_post_update
article = posts(:article)
get_paths '/', '/posts/page/1', '/articles', '/articles/page/1'
assert_cache_expired('index.html', 'posts/', 'articles/', 'articles.html') do
get_paths '/', '/posts/page/1', '/articles', '/articles/page/1', '/posts.rss', '/articles.rss'
assert_cache_expired('index.html', 'posts/', 'articles/', 'articles.html', 'posts.rss', 'articles.rss') do
login_as :quentin
put "/admin/articles/#{article.permalink}", :article => { :content => 'well this is different' }
assert_redirected_to admin_post_path(article)
Expand All @@ -98,26 +104,26 @@ def test_should_expire_home_page_on_post_update

def test_should_expire_home_page_on_post_destroy
article = posts(:article)
get_paths '/', '/posts/page/1', '/articles', '/articles/page/1'
assert_cache_expired('index.html', 'posts/', 'articles/', 'articles.html') do
get_paths '/', '/posts/page/1', '/articles', '/articles/page/1', '/posts.rss', '/articles.rss'
assert_cache_expired('index.html', 'posts/', 'articles/', 'articles.html', 'posts.rss', 'articles.rss') do
login_as :quentin
delete "/admin/articles/#{article.permalink}"
end
end

def test_should_expire_home_page_on_single_feed_refresh
feed = feeds(:blog)
get_paths '/', '/posts/page/1', '/articles', '/articles/page/1'
assert_cache_expired('index.html', 'posts/', 'articles/', 'articles.html') do
get_paths '/', '/posts/page/1', '/articles', '/articles/page/1', '/posts.rss', '/articles.rss'
assert_cache_expired('index.html', 'posts/', 'articles/', 'articles.html', 'posts.rss', 'articles.rss') do
login_as :quentin
put feed_path(feed, :refresh => true)
end
end

def test_should_expire_home_page_on_all_feeds_refresh
feed = feeds(:blog)
get_paths '/', '/posts/page/1', '/articles', '/articles/page/1', '/tweets', '/tweets/page/1'
assert_cache_expired('index.html', 'posts/', 'articles/', 'articles.html', 'tweets/', 'tweets.html') do
get_paths '/', '/posts/page/1', '/articles', '/articles/page/1', '/tweets', '/tweets/page/1', '/posts.rss', '/articles.rss'
assert_cache_expired('index.html', 'posts/', 'articles/', 'articles.html', 'tweets/', 'tweets.html', 'posts.rss', 'articles.rss') do
login_as :quentin
post refresh_feeds_path
end
Expand Down Expand Up @@ -168,7 +174,7 @@ def test_should_expire_show_page_on_comment_create
post "#{article.link}/comments", :comment => { :name => 'Pat', :email => 'pat@example.com', :body => "Totally." }
end
end

# TODO

def teardown
Expand All @@ -187,7 +193,7 @@ def login_as(name)
end

def wipe_cache!
%w(/index.html /posts.html /posts /articles.html /articles /snippets.html /snippets).each do |file|
%w(/index.html /posts.html /posts /articles.html /articles /snippets.html /snippets /posts.rss /articles.rss /snippets.rss).each do |file|
file = RAILS_ROOT + '/public' + file
FileUtils.rm_rf(file) if File.exists?(file)
end
Expand Down

0 comments on commit afe80b2

Please sign in to comment.