diff options
Diffstat (limited to 'test/models/node_test.rb')
| -rw-r--r-- | test/models/node_test.rb | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/test/models/node_test.rb b/test/models/node_test.rb index 39be6d32..bd91d560 100644 --- a/test/models/node_test.rb +++ b/test/models/node_test.rb | |||
| @@ -1157,4 +1157,91 @@ class NodeTest < ActiveSupport::TestCase | |||
| 1157 | assert_raises(ActiveRecord::RecordInvalid) { node.reload.publish_draft! } | 1157 | assert_raises(ActiveRecord::RecordInvalid) { node.reload.publish_draft! } |
| 1158 | assert_nil node.reload.head | 1158 | assert_nil node.reload.head |
| 1159 | end | 1159 | end |
| 1160 | |||
| 1161 | test "publishing a redirect to a page that itself redirects is refused" do | ||
| 1162 | final = Node.root.children.create!(:slug => "chain_final") | ||
| 1163 | final.publish_draft! | ||
| 1164 | |||
| 1165 | middle = Node.root.children.create!(:slug => "chain_middle") | ||
| 1166 | middle.draft.update!(:redirect => "temporary", :redirect_node_id => final.id) | ||
| 1167 | middle.publish_draft! | ||
| 1168 | |||
| 1169 | first = Node.root.children.create!(:slug => "chain_first") | ||
| 1170 | first.draft.update!(:redirect => "temporary", :redirect_node_id => middle.id) | ||
| 1171 | |||
| 1172 | assert_raises(ActiveRecord::RecordInvalid) { first.reload.publish_draft! } | ||
| 1173 | assert_nil first.reload.head | ||
| 1174 | end | ||
| 1175 | |||
| 1176 | test "publishing a redirect is refused when something already redirects here" do | ||
| 1177 | target = Node.root.children.create!(:slug => "chain_target") | ||
| 1178 | target.publish_draft! | ||
| 1179 | |||
| 1180 | source = Node.root.children.create!(:slug => "chain_source") | ||
| 1181 | source.draft.update!(:redirect => "temporary", :redirect_node_id => target.id) | ||
| 1182 | source.publish_draft! | ||
| 1183 | |||
| 1184 | onward = Node.root.children.create!(:slug => "chain_onward") | ||
| 1185 | onward.publish_draft! | ||
| 1186 | |||
| 1187 | target.reload | ||
| 1188 | find_or_create_draft(target, @user1) | ||
| 1189 | target.draft.update!(:redirect => "temporary", :redirect_node_id => onward.id) | ||
| 1190 | |||
| 1191 | assert_raises(ActiveRecord::RecordInvalid) { target.reload.publish_draft! } | ||
| 1192 | assert_nil target.reload.head.redirect | ||
| 1193 | end | ||
| 1194 | |||
| 1195 | test "a draft redirect elsewhere does not block publishing a redirect here" do | ||
| 1196 | target = Node.root.children.create!(:slug => "draft_chain_target") | ||
| 1197 | target.publish_draft! | ||
| 1198 | |||
| 1199 | onward = Node.root.children.create!(:slug => "draft_chain_onward") | ||
| 1200 | onward.publish_draft! | ||
| 1201 | |||
| 1202 | source = Node.root.children.create!(:slug => "draft_chain_source") | ||
| 1203 | source.draft.update!(:redirect => "temporary", :redirect_node_id => target.id) | ||
| 1204 | # deliberately not published: only live redirects count | ||
| 1205 | |||
| 1206 | target.reload | ||
| 1207 | find_or_create_draft(target, @user1) | ||
| 1208 | target.draft.update!(:redirect => "temporary", :redirect_node_id => onward.id) | ||
| 1209 | target.reload.publish_draft! | ||
| 1210 | |||
| 1211 | assert_equal "temporary", target.reload.head.redirect | ||
| 1212 | end | ||
| 1213 | |||
| 1214 | test "publishing a page that redirects to itself is refused" do | ||
| 1215 | node = Node.root.children.create!(:slug => "self_redirect") | ||
| 1216 | node.draft.update!(:redirect => "temporary", :redirect_node_id => node.id) | ||
| 1217 | |||
| 1218 | assert_raises(ActiveRecord::RecordInvalid) { node.reload.publish_draft! } | ||
| 1219 | assert_nil node.reload.head | ||
| 1220 | end | ||
| 1221 | |||
| 1222 | test "publishing a redirect to a node that no longer exists is refused" do | ||
| 1223 | doomed = Node.root.children.create!(:slug => "doomed_redirect_target") | ||
| 1224 | node = Node.root.children.create!(:slug => "dangling_redirect") | ||
| 1225 | node.draft.update!(:redirect => "temporary", :redirect_node_id => doomed.id) | ||
| 1226 | doomed.destroy! | ||
| 1227 | |||
| 1228 | assert_raises(ActiveRecord::RecordInvalid) { node.reload.publish_draft! } | ||
| 1229 | assert_nil node.reload.head | ||
| 1230 | end | ||
| 1231 | |||
| 1232 | test "the public search excludes a redirecting page" do | ||
| 1233 | found = Node.root.children.create!(:slug => "search_visible") | ||
| 1234 | found.draft.update!(:title => "Wachhund") | ||
| 1235 | found.publish_draft! | ||
| 1236 | |||
| 1237 | hidden = Node.root.children.create!(:slug => "search_hidden") | ||
| 1238 | hidden.draft.update!(:title => "Wachhund", :redirect => "temporary", | ||
| 1239 | :redirect_node_id => found.id) | ||
| 1240 | hidden.publish_draft! | ||
| 1241 | |||
| 1242 | results = Node.search("Wachhund") | ||
| 1243 | |||
| 1244 | assert_includes results, found | ||
| 1245 | assert_not_includes results, hidden | ||
| 1246 | end | ||
| 1160 | end | 1247 | end |
