summaryrefslogtreecommitdiff
path: root/test/controllers/revisions_controller_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/controllers/revisions_controller_test.rb')
-rw-r--r--test/controllers/revisions_controller_test.rb167
1 files changed, 154 insertions, 13 deletions
diff --git a/test/controllers/revisions_controller_test.rb b/test/controllers/revisions_controller_test.rb
index b4dcd8f..e5726f7 100644
--- a/test/controllers/revisions_controller_test.rb
+++ b/test/controllers/revisions_controller_test.rb
@@ -1,12 +1,12 @@
1require 'test_helper' 1require 'test_helper'
2 2
3class RevisionsControllerTest < ActionController::TestCase 3class RevisionsControllerTest < ActionController::TestCase
4 4
5 def setup 5 def setup
6 Node.root.descendants.destroy_all 6 Node.root.descendants.destroy_all
7 @user = User.find_by_login("aaron") 7 @user = User.find_by_login("aaron")
8 @node = Node.root.children.create!( :slug => "version_me" ) 8 @node = Node.root.children.create!( :slug => "version_me" )
9 9
10 draft = @node.draft 10 draft = @node.draft
11 draft.body = "first" 11 draft.body = "first"
12 @node.publish_draft! 12 @node.publish_draft!
@@ -15,48 +15,189 @@ class RevisionsControllerTest < ActionController::TestCase
15 draft.update(:body => "second") 15 draft.update(:body => "second")
16 @node.publish_draft! 16 @node.publish_draft!
17 end 17 end
18 18
19 test "setup" do 19 test "setup" do
20 assert_equal 2, Node.count 20 assert_equal 2, Node.count
21 assert_equal 2, @node.pages.count 21 assert_equal 2, @node.pages.count
22 assert_equal ["first", "second"], @node.pages.map {|p| p.body} 22 assert_equal ["first", "second"], @node.pages.map {|p| p.body}
23 end 23 end
24 24
25 test "get list of revisions for a given node" do 25 test "get list of revisions for a given node" do
26 login_as :quentin 26 login_as :quentin
27 get :index, params: { :node_id => @node.id } 27 get :index, params: { :node_id => @node.id }
28 assert_response :success 28 assert_response :success
29 assert_select ".revision", 2 29 assert_select ".revision", 2
30 end 30 end
31 31
32 test "showing one revision" do 32 test "showing one revision" do
33 login_as :quentin 33 login_as :quentin
34 get :show, params: { :node_id => @node.id, :id => @node.pages.last.id } 34 get :show, params: { :node_id => @node.id, :id => @node.pages.last.id }
35 assert_response :success 35 assert_response :success
36 assert_select "strong", "Body" 36 assert_select ".node_description", "Body"
37 assert_select "td", {:count => 1, :text => "second"} 37 assert_select ".node_content", {:count => 1, :text => "second"}
38 end
39
40 test "showing a revision renders real markup in the body, not escaped entities" do
41 login_as :quentin
42 node = Node.root.children.create!(:slug => "show_markup_test")
43 draft = node.draft
44 draft.body = "<h3>Hello</h3>"
45 node.publish_draft!
46
47 get :show, params: { :node_id => node.id, :id => node.head.id }
48 assert_response :success
49 assert_select ".node_content h3", "Hello"
38 end 50 end
39 51
40 test "diffing two revisions" do 52 test "diffing two revisions" do
41 login_as :quentin 53 login_as :quentin
42 post( 54 post(
43 :diff, params: { 55 :diff, params: {
44 :node_id => @node.id, 56 :node_id => @node.id,
45 :start_revision => @node.pages.first.revision, 57 :start_revision => @node.pages.first.revision,
46 :end_revision => @node.pages.last.revision 58 :end_revision => @node.pages.last.revision
47 } 59 }
48 ) 60 )
49 assert_response :success 61 assert_response :success
50 end 62 end
51 63
52 test "restoring a revision" do 64 test "restoring a revision" do
53 assert_equal "second", @node.head.body 65 assert_equal "second", @node.head.body
54 66
55 login_as :aaron 67 login_as :aaron
56 put( :restore, params: { :node_id => @node.id, :id => @node.pages.first.id } ) 68 put( :restore, params: { :node_id => @node.id, :id => @node.pages.first.id } )
57 69
58 @node.reload 70 @node.reload
59 assert_equal @node.head, @node.pages.first 71 assert_equal @node.head, @node.pages.first
60 assert_equal "first", @node.head.reload.body 72 assert_equal "first", @node.head.reload.body
61 end 73 end
74
75 test "diffing two revisions renders real markup with only the changed words marked" do
76 login_as :quentin
77 post(
78 :diff, params: {
79 :node_id => @node.id,
80 :start_revision => @node.pages.first.revision,
81 :end_revision => @node.pages.last.revision
82 }
83 )
84 assert_response :success
85 assert_select "del", "first"
86 assert_select "ins", "second"
87 assert_no_match /&lt;/, response.body
88 end
89
90 test "diffing two revisions in side by side view renders two columns" do
91 login_as :quentin
92 post(
93 :diff, params: {
94 :node_id => @node.id,
95 :start_revision => @node.pages.first.revision,
96 :end_revision => @node.pages.last.revision,
97 :view => "side_by_side"
98 }
99 )
100 assert_response :success
101 assert_select ".diff_column", 2
102 end
103
104 test "diffing head against draft by name" do
105 login_as :quentin
106 @node.find_or_create_draft(@user)
107 @node.draft.update(:body => "draft body")
108
109 post(:diff, params: { :node_id => @node.id, :start_revision => "head", :end_revision => "draft" })
110 assert_response :success
111 end
112
113 test "diffing a layer pair that no longer exists redirects with a flash" do
114 login_as :quentin
115 post(:diff, params: { :node_id => @node.id, :start_revision => "draft", :end_revision => "autosave" })
116 assert_redirected_to node_path(@node)
117 assert flash[:error].present?
118 end
119
120 test "diffing by name shows a clear comparison label instead of a misleading revision picker" do
121 login_as :quentin
122 @node.find_or_create_draft(@user)
123
124 post(:diff, params: { :node_id => @node.id, :start_revision => "head", :end_revision => "draft" })
125 assert_response :success
126 assert_select "strong", "Head"
127 assert_select "strong", "Draft"
128 assert_select "select[name=?]", "start_revision", :count => 0
129 end
130
131 test "pair-switcher buttons carry their params as real hidden fields, not a query string" do
132 login_as :quentin
133 @node.find_or_create_draft(@user)
134 @node.lock_for_editing!(@user)
135 @node.autosave!({ :body => "unsaved" }, @user)
136
137 post(:diff, params: { :node_id => @node.id, :start_revision => "head", :end_revision => "draft" })
138 assert_response :success
139 assert_select "form.computation input[type=hidden][name=start_revision]"
140 assert_select "form.computation input[type=hidden][name=end_revision]"
141 end
142
143 test "the view toggle is available even when comparing named layers" do
144 login_as :quentin
145 @node.find_or_create_draft(@user)
146
147 post(:diff, params: { :node_id => @node.id, :start_revision => "head", :end_revision => "draft" })
148 assert_response :success
149 assert_select "a", "Side by side"
150 end
151
152 test "diffing two revisions also shows tag, template, and asset changes" do
153 login_as :quentin
154 @node.find_or_create_draft(@user)
155 @node.draft.tag_list = "update"
156 @node.draft.save!
157
158 post(:diff, params: { :node_id => @node.id, :start_revision => @node.pages.first.revision, :end_revision => @node.pages.last.revision })
159 assert_response :success
160 assert_select "h3", "Tags"
161 assert_select "h3", "Template"
162 assert_select "h3", "Assets"
163 end
164
165 test "revisions#index links back to the node" do
166 login_as :quentin
167 get :index, params: { :node_id => @node.id }
168 assert_response :success
169 assert_select "a[href=?]", node_path(@node)
170 end
171
172 test "diff defaults to a locale that actually changed, not the ambient default" do
173 login_as :quentin
174 node = Node.root.children.create!(:slug => "diff_default_locale_test")
175 node.draft.save!
176 node.publish_draft!
177
178 node.find_or_create_draft(@user)
179 Globalize.with_locale(:en) { node.draft.update!(:title => "Changed in English only") }
180 node.draft.save!
181
182 post(:diff, params: { :node_id => node.id, :start_revision => "head", :end_revision => "draft" })
183
184 assert_response :success
185 assert_match(/Changed/, response.body)
186 end
187
188 test "diff respects an explicitly requested locale over the auto-detected one" do
189 login_as :quentin
190 node = Node.root.children.create!(:slug => "diff_explicit_locale_test")
191 node.draft.save!
192 node.publish_draft!
193
194 node.find_or_create_draft(@user)
195 Globalize.with_locale(:en) { node.draft.update!(:title => "English changed") }
196 node.draft.save!
197
198 post(:diff, params: { :node_id => node.id, :start_revision => "head", :end_revision => "draft", :locale => "de" })
199
200 assert_response :success
201 assert_no_match(/English changed/, response.body)
202 end
62end 203end