FIX: deleting category background images sometimes has no effect
This commit is contained in:
parent
4771b0a99f
commit
f5a2ed99b0
|
@ -108,10 +108,6 @@ class Category < ActiveRecord::Base
|
||||||
Category.reset_topic_ids_cache
|
Category.reset_topic_ids_cache
|
||||||
end
|
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)
|
def self.scoped_to_permissions(guardian, permission_types)
|
||||||
if guardian.try(:is_admin?)
|
if guardian.try(:is_admin?)
|
||||||
all
|
all
|
||||||
|
|
|
@ -257,7 +257,7 @@ class Stylesheet::Manager
|
||||||
def color_scheme_digest
|
def color_scheme_digest
|
||||||
|
|
||||||
cs = theme&.color_scheme
|
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
|
if cs || category_updated > 0
|
||||||
Digest::SHA1.hexdigest "#{RailsMultisite::ConnectionManagement.current_db}-#{cs&.id}-#{cs&.version}-#{Stylesheet::Manager.last_file_updated}-#{category_updated}"
|
Digest::SHA1.hexdigest "#{RailsMultisite::ConnectionManagement.current_db}-#{cs&.id}-#{cs&.version}-#{Stylesheet::Manager.last_file_updated}-#{category_updated}"
|
||||||
|
|
|
@ -64,4 +64,30 @@ describe Stylesheet::Manager do
|
||||||
# our theme better have a name with the theme_id as part of it
|
# our theme better have a name with the theme_id as part of it
|
||||||
expect(new_link).to include("/stylesheets/desktop_theme_#{theme.id}_")
|
expect(new_link).to include("/stylesheets/desktop_theme_#{theme.id}_")
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -19,14 +19,6 @@ describe Category do
|
||||||
expect(cats.errors[:name]).to be_present
|
expect(cats.errors[:name]).to be_present
|
||||||
end
|
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
|
describe "resolve_permissions" do
|
||||||
it "can determine read_restricted" do
|
it "can determine read_restricted" do
|
||||||
read_restricted, resolved = Category.resolve_permissions(everyone: :full)
|
read_restricted, resolved = Category.resolve_permissions(everyone: :full)
|
||||||
|
|
Loading…
Reference in New Issue