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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
require 'test_helper'
class RevisionsControllerTest < ActionController::TestCase
def setup
Node.root.descendants.destroy_all
@user = User.find_by_login("aaron")
@node = Node.root.children.create!( :slug => "version_me" )
draft = @node.draft
draft.body = "first"
@node.publish_draft!
@node.find_or_create_draft @user
draft = @node.draft
draft.update(:body => "second")
@node.publish_draft!
end
test "setup" do
assert_equal 2, Node.count
assert_equal 2, @node.pages.count
assert_equal ["first", "second"], @node.pages.map {|p| p.body}
end
test "get list of revisions for a given node" do
login_as :quentin
get :index, params: { :node_id => @node.id }
assert_response :success
assert_select ".revision", 2
end
test "showing one revision" do
login_as :quentin
get :show, params: { :node_id => @node.id, :id => @node.pages.last.id }
assert_response :success
assert_select ".node_description", "Body"
assert_select ".node_content", {:count => 1, :text => "second"}
end
test "showing a revision renders real markup in the body, not escaped entities" do
login_as :quentin
node = Node.root.children.create!(:slug => "show_markup_test")
draft = node.draft
draft.body = "<h3>Hello</h3>"
node.publish_draft!
get :show, params: { :node_id => node.id, :id => node.head.id }
assert_response :success
assert_select ".node_content h3", "Hello"
end
test "diffing two revisions" do
login_as :quentin
post(
:diff, params: {
:node_id => @node.id,
:start_revision => @node.pages.first.revision,
:end_revision => @node.pages.last.revision
}
)
assert_response :success
end
test "restoring a revision" do
assert_equal "second", @node.head.body
login_as :aaron
put( :restore, params: { :node_id => @node.id, :id => @node.pages.first.id } )
@node.reload
assert_equal @node.head, @node.pages.first
assert_equal "first", @node.head.reload.body
end
test "diffing two revisions renders real markup with only the changed words marked" do
login_as :quentin
post(
:diff, params: {
:node_id => @node.id,
:start_revision => @node.pages.first.revision,
:end_revision => @node.pages.last.revision
}
)
assert_response :success
assert_select "del", "first"
assert_select "ins", "second"
assert_no_match /</, response.body
end
test "diffing two revisions in side by side view renders two columns" do
login_as :quentin
post(
:diff, params: {
:node_id => @node.id,
:start_revision => @node.pages.first.revision,
:end_revision => @node.pages.last.revision,
:view => "side_by_side"
}
)
assert_response :success
assert_select ".diff_column", 2
end
end
|