diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-06-24 16:17:16 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-06-24 16:17:16 +0200 |
| commit | 75670df5b8a5700c48ac8cb41f8d1732b5738402 (patch) | |
| tree | 0611ab89cd9fa6aa5c1c7cc44df28de4388c608e /app/models | |
| parent | 61dc69cc5d8089ed9f96bc65dc64de6e075f70cf (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')
| -rw-r--r-- | app/models/asset.rb | 4 | ||||
| -rw-r--r-- | app/models/node.rb | 2 | ||||
| -rw-r--r-- | app/models/page.rb | 18 |
3 files changed, 17 insertions, 7 deletions
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 | |||
| 2 | 2 | ||
| 3 | has_many :related_assets, :dependent => :destroy | 3 | has_many :related_assets, :dependent => :destroy |
| 4 | has_many :pages, :through => :related_assets | 4 | has_many :pages, :through => :related_assets |
| 5 | 5 | ||
| 6 | has_attached_file( | 6 | has_attached_file( |
| 7 | :upload, | 7 | :upload, |
| 8 | :path => ":rails_root/public/system/:attachment/:id/:style/:filename", | ||
| 9 | :url => "/system/:attachment/:id/:style/:filename", | ||
| 8 | :styles => { | 10 | :styles => { |
| 9 | :medium => "300x300", | 11 | :medium => "300x300", |
| 10 | :thumb => "100x100", | 12 | :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 | |||
| 146 | 146 | ||
| 147 | # returns an array with all parts of a unique_name rather than a string | 147 | # returns an array with all parts of a unique_name rather than a string |
| 148 | def unique_path | 148 | def unique_path |
| 149 | unique_name.split("/") rescue [unique_name] | 149 | unique_name.to_s |
| 150 | end | 150 | end |
| 151 | 151 | ||
| 152 | # returns array with pages up to root excluding root | 152 | # 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 | |||
| 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]}") |
