/
test_view_helpers.rb
48 lines (38 loc) · 1.24 KB
/
test_view_helpers.rb
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
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
include PaginateAlphabetically::ViewHelpers
module PaginateAlphabetically
module ViewHelpers
def request
stub(:path => '')
end
end
end
class ViewHelperTest < ActiveSupport::TestCase
def setup
@result = alphabetically_paginate([Thing.create!(:name => 'a')])
end
test "it includes all the letters" do
('A'..'Z').each do |letter|
assert @result.include?(letter)
end
end
test "it links to the available letters" do
assert @result.include?('<a href="?letter=A">')
end
test "it returns nothing when the collection is empty" do
assert_equal "", alphabetically_paginate([])
end
test "it does not link to letters that have no content" do
assert_equal false, @result.include?('href="?letter=B"')
end
test "it wraps the letters as list items" do
assert @result.include?('<li>B</li>')
end
test "it wraps the result in a ul" do
assert @result.include?('<ul class="pagination">')
end
test "it allows the css class to be overridden" do
result_with_class = alphabetically_paginate([Thing.create!(:name => 'a')], :class => 'overridden-class')
assert result_with_class.include?('class="overridden-class"')
end
end