diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/models/helpers/node_actions_helper_test.rb | 32 | ||||
| -rw-r--r-- | test/models/node_action_test.rb | 16 |
2 files changed, 43 insertions, 5 deletions
diff --git a/test/models/helpers/node_actions_helper_test.rb b/test/models/helpers/node_actions_helper_test.rb index 93bbdf6..5244c19 100644 --- a/test/models/helpers/node_actions_helper_test.rb +++ b/test/models/helpers/node_actions_helper_test.rb | |||
| @@ -21,12 +21,13 @@ class NodeActionsHelperTest < ActionView::TestCase | |||
| 21 | "human_readable_node_name" => "Subject" }.merge(metadata)) | 21 | "human_readable_node_name" => "Subject" }.merge(metadata)) |
| 22 | end | 22 | end |
| 23 | 23 | ||
| 24 | test "publish renders the title pair" do | 24 | test "publish renders the revision sentence, not the titles" do |
| 25 | out = action_summary(entry("publish", | 25 | out = action_summary(entry("publish", |
| 26 | { "via" => "draft", "title" => { "from" => "Old", "to" => "New" } })) | 26 | { "via" => "draft", "title" => { "from" => "Old", "to" => "New" } })) |
| 27 | 27 | ||
| 28 | assert_includes out, "quentin" | 28 | assert_includes out, "quentin" |
| 29 | assert_includes out, "Old" | 29 | assert_includes out, "new revision" |
| 30 | assert_not_includes out, "Old" | ||
| 30 | end | 31 | end |
| 31 | 32 | ||
| 32 | test "first publish uses its own sentence" do | 33 | test "first publish uses its own sentence" do |
| @@ -68,10 +69,8 @@ class NodeActionsHelperTest < ActionView::TestCase | |||
| 68 | 69 | ||
| 69 | test "metadata values are escaped" do | 70 | test "metadata values are escaped" do |
| 70 | out = action_summary(entry("publish", | 71 | out = action_summary(entry("publish", |
| 71 | { "human_readable_node_name" => "<b>bold</b>", | 72 | { "human_readable_node_name" => "<b>bold</b>" })) |
| 72 | "title" => { "from" => "<script>alert(1)</script>", "to" => "x" } })) | ||
| 73 | 73 | ||
| 74 | assert_not_includes out, "<script>" | ||
| 75 | assert_not_includes out, "<b>" | 74 | assert_not_includes out, "<b>" |
| 76 | end | 75 | end |
| 77 | 76 | ||
| @@ -82,4 +81,27 @@ class NodeActionsHelperTest < ActionView::TestCase | |||
| 82 | 81 | ||
| 83 | assert_includes out, "<a " | 82 | assert_includes out, "<a " |
| 84 | end | 83 | end |
| 84 | |||
| 85 | test "details are guarded off when nothing but an unchanged title is present" do | ||
| 86 | unchanged = entry("publish", { "title" => { "from" => "Same", "to" => "Same" } }) | ||
| 87 | changed = entry("publish", { "title" => { "from" => "Old", "to" => "New" } }) | ||
| 88 | |||
| 89 | assert_not action_details?(unchanged) | ||
| 90 | assert action_details?(changed) | ||
| 91 | end | ||
| 92 | |||
| 93 | test "first publish with a byline names the author" do | ||
| 94 | out = action_summary(entry("publish", | ||
| 95 | { "title" => { "from" => nil, "to" => "New" }, | ||
| 96 | "author" => { "from" => nil, "to" => "quentin" } })) | ||
| 97 | |||
| 98 | assert_includes out, "author" | ||
| 99 | end | ||
| 100 | |||
| 101 | test "create entries with their flat title render and are guarded off details" do | ||
| 102 | e = entry("create", { "title" => "Initial", "path" => "a/b" }) | ||
| 103 | |||
| 104 | assert_includes action_summary(e), "a/b" | ||
| 105 | assert_not action_details?(e) | ||
| 106 | end | ||
| 85 | end | 107 | end |
diff --git a/test/models/node_action_test.rb b/test/models/node_action_test.rb index 24d8245..b177cca 100644 --- a/test/models/node_action_test.rb +++ b/test/models/node_action_test.rb | |||
| @@ -18,6 +18,12 @@ class NodeActionTest < ActiveSupport::TestCase | |||
| 18 | assert_equal({ :title => { "from" => nil, "to" => "Erstausgabe" } }, diff) | 18 | assert_equal({ :title => { "from" => nil, "to" => "Erstausgabe" } }, diff) |
| 19 | end | 19 | end |
| 20 | 20 | ||
| 21 | test "first publish carries the byline when the page has one" do | ||
| 22 | diff = NodeAction.head_diff(nil, build_page(:user => users(:quentin))) | ||
| 23 | |||
| 24 | assert_equal({ "from" => nil, "to" => users(:quentin).login }, diff[:author]) | ||
| 25 | end | ||
| 26 | |||
| 21 | test "title pair is always present, even when unchanged" do | 27 | test "title pair is always present, even when unchanged" do |
| 22 | diff = NodeAction.head_diff(build_page, build_page) | 28 | diff = NodeAction.head_diff(build_page, build_page) |
| 23 | 29 | ||
| @@ -109,4 +115,14 @@ class NodeActionTest < ActiveSupport::TestCase | |||
| 109 | 115 | ||
| 110 | assert_nil NodeAction.head_diff(old_page, new_page)[:translation_diff] | 116 | assert_nil NodeAction.head_diff(old_page, new_page)[:translation_diff] |
| 111 | end | 117 | end |
| 118 | |||
| 119 | test "record! passes provenance and historical timestamps through" do | ||
| 120 | long_ago = 2.years.ago | ||
| 121 | action = NodeAction.record!(:node => nil, :action => "publish", | ||
| 122 | :occurred_at => long_ago, | ||
| 123 | :inferred_from => "from_page_revision") | ||
| 124 | |||
| 125 | assert_equal "from_page_revision", action.inferred_from | ||
| 126 | assert_in_delta long_ago.to_f, action.occurred_at.to_f, 1.0 | ||
| 127 | end | ||
| 112 | end | 128 | end |
