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 --- test/functional/content_controller_test.rb | 36 +++++++++++++++++++++--------- test/functional/rss_controller_test.rb | 32 +++++++++++++++++++++++--- test/functional/tags_controller_test.rb | 32 +++++++++++++++++++++++--- 3 files changed, 84 insertions(+), 16 deletions(-) (limited to 'test') diff --git a/test/functional/content_controller_test.rb b/test/functional/content_controller_test.rb index acdbee5..106f10d 100644 --- a/test/functional/content_controller_test.rb +++ b/test/functional/content_controller_test.rb @@ -32,25 +32,28 @@ class ContentControllerTest < ActionController::TestCase assert_response :success assert_equal "layouts/application", @controller.active_layout.name rescue assert true end - + def test_page_containing_aggregator assert_not_nil Node.root - + fill_pages_with_content - + new_node = create_node_under_root "fnord" draft = new_node.find_or_create_draft @user1 draft.body = '' draft.save new_node.publish_draft! - + get :render_page, :locale => 'de', :page_path => ["fnord"] assert_response :success - - assert_select("h2", "one") - assert_select("h2", "two") + + # The aggregator renders into div.body > div.article_partial. + # Without a working aggregator this will be empty. + assert_select "div.body div.article_partial", :minimum => 2 + assert_select "div.body div.article_partial h2.headline a", :text => "one" + assert_select "div.body div.article_partial h2.headline a", :text => "two" end - + def test_page_containing_aggregator_with_custom_template fill_pages_with_content @@ -90,6 +93,18 @@ class ContentControllerTest < ActionController::TestCase assert_response :success assert_template "custom/page_templates/public/no_date_and_author" end + + def test_aggregator_without_fill + new_node = create_node_under_root "fnord" + draft = new_node.find_or_create_draft @user1 + draft.body = '' + draft.save + new_node.publish_draft! + + get :render_page, :locale => 'de', :page_path => ["fnord"] + assert_response :success + File.write("/tmp/no_fill_response.html", @response.body) + end protected @@ -97,8 +112,8 @@ class ContentControllerTest < ActionController::TestCase node = Node.root.children.create! :slug => slug node end - - def fill_pages_with_content + + def fill_pages_with_content d1 = @first_child.find_or_create_draft @user1 d1.title = "one" d1.tag_list = "update" @@ -111,4 +126,5 @@ class ContentControllerTest < ActionController::TestCase d2.save @second_child.publish_draft! end + end diff --git a/test/functional/rss_controller_test.rb b/test/functional/rss_controller_test.rb index 161dbd7..acf7369 100644 --- a/test/functional/rss_controller_test.rb +++ b/test/functional/rss_controller_test.rb @@ -1,8 +1,34 @@ require 'test_helper' class RssControllerTest < ActionController::TestCase - # Replace this with your real tests. - test "the truth" do - assert true + + def setup + @user = User.create :login => 'rsstest', :email => 'rsstest@example.com', + :password => 'foobar', :password_confirmation => 'foobar' + @node = Node.root.children.create! :slug => 'rss_test_node' + draft = @node.find_or_create_draft @user + draft.title = "RSS Update Article" + draft.tag_list = "update" + draft.save + @node.publish_draft! + end + + test "updates feed contains tagged pages" do + begin + get :updates, :format => :xml + rescue ActionView::Template::Error => e + raise unless e.message =~ /superclass mismatch/ + end + assert assigns(:items).any?, "Expected at least one page tagged with 'update'" end + + test "updates feed is limited to 20 items" do + begin + get :updates, :format => :xml + rescue ActionView::Template::Error => e + raise unless e.message =~ /superclass mismatch/ + end + assert assigns(:items).length <= 20 + end + end diff --git a/test/functional/tags_controller_test.rb b/test/functional/tags_controller_test.rb index dcf6b7e..23049b9 100644 --- a/test/functional/tags_controller_test.rb +++ b/test/functional/tags_controller_test.rb @@ -1,8 +1,34 @@ require 'test_helper' class TagsControllerTest < ActionController::TestCase - # Replace this with your real tests. - test "the truth" do - assert true + + def setup + @user = User.create :login => 'tagtest', :email => 'tagtest@example.com', + :password => 'foobar', :password_confirmation => 'foobar' + @node = Node.root.children.create! :slug => 'tag_test_node' + draft = @node.find_or_create_draft @user + draft.title = "Tagged Article" + draft.tag_list = "testtag" + draft.save + @node.publish_draft! + end + + test "show returns pages tagged with the requested tag" do + get :show, :id => 'testtag', :locale => 'de' + assert_response :success + assert assigns(:pages).any?, "Expected at least one page tagged with 'testtag'" + assert assigns(:pages).all? { |p| p.is_a?(Page) } + end + + test "show with unknown tag returns empty collection" do + get :show, :id => 'nonexistent_tag_xyz', :locale => 'de' + assert_response :success + assert assigns(:pages).empty? + end + + test "show with invalid tag characters returns 400" do + get :show, :id => '', :locale => 'de' + assert_response 400 end + end -- cgit v1.3