From 0f2dfa79ecdeb17d4a2b8972393e9026d225fb24 Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Wed, 4 Nov 2009 12:25:40 -0300 Subject: [PATCH] Expiring article cache after a comment --- app/controllers/public/content_viewer_controller.rb | 1 + test/functional/content_viewer_controller_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 0 deletions(-) diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index ee5418c..bc1021f 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -97,6 +97,7 @@ class ContentViewerController < ApplicationController @comment.author = user if logged_in? @comment.article = @page if @comment.save + @page.touch @comment = nil # clear the comment form else @form_div = 'opened' diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 5af6cff..993b7a5 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -873,4 +873,14 @@ class ContentViewerControllerTest < Test::Unit::TestCase assert_tag :tag => 'a', :content => 'New article' end + should 'touch article after adding a comment' do + yesterday = Time.now.yesterday + Article.record_timestamps = false + page = profile.articles.create(:name => 'myarticle', :body => 'the body of the text', :created_at => yesterday, :updated_at => yesterday) + Article.record_timestamps = true + + login_as('ze') + post :view_page, :profile => profile.identifier, :page => [ 'myarticle' ], :comment => { :title => 'crap!', :body => 'I think that this article is crap' } + assert_not_equal yesterday, assigns(:page).updated_at + end end -- libgit2 0.21.2