Commit 17997821e62e31c7a4c34156bed505273e2c2579

Authored by Victor Costa
1 parent 28d7d4cf
Exists in master

Differ cache_key for logged in and not logged users

Showing 2 changed files with 14 additions and 0 deletions   Show diff stats
lib/ext/article.rb
... ... @@ -16,6 +16,12 @@ class Article
16 16 comment_paragraph_plugin_activate && comment_paragraph_plugin_enabled?
17 17 end
18 18  
  19 + def cache_key_with_comment_paragraph(params = {}, user = nil, language = 'en')
  20 + cache_key_without_comment_paragraph(params, user, language) + (user.present? ? '-logged_in-': '-not_logged-')
  21 + end
  22 +
  23 + alias_method_chain :cache_key, :comment_paragraph
  24 +
19 25 protected
20 26  
21 27 def comment_paragraph_plugin_parse_html
... ...
test/unit/article_test.rb
... ... @@ -150,4 +150,12 @@ class ArticleTest < ActiveSupport::TestCase
150 150 assert !article.comment_paragraph_plugin_enabled?
151 151 end
152 152  
  153 + should 'append not_logged to cache key when user is not logged in' do
  154 + assert_match /-not_logged-/, article.cache_key
  155 + end
  156 +
  157 + should 'append logged_in to cache key when user is logged in' do
  158 + assert_match /-logged_in-/, article.cache_key({}, fast_create(Person))
  159 + end
  160 +
153 161 end
... ...