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/controllers/rss_controller.rb | 11 ++++++++--- app/controllers/tags_controller.rb | 18 ++++++++++++------ app/helpers/link_helper.rb | 7 ++++--- app/models/asset.rb | 4 +++- app/models/node.rb | 2 +- app/models/page.rb | 18 +++++++++++++----- app/views/pages/index.html.erb | 2 +- 7 files changed, 42 insertions(+), 20 deletions(-) (limited to 'app') diff --git a/app/controllers/rss_controller.rb b/app/controllers/rss_controller.rb index 70a642c..be9cd2c 100644 --- a/app/controllers/rss_controller.rb +++ b/app/controllers/rss_controller.rb @@ -7,10 +7,15 @@ class RssController < ApplicationController expires_in 31.minutes, :public => true I18n.locale = :de - - @items = Page.heads.tagged_with("update") + + @items = Page.heads + .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) = ?", "update") .order("published_at DESC").limit(20) - + respond_to do |format| format.xml {} format.rdf {} diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index f09d560..e4ceec9 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -12,17 +12,23 @@ class TagsController < ApplicationController tag_name = params[:id] if tag_name.match(/^[a-zA-Z0-9_\w\s\-\.\']+$/) - @tag = Tag.find_by_name(tag_name) + @tag = ActsAsTaggableOn::Tag.find_by_name(tag_name) @tag = @tag ? @tag.name : tag_name @page = Page.new params[:page] = (params[:page].is_a?(Integer) ? params[:page] : 1) - @pages = Page.heads.tagged_with(@tag).paginate( - :order => 'published_at DESC', - :page => params[:page], - :per_page => 23 - ) + @pages = Page.heads + .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) = ?", @tag.downcase) + .order('published_at DESC') + .paginate( + :page => params[:page], + :per_page => 23 + ) respond_to do |format| format.html {} diff --git a/app/helpers/link_helper.rb b/app/helpers/link_helper.rb index 1b20e6d..29c58f0 100644 --- a/app/helpers/link_helper.rb +++ b/app/helpers/link_helper.rb @@ -15,7 +15,8 @@ module LinkHelper def link_to_path title, path, html_options = {} if params[:page_path] - active = (params[:page_path].join("/") == path.sub(/^\//, "")) + page_path = params[:page_path].is_a?(Array) ? params[:page_path].join("/") : params[:page_path] + active = (page_path == path.sub(/^\//, "")) end active_class = active ? {:class => 'active'} : {:class => 'inactive'} @@ -29,7 +30,7 @@ module LinkHelper :controller => :content, :action => :render_page, :locale => params[:locale], - :page_path => (path.sub(/^\//, "").split("/") rescue "") + :page_path => (path.sub(/^\//, "") rescue "") }, html_options ) @@ -51,4 +52,4 @@ module LinkHelper ) end -end \ No newline at end of file +end 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]}") diff --git a/app/views/pages/index.html.erb b/app/views/pages/index.html.erb index 16539da..06cb16c 100644 --- a/app/views/pages/index.html.erb +++ b/app/views/pages/index.html.erb @@ -10,7 +10,7 @@ <%=h page.node_id %> <%=h page.title %> - <%= link_to 'Show', link_to_path(page.node.unique_path) %> + <%= link_to 'Show', content_path(:page_path => page.node.unique_path) %> <%= link_to 'Edit', edit_page_path(page) %> <%= link_to 'Destroy', page, :confirm => 'Are you sure?', :method => :delete %> -- cgit v1.3