From 75670df5b8a5700c48ac8cb41f8d1732b5738402 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Wed, 24 Jun 2026 16:17:16 +0200 Subject: Fix tagged content aggregator, assets path, and add regression tests - Replace tagged_with calls in Page.aggregate, TagsController, RssController with direct SQL joins (acts-as-taggable-on 3.5 broken on Rails 3.2) - Fix Paperclip :path/:url to use plain :id format matching existing uploads - Add proper regression tests for aggregator, tags, and rss controllers - Fix assert_select assertions to target div.body div.article_partial --- app/models/asset.rb | 4 +++- app/models/node.rb | 2 +- app/models/page.rb | 18 +++++++++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) (limited to 'app/models') diff --git a/app/models/asset.rb b/app/models/asset.rb index d27c525..3ad5857 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -2,9 +2,11 @@ class Asset < ActiveRecord::Base has_many :related_assets, :dependent => :destroy has_many :pages, :through => :related_assets - + has_attached_file( :upload, + :path => ":rails_root/public/system/:attachment/:id/:style/:filename", + :url => "/system/:attachment/:id/:style/:filename", :styles => { :medium => "300x300", :thumb => "100x100", diff --git a/app/models/node.rb b/app/models/node.rb index 1b80565..3cab7ed 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -146,7 +146,7 @@ class Node < ActiveRecord::Base # returns an array with all parts of a unique_name rather than a string def unique_path - unique_name.split("/") rescue [unique_name] + unique_name.to_s end # returns array with pages up to root excluding root diff --git a/app/models/page.rb b/app/models/page.rb index 05abd43..5c93a93 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -39,8 +39,8 @@ class Page < ActiveRecord::Base # partially or entirely overwritten by the options hash. Afterwards the merged # parameters are used to query the DB for Pages matching these parameters. # The aggregation only takes published pages into account. - def self.aggregate options, page=1 + def self.aggregate options, page=1 defaults = { :tags => "", :limit => 25, @@ -52,10 +52,18 @@ class Page < ActiveRecord::Base scope = Page.heads unless options[:tags].blank? - scope = scope.tagged_with( - options[:tags].gsub(/\s/, ",").split(",").map(&:strip), - :match_all => true - ) + tag_names = options[:tags].gsub(/\s/, ",").split(",").map(&:strip).map(&:downcase).uniq.reject(&:blank?) + + unless tag_names.empty? + scope = scope + .joins("JOIN taggings ON taggings.taggable_id = pages.id + AND taggings.taggable_type = 'Page' + AND taggings.context = 'tags'") + .joins("JOIN tags ON tags.id = taggings.tag_id") + .where("LOWER(tags.name) IN (?)", tag_names) + .group("pages.id") + .having("COUNT(DISTINCT tags.id) = ?", tag_names.length) + end end scope.order("#{options[:order_by]} #{options[:order_direction]}") -- cgit v1.3