From f5a2ed99b0c714902da79f7374100cf997289685 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 4 Oct 2017 17:04:29 -0400 Subject: [PATCH] FIX: deleting category background images sometimes has no effect --- app/models/category.rb | 4 ---- lib/stylesheet/manager.rb | 2 +- spec/components/stylesheet/manager_spec.rb | 26 ++++++++++++++++++++++ spec/models/category_spec.rb | 8 ------- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/app/models/category.rb b/app/models/category.rb index 1b9032b8d49..72fe1b6e49f 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -108,10 +108,6 @@ class Category < ActiveRecord::Base Category.reset_topic_ids_cache end - def self.last_updated_at - order('updated_at desc').limit(1).pluck(:updated_at).first.to_i - end - def self.scoped_to_permissions(guardian, permission_types) if guardian.try(:is_admin?) all diff --git a/lib/stylesheet/manager.rb b/lib/stylesheet/manager.rb index 85cd6bd0833..92442b56060 100644 --- a/lib/stylesheet/manager.rb +++ b/lib/stylesheet/manager.rb @@ -257,7 +257,7 @@ class Stylesheet::Manager def color_scheme_digest cs = theme&.color_scheme - category_updated = Category.where("uploaded_background_id IS NOT NULL").last_updated_at + category_updated = Category.where("uploaded_background_id IS NOT NULL").pluck(:updated_at).map(&:to_i).sum if cs || category_updated > 0 Digest::SHA1.hexdigest "#{RailsMultisite::ConnectionManagement.current_db}-#{cs&.id}-#{cs&.version}-#{Stylesheet::Manager.last_file_updated}-#{category_updated}" diff --git a/spec/components/stylesheet/manager_spec.rb b/spec/components/stylesheet/manager_spec.rb index 98a28e4b9ee..07571887fa3 100644 --- a/spec/components/stylesheet/manager_spec.rb +++ b/spec/components/stylesheet/manager_spec.rb @@ -64,4 +64,30 @@ describe Stylesheet::Manager do # our theme better have a name with the theme_id as part of it expect(new_link).to include("/stylesheets/desktop_theme_#{theme.id}_") end + + describe 'color_scheme_digest' do + it "changes with category background image" do + theme = Theme.new( + name: 'parent', + user_id: -1 + ) + category1 = Fabricate(:category, uploaded_background_id: 123, updated_at: 1.week.ago) + category2 = Fabricate(:category, uploaded_background_id: 456, updated_at: 2.days.ago) + + manager = Stylesheet::Manager.new(:desktop_theme, theme.key) + + digest1 = manager.color_scheme_digest + + category2.update_attributes(uploaded_background_id: 789, updated_at: 1.day.ago) + + digest2 = manager.color_scheme_digest + expect(digest2).to_not eq(digest1) + + category1.update_attributes(uploaded_background_id: nil, updated_at: 5.minutes.ago) + + digest3 = manager.color_scheme_digest + expect(digest3).to_not eq(digest2) + expect(digest3).to_not eq(digest1) + end + end end diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb index e61de161b15..7c9fbc565bd 100644 --- a/spec/models/category_spec.rb +++ b/spec/models/category_spec.rb @@ -19,14 +19,6 @@ describe Category do expect(cats.errors[:name]).to be_present end - describe "last_updated_at" do - it "returns a number value of when the category was last updated" do - last = Category.last_updated_at - expect(last).to be_present - expect(last.to_i).to eq(last) - end - end - describe "resolve_permissions" do it "can determine read_restricted" do read_restricted, resolved = Category.resolve_permissions(everyone: :full)