Skip to content

Commit 05c16ef

Browse files
nbudinclaude
andcommitted
Add tests for Page#compute_og_description and save callback
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e0ce191 commit 05c16ef

1 file changed

Lines changed: 33 additions & 3 deletions

File tree

test/models/page_test.rb

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,37 @@
3333
require "test_helper"
3434

3535
class PageTest < ActiveSupport::TestCase
36-
# test "the truth" do
37-
# assert true
38-
# end
36+
include ActiveJob::TestHelper
37+
38+
let(:convention) { create(:convention) }
39+
40+
describe "#compute_og_description" do
41+
it "strips HTML tags and truncates to 160 characters" do
42+
page = create(:page, parent: convention, content: "<p>#{"a" * 200}</p>")
43+
result = page.compute_og_description
44+
assert_equal 160, result.length
45+
assert_no_match(%r{</?p>}, result)
46+
end
47+
48+
it "returns the plain text content for short pages" do
49+
page = create(:page, parent: convention, content: "Hello world")
50+
assert_equal "Hello world", page.compute_og_description
51+
end
52+
53+
it "returns an empty string if rendering raises" do
54+
page = create(:page, parent: convention, content: "Hello world")
55+
CmsContentFinder.stub(:new, ->(*) { raise "boom" }) { assert_equal "", page.compute_og_description }
56+
end
57+
end
58+
59+
describe "after save" do
60+
it "enqueues CachePageOgDescriptionJob on create" do
61+
assert_enqueued_with(job: CachePageOgDescriptionJob) { create(:page, parent: convention) }
62+
end
63+
64+
it "enqueues CachePageOgDescriptionJob on update" do
65+
page = create(:page, parent: convention)
66+
assert_enqueued_with(job: CachePageOgDescriptionJob) { page.update!(name: "Updated") }
67+
end
68+
end
3969
end

0 commit comments

Comments
 (0)