recent_documents_block_test.rb
3.41 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
require_relative "../test_helper"
class RecentDocumentsBlockTest < ActiveSupport::TestCase
include ActionView::Helpers::OutputSafetyHelper
def setup
@articles = []
@profile = create_user('testinguser').person
@profile.articles.destroy_all
['first', 'second', 'third', 'fourth', 'fifth'].each do |name|
article = @profile.articles.create!(:name => name)
@articles << article
end
box = Box.new
box.owner = profile
box.save!
@block = RecentDocumentsBlock.new
@block.box_id = box.id
@block.save!
end
attr_reader :block, :profile, :articles
should 'describe itself' do
assert_not_equal Block.description, RecentDocumentsBlock.description
end
should 'provide a default title' do
assert_not_equal Block.new.default_title, RecentDocumentsBlock.new.default_title
end
should 'list recent documents' do
assert_equivalent block.docs, articles
end
should 'respect the maximum number of items as configured' do
block.limit = 3
list = block.docs
assert_includes list, articles[4]
assert_includes list, articles[3]
assert_includes list, articles[2]
assert_not_includes list, articles[1]
assert_not_includes list, articles[0]
end
should 'store limit as a number' do
block.limit = ''
assert block.limit.is_a?(Fixnum)
end
should 'have a non-zero default' do
block.limit = nil
assert block.limit > 0
end
should 'be able to update display setting' do
assert @block.update!(:display => 'always')
@block.reload
assert_equal 'always', @block.display
end
should 'return the max value in the range between zero and limit' do
block = RecentDocumentsBlock.new
assert_equal 5, block.get_limit
end
should 'return 0 if limit of the block is negative' do
block = RecentDocumentsBlock.new
block.limit = -5
assert_equal 0, block.get_limit
end
end
require 'boxes_helper'
class RecentDocumentsBlockViewTest < ActionView::TestCase
include BoxesHelper
def setup
@articles = []
@profile = create_user('testinguser').person
@profile.articles.destroy_all
['first', 'second', 'third', 'fourth', 'fifth'].each do |name|
article = @profile.articles.create!(:name => name)
@articles << article
end
box = Box.new
box.owner = profile
box.save!
@block = RecentDocumentsBlock.new
@block.box_id = box.id
@block.save!
end
attr_reader :block, :profile, :articles
should 'link to documents' do
articles.each do |a|
ActionView::Base.any_instance.expects(:link_to).with(a.title, a.url)
end
ActionView::Base.any_instance.stubs(:block_title).returns("")
ActionView::Base.any_instance.stubs(:content_tag).returns("")
ActionView::Base.any_instance.stubs(:li).returns("")
render_block_content(block)
end
should 'display a link to sitemap with title "All content"' do
ActionView::Base.any_instance.expects(:link_to).with('All content', :controller => 'profile', :action => 'sitemap', :profile => profile.identifier)
ActionView::Base.any_instance.expects(:_).with('All content').returns('All content')
render_block_footer(block)
end
should 'not display link to sitemap when owner is environment' do
block = RecentDocumentsBlock.new
box = mock
block.expects(:box).returns(box).at_least_once
box.expects(:owner).returns(Environment.new).at_least_once
assert_equal '', render_block_footer(block)
end
end