From 17997821e62e31c7a4c34156bed505273e2c2579 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Thu, 2 Apr 2015 16:52:01 -0300 Subject: [PATCH] Differ cache_key for logged in and not logged users --- lib/ext/article.rb | 6 ++++++ test/unit/article_test.rb | 8 ++++++++ 2 files changed, 14 insertions(+), 0 deletions(-) diff --git a/lib/ext/article.rb b/lib/ext/article.rb index e4529a4..95e5f11 100644 --- a/lib/ext/article.rb +++ b/lib/ext/article.rb @@ -16,6 +16,12 @@ class Article comment_paragraph_plugin_activate && comment_paragraph_plugin_enabled? end + def cache_key_with_comment_paragraph(params = {}, user = nil, language = 'en') + cache_key_without_comment_paragraph(params, user, language) + (user.present? ? '-logged_in-': '-not_logged-') + end + + alias_method_chain :cache_key, :comment_paragraph + protected def comment_paragraph_plugin_parse_html diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 7f6bbd3..2c0a5b0 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -150,4 +150,12 @@ class ArticleTest < ActiveSupport::TestCase assert !article.comment_paragraph_plugin_enabled? end + should 'append not_logged to cache key when user is not logged in' do + assert_match /-not_logged-/, article.cache_key + end + + should 'append logged_in to cache key when user is logged in' do + assert_match /-logged_in-/, article.cache_key({}, fast_create(Person)) + end + end -- libgit2 0.21.2