summaryrefslogtreecommitdiff
path: root/app/models/page.rb
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-06-24 16:17:16 +0200
committererdgeist <erdgeist@erdgeist.org>2026-06-24 16:17:16 +0200
commit75670df5b8a5700c48ac8cb41f8d1732b5738402 (patch)
tree0611ab89cd9fa6aa5c1c7cc44df28de4388c608e /app/models/page.rb
parent61dc69cc5d8089ed9f96bc65dc64de6e075f70cf (diff)
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
Diffstat (limited to 'app/models/page.rb')
-rw-r--r--app/models/page.rb18
1 files changed, 13 insertions, 5 deletions
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
39 # partially or entirely overwritten by the options hash. Afterwards the merged 39 # partially or entirely overwritten by the options hash. Afterwards the merged
40 # parameters are used to query the DB for Pages matching these parameters. 40 # parameters are used to query the DB for Pages matching these parameters.
41 # The aggregation only takes published pages into account. 41 # The aggregation only takes published pages into account.
42 def self.aggregate options, page=1
43 42
43 def self.aggregate options, page=1
44 defaults = { 44 defaults = {
45 :tags => "", 45 :tags => "",
46 :limit => 25, 46 :limit => 25,
@@ -52,10 +52,18 @@ class Page < ActiveRecord::Base
52 52
53 scope = Page.heads 53 scope = Page.heads
54 unless options[:tags].blank? 54 unless options[:tags].blank?
55 scope = scope.tagged_with( 55 tag_names = options[:tags].gsub(/\s/, ",").split(",").map(&:strip).map(&:downcase).uniq.reject(&:blank?)
56 options[:tags].gsub(/\s/, ",").split(",").map(&:strip), 56
57 :match_all => true 57 unless tag_names.empty?
58 ) 58 scope = scope
59 .joins("JOIN taggings ON taggings.taggable_id = pages.id
60 AND taggings.taggable_type = 'Page'
61 AND taggings.context = 'tags'")
62 .joins("JOIN tags ON tags.id = taggings.tag_id")
63 .where("LOWER(tags.name) IN (?)", tag_names)
64 .group("pages.id")
65 .having("COUNT(DISTINCT tags.id) = ?", tag_names.length)
66 end
59 end 67 end
60 68
61 scope.order("#{options[:order_by]} #{options[:order_direction]}") 69 scope.order("#{options[:order_by]} #{options[:order_direction]}")