Commit 915ab720164a269dc63d635038c515b93fd8da9f
1 parent
3a7be165
Exists in
stable-spb-1.4
and in
8 other branches
Fix cache_key expiration on image uploaded in articles
Signed-off-by: Daniela Soares Feitosa <danielafeitosa@colivre.coop.br> Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com> (cherry picked from commit 675895176abd1c50fe5c110de6dc6a5658899618)
Showing
2 changed files
with
16 additions
and
0 deletions
Show diff stats
lib/create_thumbnails_job.rb
... | ... | @@ -3,5 +3,9 @@ class CreateThumbnailsJob < Struct.new(:class_name, :file_id) |
3 | 3 | return unless class_name.constantize.exists?(file_id) |
4 | 4 | file = class_name.constantize.find(file_id) |
5 | 5 | file.create_thumbnails |
6 | + article = Article.where(:image_id => file_id).first | |
7 | + if article | |
8 | + article.touch | |
9 | + end | |
6 | 10 | end |
7 | 11 | end | ... | ... |
test/unit/create_thumbnails_job_test.rb
... | ... | @@ -34,4 +34,16 @@ class CreateThumbnailsJobTest < ActiveSupport::TestCase |
34 | 34 | end |
35 | 35 | end |
36 | 36 | |
37 | + should 'expire cache of articles that use an image that just got a thumbnail' do | |
38 | + person = create_user('test_user').person | |
39 | + file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => person) | |
40 | + article = create(Article, :name => 'test', :image_builder => { | |
41 | + :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') | |
42 | + }, :profile_id => person.id) | |
43 | + old_cache_key = article.cache_key | |
44 | + job = CreateThumbnailsJob.new(file.class.name, file.id) | |
45 | + job.perform | |
46 | + process_delayed_job_queue | |
47 | + assert_not_equal old_cache_key, Article.find(article.id).reload.cache_key | |
48 | + end | |
37 | 49 | end | ... | ... |