diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 19:12:56 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 19:12:56 +0200 |
| commit | ba789678f9e8ed189413afb1446ad210df34e488 (patch) | |
| tree | 23ac4ce3c3403438fa8e50985de2db3b11a924a8 /test/controllers | |
| parent | 4072efdc912ecb3b79621fb1838434f792e3a531 (diff) | |
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.
Diffstat (limited to 'test/controllers')
| -rw-r--r-- | test/controllers/revisions_controller_test.rb | 32 |
1 files changed, 32 insertions, 0 deletions
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 | |||
| 168 | assert_response :success | 168 | assert_response :success |
| 169 | assert_select "a[href=?]", node_path(@node) | 169 | assert_select "a[href=?]", node_path(@node) |
| 170 | end | 170 | end |
| 171 | |||
| 172 | test "diff defaults to a locale that actually changed, not the ambient default" do | ||
| 173 | login_as :quentin | ||
| 174 | node = Node.root.children.create!(:slug => "diff_default_locale_test") | ||
| 175 | node.draft.save! | ||
| 176 | node.publish_draft! | ||
| 177 | |||
| 178 | node.find_or_create_draft(@user) | ||
| 179 | Globalize.with_locale(:en) { node.draft.update!(:title => "Changed in English only") } | ||
| 180 | node.draft.save! | ||
| 181 | |||
| 182 | post(:diff, params: { :node_id => node.id, :start_revision => "head", :end_revision => "draft" }) | ||
| 183 | |||
| 184 | assert_response :success | ||
| 185 | assert_match(/Changed/, response.body) | ||
| 186 | end | ||
| 187 | |||
| 188 | test "diff respects an explicitly requested locale over the auto-detected one" do | ||
| 189 | login_as :quentin | ||
| 190 | node = Node.root.children.create!(:slug => "diff_explicit_locale_test") | ||
| 191 | node.draft.save! | ||
| 192 | node.publish_draft! | ||
| 193 | |||
| 194 | node.find_or_create_draft(@user) | ||
| 195 | Globalize.with_locale(:en) { node.draft.update!(:title => "English changed") } | ||
| 196 | node.draft.save! | ||
| 197 | |||
| 198 | post(:diff, params: { :node_id => node.id, :start_revision => "head", :end_revision => "draft", :locale => "de" }) | ||
| 199 | |||
| 200 | assert_response :success | ||
| 201 | assert_no_match(/English changed/, response.body) | ||
| 202 | end | ||
| 171 | end | 203 | end |
