summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-21 22:23:32 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-21 22:23:32 +0200
commita2e4a1a5d3e73504e78461e0e39a3d24815b76d4 (patch)
treec31409bc206f3a6c8741fa1c92abeb79061371ad /test
parentec8329069d36cc6aa444c8a48b6b34a3e8f5c9d2 (diff)
Make PDFs eligible for headline and allow searching assets by filename
Diffstat (limited to 'test')
-rw-r--r--test/controllers/related_assets_controller_test.rb25
-rw-r--r--test/models/related_asset_test.rb16
2 files changed, 38 insertions, 3 deletions
diff --git a/test/controllers/related_assets_controller_test.rb b/test/controllers/related_assets_controller_test.rb
index 2384adc..ced4b74 100644
--- a/test/controllers/related_assets_controller_test.rb
+++ b/test/controllers/related_assets_controller_test.rb
@@ -134,4 +134,29 @@ class RelatedAssetsControllerTest < ActionController::TestCase
134 assert_response :success 134 assert_response :success
135 assert_not related.reload.headline? 135 assert_not related.reload.headline?
136 end 136 end
137
138 test "search includes PDF assets as headline-eligible candidates" do
139 login_as :quentin
140 node = Node.root.children.create!(:slug => "related_assets_search_pdf_test")
141 asset = Asset.create!(:name => "expert-opinion-searchable", :upload_content_type => "application/pdf")
142
143 get :search, params: { :node_id => node.id, :search_term => "expert-opinion-searchable" }
144
145 assert_response :success
146 ids = JSON.parse(response.body).map { |r| r["id"] }
147 assert_includes ids, asset.id
148 end
149
150 test "search matches by filename as well as name" do
151 login_as :quentin
152 node = Node.root.children.create!(:slug => "related_assets_search_filename_test")
153 asset = Asset.create!(:name => "Untitled", :upload_content_type => "application/pdf",
154 :upload_file_name => "Stellungnahme_Patientendaten_Schutz.pdf")
155
156 get :search, params: { :node_id => node.id, :search_term => "Patientendaten" }
157
158 assert_response :success
159 ids = JSON.parse(response.body).map { |r| r["id"] }
160 assert_includes ids, asset.id
161 end
137end 162end
diff --git a/test/models/related_asset_test.rb b/test/models/related_asset_test.rb
index 710b4cc..bb86ddb 100644
--- a/test/models/related_asset_test.rb
+++ b/test/models/related_asset_test.rb
@@ -11,15 +11,25 @@ class RelatedAssetTest < ActiveSupport::TestCase
11 assert related.valid? 11 assert related.valid?
12 end 12 end
13 13
14 test "headline cannot be set on a non-image asset" do 14 test "headline can be set on a PDF asset" do
15 node = Node.root.children.create!(:slug => "related_asset_headline_pdf_test") 15 node = Node.root.children.create!(:slug => "related_asset_headline_pdf_test")
16 asset = Asset.create!(:name => "programme", :upload_content_type => "application/pdf") 16 asset = Asset.create!(:name => "expert opinion", :upload_content_type => "application/pdf")
17 node.draft.assets << asset
18 related = node.draft.related_assets.find_by(:asset_id => asset.id)
19
20 related.headline = true
21 assert related.valid?
22 end
23
24 test "headline cannot be set on a non-image, non-PDF asset" do
25 node = Node.root.children.create!(:slug => "related_asset_headline_text_test")
26 asset = Asset.create!(:name => "programme", :upload_content_type => "text/plain")
17 node.draft.assets << asset 27 node.draft.assets << asset
18 related = node.draft.related_assets.find_by(:asset_id => asset.id) 28 related = node.draft.related_assets.find_by(:asset_id => asset.id)
19 29
20 related.headline = true 30 related.headline = true
21 assert_not related.valid? 31 assert_not related.valid?
22 assert_includes related.errors[:headline], "can only be set on image assets" 32 assert_includes related.errors[:headline], "can only be set on image or PDF assets"
23 end 33 end
24 34
25 test "the headline validation does not raise when asset is missing" do 35 test "the headline validation does not raise when asset is missing" do