summaryrefslogtreecommitdiff
path: root/app
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
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')
-rw-r--r--app/controllers/rss_controller.rb11
-rw-r--r--app/controllers/tags_controller.rb18
-rw-r--r--app/helpers/link_helper.rb7
-rw-r--r--app/models/asset.rb4
-rw-r--r--app/models/node.rb2
-rw-r--r--app/models/page.rb18
-rw-r--r--app/views/pages/index.html.erb2
7 files changed, 42 insertions, 20 deletions
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
7 expires_in 31.minutes, :public => true 7 expires_in 31.minutes, :public => true
8 8
9 I18n.locale = :de 9 I18n.locale = :de
10 10
11 @items = Page.heads.tagged_with("update") 11 @items = Page.heads
12 .joins("JOIN taggings ON taggings.taggable_id = pages.id
13 AND taggings.taggable_type = 'Page'
14 AND taggings.context = 'tags'")
15 .joins("JOIN tags ON tags.id = taggings.tag_id")
16 .where("LOWER(tags.name) = ?", "update")
12 .order("published_at DESC").limit(20) 17 .order("published_at DESC").limit(20)
13 18
14 respond_to do |format| 19 respond_to do |format|
15 format.xml {} 20 format.xml {}
16 format.rdf {} 21 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
12 tag_name = params[:id] 12 tag_name = params[:id]
13 13
14 if tag_name.match(/^[a-zA-Z0-9_\w\s\-\.\']+$/) 14 if tag_name.match(/^[a-zA-Z0-9_\w\s\-\.\']+$/)
15 @tag = Tag.find_by_name(tag_name) 15 @tag = ActsAsTaggableOn::Tag.find_by_name(tag_name)
16 @tag = @tag ? @tag.name : tag_name 16 @tag = @tag ? @tag.name : tag_name
17 @page = Page.new 17 @page = Page.new
18 18
19 params[:page] = (params[:page].is_a?(Integer) ? params[:page] : 1) 19 params[:page] = (params[:page].is_a?(Integer) ? params[:page] : 1)
20 20
21 @pages = Page.heads.tagged_with(@tag).paginate( 21 @pages = Page.heads
22 :order => 'published_at DESC', 22 .joins("JOIN taggings ON taggings.taggable_id = pages.id
23 :page => params[:page], 23 AND taggings.taggable_type = 'Page'
24 :per_page => 23 24 AND taggings.context = 'tags'")
25 ) 25 .joins("JOIN tags ON tags.id = taggings.tag_id")
26 .where("LOWER(tags.name) = ?", @tag.downcase)
27 .order('published_at DESC')
28 .paginate(
29 :page => params[:page],
30 :per_page => 23
31 )
26 32
27 respond_to do |format| 33 respond_to do |format|
28 format.html {} 34 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
15 15
16 def link_to_path title, path, html_options = {} 16 def link_to_path title, path, html_options = {}
17 if params[:page_path] 17 if params[:page_path]
18 active = (params[:page_path].join("/") == path.sub(/^\//, "")) 18 page_path = params[:page_path].is_a?(Array) ? params[:page_path].join("/") : params[:page_path]
19 active = (page_path == path.sub(/^\//, ""))
19 end 20 end
20 21
21 active_class = active ? {:class => 'active'} : {:class => 'inactive'} 22 active_class = active ? {:class => 'active'} : {:class => 'inactive'}
@@ -29,7 +30,7 @@ module LinkHelper
29 :controller => :content, 30 :controller => :content,
30 :action => :render_page, 31 :action => :render_page,
31 :locale => params[:locale], 32 :locale => params[:locale],
32 :page_path => (path.sub(/^\//, "").split("/") rescue "") 33 :page_path => (path.sub(/^\//, "") rescue "")
33 }, 34 },
34 html_options 35 html_options
35 ) 36 )
@@ -51,4 +52,4 @@ module LinkHelper
51 ) 52 )
52 end 53 end
53 54
54end \ No newline at end of file 55end
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]}")
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 @@
10 <tr> 10 <tr>
11 <td><%=h page.node_id %></td> 11 <td><%=h page.node_id %></td>
12 <td><%=h page.title %></td> 12 <td><%=h page.title %></td>
13 <td><%= link_to 'Show', link_to_path(page.node.unique_path) %></td> 13 <td><%= link_to 'Show', content_path(:page_path => page.node.unique_path) %></td>
14 <td><%= link_to 'Edit', edit_page_path(page) %></td> 14 <td><%= link_to 'Edit', edit_page_path(page) %></td>
15 <td><%= link_to 'Destroy', page, :confirm => 'Are you sure?', :method => :delete %></td> 15 <td><%= link_to 'Destroy', page, :confirm => 'Are you sure?', :method => :delete %></td>
16 </tr> 16 </tr>