summaryrefslogtreecommitdiff
path: root/test/models/helpers/revisions_helper_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/models/helpers/revisions_helper_test.rb')
-rw-r--r--test/models/helpers/revisions_helper_test.rb69
1 files changed, 69 insertions, 0 deletions
diff --git a/test/models/helpers/revisions_helper_test.rb b/test/models/helpers/revisions_helper_test.rb
index 6bb5f077..f59823f9 100644
--- a/test/models/helpers/revisions_helper_test.rb
+++ b/test/models/helpers/revisions_helper_test.rb
@@ -1,4 +1,73 @@
1require 'test_helper' 1require 'test_helper'
2 2
3class RevisionsHelperTest < ActionView::TestCase 3class RevisionsHelperTest < ActionView::TestCase
4 class RevisionSet
5 def initialize revisions
6 @revisions = revisions
7 end
8
9 def pages
10 self
11 end
12
13 def exists? conditions
14 @revisions.include?(conditions[:revision])
15 end
16 end
17
18 def node_with *revisions
19 RevisionSet.new(revisions)
20 end
21
22 test "a forward pair offers both neighbours in forward orientation" do
23 assert_equal [[2, 3], [4, 5]],
24 neighbour_revision_pairs(node_with(1, 2, 3, 4, 5), 3, 4)
25 end
26
27 test "a reverse pair offers both neighbours in reverse orientation" do
28 assert_equal [[3, 2], [5, 4]],
29 neighbour_revision_pairs(node_with(1, 2, 3, 4, 5), 4, 3)
30 end
31
32 test "the earliest pair has no earlier neighbour" do
33 assert_equal [nil, [2, 3]],
34 neighbour_revision_pairs(node_with(1, 2, 3), 1, 2)
35 end
36
37 test "the latest pair has no later neighbour" do
38 assert_equal [[1, 2], nil],
39 neighbour_revision_pairs(node_with(1, 2, 3), 2, 3)
40 end
41
42 test "a layer comparison offers no neighbours" do
43 assert_equal [nil, nil],
44 neighbour_revision_pairs(node_with(1, 2, 3), "head", "draft")
45 end
46
47 test "mixing a layer with a number offers no neighbours" do
48 assert_equal [nil, nil],
49 neighbour_revision_pairs(node_with(1, 2, 3), "head", 3)
50 end
51
52 test "a non-adjacent pair offers no neighbours" do
53 assert_equal [nil, nil],
54 neighbour_revision_pairs(node_with(1, 2, 3, 4, 5), 2, 5)
55 end
56
57 # The controller sets both ends to 1 when a node has a single page.
58 test "a revision compared against itself offers no neighbours" do
59 assert_equal [nil, nil], neighbour_revision_pairs(node_with(1), 1, 1)
60 end
61
62 test "string references are accepted, since they arrive from the query string" do
63 assert_equal [[1, 2], nil],
64 neighbour_revision_pairs(node_with(1, 2, 3), "2", "3")
65 end
66
67 # Revision numbers are contiguous today. Should that stop being true, the
68 # control disables rather than pointing at a revision that is not there.
69 test "a gap disables the control rather than skipping over it" do
70 assert_equal [nil, [5, 6]],
71 neighbour_revision_pairs(node_with(1, 2, 4, 5, 6), 4, 5)
72 end
4end 73end