From aa14587b052a0aa7884aaf27183981975168ab14 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Mon, 13 Jul 2026 17:09:31 +0200 Subject: Wire real autosave into translation editing The shared TinyMCE setup initializes cccms.setup_autosave() on any page with a textarea.with_editor, unconditionally starting a 7-second interval that submits to the form's data-autosave-url -- which the translation edit form never set, so the interval PUT the current page URL itself and 404'd on a nonexistent route. Fixed by actually giving it something to talk to, rather than suppressing it: a real autosave endpoint, and update now goes through Node#autosave!/#save_draft! -- the same pipeline the primary editor uses, fixed earlier this session for exactly this kind of cross-locale carryover. This was the autosave-buffer parity already flagged as due after the proof of concept; the shared JS just forced the timing. --- test/controllers/page_translations_controller_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/controllers') diff --git a/test/controllers/page_translations_controller_test.rb b/test/controllers/page_translations_controller_test.rb index d84ac45..8c899fd 100644 --- a/test/controllers/page_translations_controller_test.rb +++ b/test/controllers/page_translations_controller_test.rb @@ -18,6 +18,7 @@ class PageTranslationsControllerTest < ActionController::TestCase node = Node.root.children.create!(:slug => "translations_create_test") Globalize.with_locale(:de) { node.draft.update!(:title => "Deutscher Titel") } node.publish_draft! + node.lock_for_editing!(users(:quentin)) patch :update, params: { :node_id => node.id, :translation_locale => "en", :page => { :title => "English Title" } } @@ -39,6 +40,7 @@ class PageTranslationsControllerTest < ActionController::TestCase test "update with Save + Unlock + Exit unlocks the node and redirects to nodes#show" do login_as :quentin node = Node.root.children.create!(:slug => "translations_exit_test") + node.lock_for_editing!(users(:quentin)) patch :update, params: { :node_id => node.id, :translation_locale => "en", :page => { :title => "x" }, :commit => "Save + Unlock + Exit" } @@ -50,6 +52,7 @@ class PageTranslationsControllerTest < ActionController::TestCase login_as :quentin node = Node.root.children.create!(:slug => "translations_update_test") Globalize.with_locale(:en) { node.draft.update!(:title => "Original") } + node.lock_for_editing!(users(:quentin)) patch :update, params: { :node_id => node.id, :translation_locale => "en", :page => { :title => "Revised" } } @@ -75,4 +78,20 @@ class PageTranslationsControllerTest < ActionController::TestCase assert_match(/No EN translation exists/, flash[:error]) end + + test "autosave writes the translation without creating a new revision or touching the draft" do + login_as :quentin + node = Node.root.children.create!(:slug => "translations_autosave_test") + node.publish_draft! + node.lock_for_editing!(users(:quentin)) + page_count_before = node.pages.count + + put :autosave, params: { :node_id => node.id, :translation_locale => "en", :page => { :title => "in progress" } } + + assert_response :success + node.reload + assert_not_nil node.autosave + assert_equal page_count_before, node.pages.count + assert_equal "in progress", Globalize.with_locale(:en) { node.autosave.title } + end end -- cgit v1.3