summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-13 14:12:33 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-13 14:12:33 +0200
commitea8ee1d35948c6adc4a377c9eb77d99b2d856932 (patch)
tree2a5c97180bd9f4ac8843379af46984d498db1412 /test
parent8baac265059b70da0148487458ee4077b15f155e (diff)
Carry over other-locale translations when creating an autosave
Node#autosave! only copied assets forward onto a newly created autosave, not translations. Invisible for single-locale nodes, but a node with an existing multi-locale head/draft that gets locked and edited in one locale would silently drop every other locale's translation from the new autosave -- and from there into the draft and eventually head, since save_draft! faithfully clones whatever the autosave actually holds. Fixed by using clone_attributes_from, which already does a complete clone (translations, assets, tags, template, published_at) -- the same method save_draft! already relies on two branches later, so no new mechanism, just closing the one place still doing a partial, hand-rolled version of it.
Diffstat (limited to 'test')
-rw-r--r--test/models/node_test.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/models/node_test.rb b/test/models/node_test.rb
index a1da82c..91a4a6d 100644
--- a/test/models/node_test.rb
+++ b/test/models/node_test.rb
@@ -614,4 +614,36 @@ class NodeTest < ActiveSupport::TestCase
614 assert_includes node.autosave.reload.assets, original 614 assert_includes node.autosave.reload.assets, original
615 assert_includes node.autosave.reload.assets, extra 615 assert_includes node.autosave.reload.assets, extra
616 end 616 end
617
618 test "autosave! carries over other-locale translations to the newly created autosave row" do
619 node = Node.root.children.create!(:slug => "autosave_translation_carryover_test")
620 user = User.find_by_login("quentin")
621
622 Globalize.with_locale(:en) { node.draft.update!(:title => "English title") }
623
624 node.lock_for_editing!(user)
625 Globalize.with_locale(:de) { node.autosave!({:title => "German edit"}, user) }
626
627 autosave = node.autosave.reload
628 assert_includes autosave.translated_locales, :en
629 assert_equal "English title", Globalize.with_locale(:en) { autosave.title }
630 assert_equal "German edit", Globalize.with_locale(:de) { autosave.title }
631 end
632
633 test "autosave! does not reset other-locale translations already attached directly to an existing autosave" do
634 node = Node.root.children.create!(:slug => "autosave_translation_no_reset_test")
635 user = User.find_by_login("quentin")
636
637 Globalize.with_locale(:en) { node.draft.update!(:title => "Original English title") }
638
639 node.lock_for_editing!(user)
640 Globalize.with_locale(:de) { node.autosave!({:title => "v1"}, user) }
641 Globalize.with_locale(:en) { node.autosave.update!(:title => "Edited directly on autosave") }
642
643 Globalize.with_locale(:de) { node.autosave!({:title => "v2"}, user) }
644
645 autosave = node.autosave.reload
646 assert_equal "Edited directly on autosave", Globalize.with_locale(:en) { autosave.title }
647 assert_equal "v2", Globalize.with_locale(:de) { autosave.title }
648 end
617end 649end