diff options
Diffstat (limited to 'test/models/node_test.rb')
| -rw-r--r-- | test/models/node_test.rb | 63 |
1 files changed, 60 insertions, 3 deletions
diff --git a/test/models/node_test.rb b/test/models/node_test.rb index 022fff6..c8e49e5 100644 --- a/test/models/node_test.rb +++ b/test/models/node_test.rb | |||
| @@ -633,6 +633,7 @@ class NodeTest < ActiveSupport::TestCase | |||
| 633 | assert_equal node.head, action.page | 633 | assert_equal node.head, action.page |
| 634 | assert_equal @user1, action.user | 634 | assert_equal @user1, action.user |
| 635 | assert_equal "publish", action.action | 635 | assert_equal "publish", action.action |
| 636 | assert_equal "draft", action.metadata["via"] | ||
| 636 | end | 637 | end |
| 637 | 638 | ||
| 638 | test "publish_draft! called with no user logs no actor, not a guessed one" do | 639 | test "publish_draft! called with no user logs no actor, not a guessed one" do |
| @@ -692,7 +693,7 @@ class NodeTest < ActiveSupport::TestCase | |||
| 692 | assert_equal count_before, NodeAction.count | 693 | assert_equal count_before, NodeAction.count |
| 693 | end | 694 | end |
| 694 | 695 | ||
| 695 | test "publish_draft! records the title's from/to in metadata" do | 696 | test "publish_draft! records the title diff in metadata" do |
| 696 | node = create_node_with_published_page | 697 | node = create_node_with_published_page |
| 697 | Globalize.with_locale(:de) { node.head.update!(:title => "Original Title") } | 698 | Globalize.with_locale(:de) { node.head.update!(:title => "Original Title") } |
| 698 | find_or_create_draft(node, @user1) | 699 | find_or_create_draft(node, @user1) |
| @@ -701,7 +702,63 @@ class NodeTest < ActiveSupport::TestCase | |||
| 701 | node.publish_draft!(@user1) | 702 | node.publish_draft!(@user1) |
| 702 | 703 | ||
| 703 | action = NodeAction.last | 704 | action = NodeAction.last |
| 704 | assert_equal "Original Title", action.metadata["from"] | 705 | assert_equal "draft", action.metadata["via"] |
| 705 | assert_equal "New Title", action.metadata["to"] | 706 | assert_equal "Original Title", action.metadata.dig("title", "from") |
| 707 | assert_equal "New Title", action.metadata.dig("title", "to") | ||
| 708 | end | ||
| 709 | |||
| 710 | test "publishing a staged slug change logs a move with the path pair" do | ||
| 711 | node = create_node_with_published_page | ||
| 712 | path_before = node.unique_name | ||
| 713 | node.staged_slug = "moved-#{node.slug}" | ||
| 714 | node.save! | ||
| 715 | publish_count_before = NodeAction.where(:action => "publish").count | ||
| 716 | |||
| 717 | node.publish_draft!(@user1) | ||
| 718 | |||
| 719 | node.reload | ||
| 720 | assert_not_equal path_before, node.unique_name | ||
| 721 | |||
| 722 | action = NodeAction.where(:action => "move").last | ||
| 723 | assert_equal node, action.node | ||
| 724 | assert_equal @user1, action.user | ||
| 725 | assert_equal path_before, action.metadata.dig("path", "from") | ||
| 726 | assert_equal node.unique_name, action.metadata.dig("path", "to") | ||
| 727 | |||
| 728 | # No draft was pending: path change alone must not fabricate a publish. | ||
| 729 | assert_equal publish_count_before, NodeAction.where(:action => "publish").count | ||
| 730 | end | ||
| 731 | |||
| 732 | test "publishing a draft together with a staged move logs two entries" do | ||
| 733 | node = create_node_with_published_page | ||
| 734 | find_or_create_draft(node, @user1) | ||
| 735 | node.staged_slug = "relocated-#{node.slug}" | ||
| 736 | node.save! | ||
| 737 | |||
| 738 | assert_difference "NodeAction.count", 2 do | ||
| 739 | node.publish_draft!(@user1) | ||
| 740 | end | ||
| 741 | |||
| 742 | assert_equal %w[move publish], | ||
| 743 | NodeAction.order(:id).last(2).map(&:action).sort | ||
| 744 | end | ||
| 745 | |||
| 746 | test "restore_revision! logs a publish via revision" do | ||
| 747 | node = create_node_with_published_page | ||
| 748 | Globalize.with_locale(:de) { node.head.update!(:title => "First") } | ||
| 749 | first_head = node.head | ||
| 750 | find_or_create_draft(node, @user1) | ||
| 751 | Globalize.with_locale(:de) { node.draft.update!(:title => "Second") } | ||
| 752 | node.publish_draft!(@user1) | ||
| 753 | |||
| 754 | node.restore_revision!(first_head.revision, @user1) | ||
| 755 | |||
| 756 | action = NodeAction.last | ||
| 757 | assert_equal "publish", action.action | ||
| 758 | assert_equal "revision", action.metadata["via"] | ||
| 759 | assert_equal first_head, action.page | ||
| 760 | assert_equal @user1, action.user | ||
| 761 | assert_equal "Second", action.metadata.dig("title", "from") | ||
| 762 | assert_equal "First", action.metadata.dig("title", "to") | ||
| 706 | end | 763 | end |
| 707 | end | 764 | end |
