summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-10 00:35:24 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-10 00:35:24 +0200
commita25d90335ad3738b6831288190132c2f7498465c (patch)
tree5aa7083d9f8c8701644fe60bc7d28542775694b8 /test
parentda0b79a7c1f3116e2b450ecbe50efdf31cf23414 (diff)
Retire vendored cacycle_diff.js for a diff-lcs-based diff view
Revisions#diff now computes an inline or side-by-side word diff server-side (Page#diff_against, lib/html_word_diff.rb) instead of shipping raw/escaped content to the browser for a 2008-era vendored JS differ to mangle. View mode is picked via a `view` param, settable either on the diff page itself or directly from the revisions#index sticky bar next to "Diff revisions". Also fixes a pre-existing bug in RevisionsController#diff's single- revision branch, which set params[:start]/params[:end] instead of params[:start_revision]/params[:end_revision].
Diffstat (limited to 'test')
-rw-r--r--test/controllers/revisions_controller_test.rb29
-rw-r--r--test/models/page_test.rb34
2 files changed, 63 insertions, 0 deletions
diff --git a/test/controllers/revisions_controller_test.rb b/test/controllers/revisions_controller_test.rb
index b4dcd8f..e2fc976 100644
--- a/test/controllers/revisions_controller_test.rb
+++ b/test/controllers/revisions_controller_test.rb
@@ -59,4 +59,33 @@ class RevisionsControllerTest < ActionController::TestCase
59 assert_equal @node.head, @node.pages.first 59 assert_equal @node.head, @node.pages.first
60 assert_equal "first", @node.head.reload.body 60 assert_equal "first", @node.head.reload.body
61 end 61 end
62
63 test "diffing two revisions renders real markup with only the changed words marked" do
64 login_as :quentin
65 post(
66 :diff, params: {
67 :node_id => @node.id,
68 :start_revision => @node.pages.first.revision,
69 :end_revision => @node.pages.last.revision
70 }
71 )
72 assert_response :success
73 assert_select "del", "first"
74 assert_select "ins", "second"
75 assert_no_match /&lt;/, response.body
76 end
77
78 test "diffing two revisions in side by side view renders two columns" do
79 login_as :quentin
80 post(
81 :diff, params: {
82 :node_id => @node.id,
83 :start_revision => @node.pages.first.revision,
84 :end_revision => @node.pages.last.revision,
85 :view => "side_by_side"
86 }
87 )
88 assert_response :success
89 assert_select ".diff_column", 2
90 end
62end 91end
diff --git a/test/models/page_test.rb b/test/models/page_test.rb
index ad2742f..ac5691a 100644
--- a/test/models/page_test.rb
+++ b/test/models/page_test.rb
@@ -176,4 +176,38 @@ class PageTest < ActiveSupport::TestCase
176 assert_not_equal first_page.id, first_page.node.head_id 176 assert_not_equal first_page.id, first_page.node.head_id
177 assert first_page.published_at.present? 177 assert first_page.published_at.present?
178 end 178 end
179
180 def test_diff_against_inline_keeps_tags_and_marks_only_the_changed_word
181 n = Node.root.children.create! :slug => "diff_against_test"
182 d = n.find_or_create_draft @user1
183 d.title = "Old heading"
184 d.save!
185 n.publish_draft!
186
187 d2 = n.find_or_create_draft @user1
188 d2.title = "New heading"
189 d2.save!
190
191 diff = d2.diff_against(n.head)
192
193 assert_match "<del>Old</del>", diff[:title]
194 assert_match "<ins>New</ins>", diff[:title]
195 end
196
197 def test_diff_against_side_by_side_returns_two_annotated_strings
198 n = Node.root.children.create! :slug => "diff_against_sbs_test"
199 d = n.find_or_create_draft @user1
200 d.title = "Old heading"
201 d.save!
202 n.publish_draft!
203
204 d2 = n.find_or_create_draft @user1
205 d2.title = "New heading"
206 d2.save!
207
208 old_html, new_html = d2.diff_against(n.head, view: :side_by_side)[:title]
209
210 assert_match "<del>Old</del>", old_html
211 assert_match "<ins>New</ins>", new_html
212 end
179end 213end