1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
require 'test_helper'
class NodeActionsHelperTest < ActionView::TestCase
def setup
@original_locale = I18n.locale
I18n.locale = :en
end
def default_url_options
{ :locale => nil }
end
def teardown
I18n.locale = @original_locale
end
def entry action, metadata = {}, node: nil, user: nil, page: nil
NodeAction.create!(:node => node, :user => user, :page => page,
:action => action, :occurred_at => Time.now,
:metadata => { "username" => "quentin",
"human_readable_node_name" => "Subject" }.merge(metadata))
end
test "publish renders the title pair" do
out = action_summary(entry("publish",
{ "via" => "draft", "title" => { "from" => "Old", "to" => "New" } }))
assert_includes out, "quentin"
assert_includes out, "Old"
end
test "first publish uses its own sentence" do
out = action_summary(entry("publish",
{ "via" => "draft", "title" => { "from" => nil, "to" => "New" } }))
assert_includes out, "for the first time"
end
test "rollback publishes get the rollback sentence" do
out = action_summary(entry("publish",
{ "via" => "revision", "title" => { "from" => "Now", "to" => "Then" } }))
assert_includes out, "rolled"
end
test "move renders the path pair" do
out = action_summary(entry("move",
{ "path" => { "from" => "a/b", "to" => "a/c" } }))
assert_includes out, "a/b"
assert_includes out, "a/c"
end
test "unknown verbs degrade to a generic sentence, never an error" do
out = action_summary(entry("frobnicate"))
assert_includes out, "frobnicate"
assert_includes out, "quentin"
end
test "dead references render as plain names from metadata, no links" do
out = action_summary(entry("publish",
{ "title" => { "from" => "Old", "to" => "New" } }))
assert_not_includes out, "<a "
assert_includes out, "Subject"
end
test "metadata values are escaped" do
out = action_summary(entry("publish",
{ "human_readable_node_name" => "<b>bold</b>",
"title" => { "from" => "<script>alert(1)</script>", "to" => "x" } }))
assert_not_includes out, "<script>"
assert_not_includes out, "<b>"
end
test "live associations upgrade names to links" do
out = action_summary(entry("publish",
{ "title" => { "from" => "Old", "to" => "New" } },
:user => users(:quentin)))
assert_includes out, "<a "
end
end
|