diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 17:09:31 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 17:09:31 +0200 |
| commit | aa14587b052a0aa7884aaf27183981975168ab14 (patch) | |
| tree | 2b043061a06474929bbfb9fe79a7985267ccef17 /test/controllers | |
| parent | 0b6ae26f3b4c3c8278e569fa6644a544e996c25d (diff) | |
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.
Diffstat (limited to 'test/controllers')
| -rw-r--r-- | test/controllers/page_translations_controller_test.rb | 19 |
1 files changed, 19 insertions, 0 deletions
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 | |||
| 18 | node = Node.root.children.create!(:slug => "translations_create_test") | 18 | node = Node.root.children.create!(:slug => "translations_create_test") |
| 19 | Globalize.with_locale(:de) { node.draft.update!(:title => "Deutscher Titel") } | 19 | Globalize.with_locale(:de) { node.draft.update!(:title => "Deutscher Titel") } |
| 20 | node.publish_draft! | 20 | node.publish_draft! |
| 21 | node.lock_for_editing!(users(:quentin)) | ||
| 21 | 22 | ||
| 22 | patch :update, params: { :node_id => node.id, :translation_locale => "en", :page => { :title => "English Title" } } | 23 | patch :update, params: { :node_id => node.id, :translation_locale => "en", :page => { :title => "English Title" } } |
| 23 | 24 | ||
| @@ -39,6 +40,7 @@ class PageTranslationsControllerTest < ActionController::TestCase | |||
| 39 | test "update with Save + Unlock + Exit unlocks the node and redirects to nodes#show" do | 40 | test "update with Save + Unlock + Exit unlocks the node and redirects to nodes#show" do |
| 40 | login_as :quentin | 41 | login_as :quentin |
| 41 | node = Node.root.children.create!(:slug => "translations_exit_test") | 42 | node = Node.root.children.create!(:slug => "translations_exit_test") |
| 43 | node.lock_for_editing!(users(:quentin)) | ||
| 42 | 44 | ||
| 43 | patch :update, params: { :node_id => node.id, :translation_locale => "en", :page => { :title => "x" }, :commit => "Save + Unlock + Exit" } | 45 | patch :update, params: { :node_id => node.id, :translation_locale => "en", :page => { :title => "x" }, :commit => "Save + Unlock + Exit" } |
| 44 | 46 | ||
| @@ -50,6 +52,7 @@ class PageTranslationsControllerTest < ActionController::TestCase | |||
| 50 | login_as :quentin | 52 | login_as :quentin |
| 51 | node = Node.root.children.create!(:slug => "translations_update_test") | 53 | node = Node.root.children.create!(:slug => "translations_update_test") |
| 52 | Globalize.with_locale(:en) { node.draft.update!(:title => "Original") } | 54 | Globalize.with_locale(:en) { node.draft.update!(:title => "Original") } |
| 55 | node.lock_for_editing!(users(:quentin)) | ||
| 53 | 56 | ||
| 54 | patch :update, params: { :node_id => node.id, :translation_locale => "en", :page => { :title => "Revised" } } | 57 | patch :update, params: { :node_id => node.id, :translation_locale => "en", :page => { :title => "Revised" } } |
| 55 | 58 | ||
| @@ -75,4 +78,20 @@ class PageTranslationsControllerTest < ActionController::TestCase | |||
| 75 | 78 | ||
| 76 | assert_match(/No EN translation exists/, flash[:error]) | 79 | assert_match(/No EN translation exists/, flash[:error]) |
| 77 | end | 80 | end |
| 81 | |||
| 82 | test "autosave writes the translation without creating a new revision or touching the draft" do | ||
| 83 | login_as :quentin | ||
| 84 | node = Node.root.children.create!(:slug => "translations_autosave_test") | ||
| 85 | node.publish_draft! | ||
| 86 | node.lock_for_editing!(users(:quentin)) | ||
| 87 | page_count_before = node.pages.count | ||
| 88 | |||
| 89 | put :autosave, params: { :node_id => node.id, :translation_locale => "en", :page => { :title => "in progress" } } | ||
| 90 | |||
| 91 | assert_response :success | ||
| 92 | node.reload | ||
| 93 | assert_not_nil node.autosave | ||
| 94 | assert_equal page_count_before, node.pages.count | ||
| 95 | assert_equal "in progress", Globalize.with_locale(:en) { node.autosave.title } | ||
| 96 | end | ||
| 78 | end | 97 | end |
