content_breadcrumbs_block_test.rb
2.7 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
require File.dirname(__FILE__) + '/../test_helper'
class ContentBreadcrumbsBlockTest < ActiveSupport::TestCase
include NoosferoTestHelper
def setup
@block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.new
@profile = fast_create(Community)
@folder = fast_create(Folder, :profile_id => @profile.id)
@article = fast_create(Folder, :profile_id => @profile.id, :parent_id => @folder.id)
@params = {}
end
attr_reader :params
should 'has a description' do
assert_not_equal Block.description, BreadcrumbsPlugin::ContentBreadcrumbsBlock.description
end
should 'has a help' do
assert @block.help
end
should 'return path of links to reach a page' do
links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}]
assert_equal links, @block.page_trail(@article)
end
should 'return path of links when current page is at cms controller' do
params = {:controller => 'cms', :action => 'edit', :id => @article.id}
links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}, {:url=>{:controller=>"cms", :action=>"edit", :id=>@article.id}, :name=>"Edit"}]
assert_equal links, @block.page_trail(nil, params)
end
should 'not return cms action link when show_cms_action is false' do
params = {:controller => 'cms', :action => 'edit', :id => @article.id}
links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}]
@block.show_cms_action = false
assert_equal links, @block.page_trail(nil, params)
end
should 'include profile link on path of links to reach a page' do
links = [{:name => @profile.name, :url => @profile.url}, {:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}]
assert_equal links, @block.trail(@article, @profile)
end
should 'not include profile link on path of links when show_profile is false' do
links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}]
@block.show_profile = false
assert_equal links, @block.trail(@article, @profile)
end
should 'not include profile link on path of links when trail is empty' do
assert_equal [], @block.trail(nil, @profile)
end
should 'render trail if there is links to show' do
@page = @article
trail = instance_eval(&@block.content)
assert_match /#{@profile.name}/, trail
assert_match /#{@folder.name}/, trail
assert_match /#{@page.name}/, trail
end
should 'render nothing if there is no links to show' do
@page = nil
assert_equal '', instance_eval(&@block.content)
end
should 'not be cacheable' do
assert !@block.cacheable?
end
end