summaryrefslogtreecommitdiff
path: root/test/models
diff options
context:
space:
mode:
Diffstat (limited to 'test/models')
-rw-r--r--test/models/asset_test.rb12
-rw-r--r--test/models/helpers/content_helper_test.rb46
-rw-r--r--test/models/node_test.rb35
-rw-r--r--test/models/page_test.rb8
-rw-r--r--test/models/related_asset_test.rb16
5 files changed, 87 insertions, 30 deletions
diff --git a/test/models/asset_test.rb b/test/models/asset_test.rb
index d246abe..ab1cc5d 100644
--- a/test/models/asset_test.rb
+++ b/test/models/asset_test.rb
@@ -41,4 +41,16 @@ class AssetTest < ActiveSupport::TestCase
41 test "license_key may be blank" do 41 test "license_key may be blank" do
42 assert Asset.new(:license_key => nil).valid? 42 assert Asset.new(:license_key => nil).valid?
43 end 43 end
44
45 test "pdf? is true only for application/pdf" do
46 assert Asset.new(:upload_content_type => "application/pdf").pdf?
47 assert_not Asset.new(:upload_content_type => "image/png").pdf?
48 end
49
50 test "show_credit? is false for a PDF even with every credit field present" do
51 asset = Asset.new(:name => "demo", :upload_content_type => "application/pdf",
52 :creator => "Jane Doe", :source_url => "https://example.org", :license_key => "cc_by_4")
53 assert asset.has_credit?
54 assert_not asset.show_credit?
55 end
44end 56end
diff --git a/test/models/helpers/content_helper_test.rb b/test/models/helpers/content_helper_test.rb
index d6c7b43..c69ef4e 100644
--- a/test/models/helpers/content_helper_test.rb
+++ b/test/models/helpers/content_helper_test.rb
@@ -79,4 +79,50 @@ class ContentHelperTest < ActionView::TestCase
79 79
80 I18n.with_locale(:en) { assert_match t(:open_gallery), headline_image } 80 I18n.with_locale(:en) { assert_match t(:open_gallery), headline_image }
81 end 81 end
82
83 test "headline_image renders a document card for a PDF headline, not a lightbox image" do
84 node = Node.root.children.create!(:slug => "headline_image_pdf_test")
85 asset = Asset.create!(:name => "Expert Opinion", :upload_content_type => "application/pdf")
86 node.draft.assets << asset
87 node.draft.related_assets.find_by(:asset_id => asset.id).update!(:headline => true)
88 @page = node.draft
89
90 result = headline_image
91
92 assert_match "headline_document_card", result
93 assert_match "Expert Opinion", result
94 assert_no_match "data-gallery", result
95 end
96
97 test "headline_image lists other attached PDFs below the headline" do
98 node = Node.root.children.create!(:slug => "headline_image_multi_pdf_test")
99 headline_pdf = Asset.create!(:name => "Main Filing", :upload_content_type => "application/pdf")
100 other_pdf = Asset.create!(:name => "Supplementary Exhibit", :upload_content_type => "application/pdf")
101 node.draft.assets << headline_pdf
102 node.draft.assets << other_pdf
103 node.draft.related_assets.find_by(:asset_id => headline_pdf.id).update!(:headline => true)
104 @page = node.draft
105
106 result = headline_image
107
108 assert_match "Main Filing", result
109 assert_match "Supplementary Exhibit", result
110 assert_match "headline_document_card", result
111 assert_match "related_documents_list", result
112 end
113
114 test "headline_image lists attached PDFs even with no headline chosen" do
115 node = Node.root.children.create!(:slug => "headline_image_pdf_no_headline_test")
116 pdf_a = Asset.create!(:name => "Document A", :upload_content_type => "application/pdf")
117 pdf_b = Asset.create!(:name => "Document B", :upload_content_type => "application/pdf")
118 node.draft.assets << pdf_a
119 node.draft.assets << pdf_b
120 @page = node.draft
121
122 result = headline_image
123
124 assert_no_match "headline_document_card", result
125 assert_match "Document A", result
126 assert_match "Document B", result
127 end
82end 128end
diff --git a/test/models/node_test.rb b/test/models/node_test.rb
index ab66f81..ba38340 100644
--- a/test/models/node_test.rb
+++ b/test/models/node_test.rb
@@ -268,7 +268,6 @@ class NodeTest < ActiveSupport::TestCase
268 assert_equal "quentin", node.head.user.login 268 assert_equal "quentin", node.head.user.login
269 end 269 end
270 270
271
272 test "update?" do 271 test "update?" do
273 Node.root.descendants.delete_all 272 Node.root.descendants.delete_all
274 updates = Node.root.children.create!( :slug => "updates" ) 273 updates = Node.root.children.create!( :slug => "updates" )
@@ -359,6 +358,16 @@ class NodeTest < ActiveSupport::TestCase
359 assert_equal @user1, node.reload.lock_owner 358 assert_equal @user1, node.reload.lock_owner
360 end 359 end
361 360
361 test "title reads from autosave when neither draft nor head exists yet" do
362 node = Node.root.children.create!(:slug => "title_autosave_only_test")
363 node.draft.destroy
364 node.update_column(:draft_id, nil)
365 node.lock_for_editing!(users(:quentin))
366 node.autosave!({ :title => "autosave-only title" }, users(:quentin))
367
368 assert_equal "autosave-only title", node.reload.title
369 end
370
362 test "revert! is a safe no-op on a fresh node with only a draft" do 371 test "revert! is a safe no-op on a fresh node with only a draft" do
363 node = create_node_with_draft 372 node = create_node_with_draft
364 node.lock_for_editing!(@user1) 373 node.lock_for_editing!(@user1)
@@ -537,30 +546,6 @@ class NodeTest < ActiveSupport::TestCase
537 assert result.index(mine) < result.index(someone_elses_newer) 546 assert result.index(mine) < result.index(someone_elses_newer)
538 end 547 end
539 548
540 test "recently_changed includes a node whose head was recently published" do
541 node = Node.root.children.create!(:slug => "recent_changed_published")
542 find_or_create_draft(node, @user1)
543 node.autosave!({:title => "v1"}, @user1)
544 node.save_draft!(@user1)
545 node.publish_draft!
546
547 assert_includes Node.recently_changed, node
548 end
549
550 test "recently_changed excludes a node only touched by locking or unlocking after an old publish" do
551 node = Node.root.children.create!(:slug => "recent_changed_lock_only")
552 find_or_create_draft(node, @user1)
553 node.autosave!({:title => "v1"}, @user1)
554 node.save_draft!(@user1)
555 node.publish_draft!
556 node.head.update_column(:updated_at, 20.days.ago)
557
558 node.lock_for_editing!(@user1)
559 node.unlock!
560
561 assert_not_includes Node.recently_changed, node
562 end
563
564 test "autosave! carries over the current related assets to the newly created autosave row" do 549 test "autosave! carries over the current related assets to the newly created autosave row" do
565 node = Node.root.children.create!(:slug => "autosave_asset_carryover_test") 550 node = Node.root.children.create!(:slug => "autosave_asset_carryover_test")
566 user = User.find_by_login("quentin") 551 user = User.find_by_login("quentin")
diff --git a/test/models/page_test.rb b/test/models/page_test.rb
index 1f924f9..98a00d2 100644
--- a/test/models/page_test.rb
+++ b/test/models/page_test.rb
@@ -309,11 +309,15 @@ class PageTest < ActiveSupport::TestCase
309 309
310 kept_asset = Asset.create!(:upload_file_name => "kept.png", :upload_content_type => "image/png", :upload_file_size => 1) 310 kept_asset = Asset.create!(:upload_file_name => "kept.png", :upload_content_type => "image/png", :upload_file_size => 1)
311 removed_asset = Asset.create!(:upload_file_name => "removed.pdf", :upload_content_type => "application/pdf", :upload_file_size => 1) 311 removed_asset = Asset.create!(:upload_file_name => "removed.pdf", :upload_content_type => "application/pdf", :upload_file_size => 1)
312 n.head.update_assets([kept_asset.id, removed_asset.id]) 312 n.head.related_assets.delete_all
313 n.head.related_assets.create!(:asset_id => kept_asset.id, :position => 1)
314 n.head.related_assets.create!(:asset_id => removed_asset.id, :position => 2)
313 315
314 d2 = find_or_create_draft(n, @user1) 316 d2 = find_or_create_draft(n, @user1)
315 added_asset = Asset.create!(:upload_file_name => "added.png", :upload_content_type => "image/png", :upload_file_size => 1) 317 added_asset = Asset.create!(:upload_file_name => "added.png", :upload_content_type => "image/png", :upload_file_size => 1)
316 d2.update_assets([kept_asset.id, added_asset.id]) 318 d2.related_assets.delete_all
319 d2.related_assets.create!(:asset_id => kept_asset.id, :position => 1)
320 d2.related_assets.create!(:asset_id => added_asset.id, :position => 2)
317 d2.save! 321 d2.save!
318 322
319 diff = d2.diff_against(n.head) 323 diff = d2.diff_against(n.head)
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