Permalink
Browse files

Added etag support for PostsController#show.

  • Loading branch information...
1 parent 5e0cb25 commit b4554abaf727f7ae8bf63b19c977a5d8f2549689 @nakajima committed Feb 8, 2009
Showing with 26 additions and 19 deletions.
  1. +2 −0 app/controllers/posts_controller.rb
  2. +24 −19 test/functional/posts_controller_test.rb
@@ -25,6 +25,8 @@ def index
def show
redirect_to root_path and return unless current_post.type.match(/Article|Snippet/)
+ fresh_when(:etag => current_post)
+
@comment = flash[:comment] || current_post.comments.build
respond_to do |format|
format.html { render :template => 'posts/show.html.erb' }
@@ -4,38 +4,43 @@ class PostsControllerTest < ActionController::TestCase
# Generated tests
- def test_should_get_index
+ test "should_get_index" do
get :index
assert_response :success
assert_not_nil assigns(:posts)
end
- def test_should_get_show
+ test "should_get_show" do
get :show, :id => posts(:one).permalink
assert_response :success
end
- def test_should_redirect_to_admin_index_if_logged_in
+ test "should provide etag" do
+ get :show, :id => posts(:one).permalink
+ assert_not_nil @response.etag
+ end
+
+ test "should_redirect_to_admin_index_if_logged_in" do
login_as :quentin
get :index
assert_redirected_to admin_posts_path
end
- def test_should_redirect_to_admin_index_if_logged_in_even_for_relative_urls
+ test "should_redirect_to_admin_index_if_logged_in_even_for_relative_urls" do
set_relative_url do
login_as :quentin
get :index
assert_redirected_to admin_posts_path
end
end
- def test_should_redirect_to_admin_show_if_logged_in
+ test "should_redirect_to_admin_show_if_logged_in" do
login_as :quentin
get :show, :id => posts(:one).permalink
assert_redirected_to admin_post_path(posts(:one))
end
- def test_should_redirect_to_admin_show_if_logged_in_even_for_relative_urls
+ test "should_redirect_to_admin_show_if_logged_in_even_for_relative_urls" do
set_relative_url do
login_as :quentin
get :show, :id => posts(:one).permalink
@@ -48,7 +53,7 @@ def test_should_redirect_to_admin_show_if_logged_in_even_for_relative_urls
# NOTE Since these are all now handled by dynamically created controllers,
# we'll need a different way of testing them.
#
- # def test_should_retrieve_links_only
+ # test "should_retrieve_links_only" do
# @request.stubs(:path).returns('/links')
# Link.expects(:paginate_index).returns(posts_stub)
# Post.expects(:paginate_index).never
@@ -57,7 +62,7 @@ def test_should_redirect_to_admin_show_if_logged_in_even_for_relative_urls
# assert_equal 'links', assigns(:post_type)
# end
#
- # def test_should_retrieve_articles_only
+ # test "should_retrieve_articles_only" do
# @request.stubs(:path).returns('/articles')
# Article.expects(:paginate_index).returns(posts_stub)
# Post.expects(:paginate_index).never
@@ -66,7 +71,7 @@ def test_should_redirect_to_admin_show_if_logged_in_even_for_relative_urls
# assert_equal 'articles', assigns(:post_type)
# end
#
- # def test_should_retrieve_snippets_only
+ # test "should_retrieve_snippets_only" do
# @request.stubs(:path).returns('/snippets')
# Snippet.expects(:paginate_index).returns(posts_stub)
# Post.expects(:paginate_index).never
@@ -75,7 +80,7 @@ def test_should_redirect_to_admin_show_if_logged_in_even_for_relative_urls
# assert_equal 'snippets', assigns(:post_type)
# end
#
- # def test_should_retrieve_tweets_only
+ # test "should_retrieve_tweets_only" do
# @request.stubs(:path).returns('/tweets')
# Tweet.expects(:paginate_index).returns(posts_stub)
# Post.expects(:paginate_index).never
@@ -84,7 +89,7 @@ def test_should_redirect_to_admin_show_if_logged_in_even_for_relative_urls
# assert_equal 'tweets', assigns(:post_type)
# end
#
- # def test_should_retrieve_quotes_only
+ # test "should_retrieve_quotes_only" do
# @request.stubs(:path).returns('/quotes')
# Quote.expects(:paginate_index).returns(posts_stub)
# Post.expects(:paginate_index).never
@@ -93,7 +98,7 @@ def test_should_redirect_to_admin_show_if_logged_in_even_for_relative_urls
# assert_equal 'quotes', assigns(:post_type)
# end
#
- # def test_should_retrieve_pictures_only
+ # test "should_retrieve_pictures_only" do
# @request.stubs(:path).returns('/pictures')
# Picture.expects(:paginate_index).returns(posts_stub)
# Post.expects(:paginate_index).never
@@ -102,36 +107,36 @@ def test_should_redirect_to_admin_show_if_logged_in_even_for_relative_urls
# assert_equal 'pictures', assigns(:post_type)
# end
- def test_should_show_post
+ test "should_show_post" do
get :show, :id => posts(:one).permalink
assert_response :success
end
- def test_should_redirect_to_index_from_show_unless_article
+ test "should_redirect_to_index_from_show_unless_article" do
get :show, :id => posts(:two).id
assert_redirected_to root_path
end
- def test_should_redirect_to_index_from_show_unless_article_even_for_relative_urls
+ test "should_redirect_to_index_from_show_unless_article_even_for_relative_urls" do
set_relative_url do
get :show, :id => posts(:two).id
assert_redirected_to root_path
end
end
- def test_should_redirect_to_root_when_post_not_found
+ test "should_redirect_to_root_when_post_not_found" do
get :show, :id => 999999
assert_redirected_to root_path
end
- def test_should_redirect_to_root_when_post_not_found_even_for_relative_urls
+ test "should_redirect_to_root_when_post_not_found_even_for_relative_urls" do
set_relative_url do
get :show, :id => 999999
assert_redirected_to root_path
end
end
- def test_feed_tag
+ test "feed_tag" do
get :index
assert(h = Hpricot.parse(@response.body))
links = h.search("link[@type='application/rss+xml']")
@@ -141,7 +146,7 @@ def test_feed_tag
end
end
- def test_feed_tag_with_relative_urls
+ test "feed_tag_with_relative_urls" do
set_relative_url do
get :index
assert(h = Hpricot.parse(@response.body))

0 comments on commit b4554ab

Please sign in to comment.