Commit bd70a538c161042ffe70ec22e1a97ae5ffa2e3dd

Authored by Antonio Terceiro
2 parents 1e537056 67589517

Merge branch 'fix_image_cache_key' into 'master'

Fix cache_key expiration on image uploaded in articles

Signed-off-by: Daniela Soares Feitosa <danielafeitosa@colivre.coop.br>

See merge request !717
lib/create_thumbnails_job.rb
... ... @@ -3,5 +3,9 @@ class CreateThumbnailsJob &lt; 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 &lt; 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
... ...