From ba789678f9e8ed189413afb1446ad210df34e488 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Mon, 13 Jul 2026 19:12:56 +0200 Subject: Make revision diffs locale-aware, defaulting to whichever locale changed diff_against compared title/abstract/body under whatever I18n.locale happened to be ambient, with no concept of 'diff this translation specifically' -- so a change confined to one locale was invisible to Diff Head vs. Draft regardless of which locale you were looking at when you clicked it, exactly the 'yields nothing' complaint from earlier this session. Page#diff_against gains a locale: keyword, additive only -- nil preserves the exact original ambient-locale behavior every existing caller and test already depends on; passing a locale switches to reading each side's actual PageTranslation row directly, same fallback-free reasoning as Page#translation_summary. Page#locale_diff_summary reports one entry per locale present on either side, so an added or removed translation counts as a change even where content matches everywhere it exists on both. RevisionsController#diff now resolves a real locale before diffing -- defaulting to whichever locale actually changed, falling back to the default locale only when nothing did -- and the view carries that locale through every existing control (view toggle, layer-pair buttons, the revision-select form) so it and the view/layer-pair axis stay independently selectable rather than resetting each other. --- test/controllers/revisions_controller_test.rb | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'test') diff --git a/test/controllers/revisions_controller_test.rb b/test/controllers/revisions_controller_test.rb index 76d4e8c..e5726f7 100644 --- a/test/controllers/revisions_controller_test.rb +++ b/test/controllers/revisions_controller_test.rb @@ -168,4 +168,36 @@ class RevisionsControllerTest < ActionController::TestCase assert_response :success assert_select "a[href=?]", node_path(@node) end + + test "diff defaults to a locale that actually changed, not the ambient default" do + login_as :quentin + node = Node.root.children.create!(:slug => "diff_default_locale_test") + node.draft.save! + node.publish_draft! + + node.find_or_create_draft(@user) + Globalize.with_locale(:en) { node.draft.update!(:title => "Changed in English only") } + node.draft.save! + + post(:diff, params: { :node_id => node.id, :start_revision => "head", :end_revision => "draft" }) + + assert_response :success + assert_match(/Changed/, response.body) + end + + test "diff respects an explicitly requested locale over the auto-detected one" do + login_as :quentin + node = Node.root.children.create!(:slug => "diff_explicit_locale_test") + node.draft.save! + node.publish_draft! + + node.find_or_create_draft(@user) + Globalize.with_locale(:en) { node.draft.update!(:title => "English changed") } + node.draft.save! + + post(:diff, params: { :node_id => node.id, :start_revision => "head", :end_revision => "draft", :locale => "de" }) + + assert_response :success + assert_no_match(/English changed/, response.body) + end end -- cgit v1.3