Commit c09474f6d2f95bee7d632357fdaa1edb04195b23

Authored by Rafael Reggiani Manzo
1 parent de523447

Fix BreadcrumbsPlugin unit tests

After the refactor removing HTML generation from the Block subclass, the
tests were outdated.

The tests related to methods moved to the helper have been placed on its
own test file and adapted accordingly since the code has changed
slightly, but the assertions remained untouched (thus the refactor is
correct).

Finally block tests related to the view have been moved into a new view
test suite.
plugins/breadcrumbs/test/unit/breadcrumbs_plugin_helper_test.rb 0 → 100644
... ... @@ -0,0 +1,66 @@
  1 +require 'test_helper'
  2 +
  3 +class BreadcrumbsPluginHelperTest < ActionView::TestCase
  4 + include BreadcrumbsPluginHelper
  5 +
  6 + def setup
  7 + @block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.new
  8 + @profile = fast_create(Community)
  9 + @folder = fast_create(Folder, :profile_id => @profile.id)
  10 + @article = fast_create(Folder, :profile_id => @profile.id, :parent_id => @folder.id)
  11 + @params = {}
  12 + end
  13 +
  14 + attr_reader :params
  15 +
  16 + should 'return path of links to reach a page' do
  17 + links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}]
  18 + assert_equal links, page_trail(@article)
  19 + end
  20 +
  21 + should 'return path of links when current page is at cms controller' do
  22 + params = {:controller => 'cms', :action => 'edit', :id => @article.id}
  23 + links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}, {:url=>params, :name=>"Edit"}]
  24 + assert_equal links, trail(@block, nil, nil, params)
  25 + end
  26 +
  27 + should 'not return cms action link when show_cms_action is false' do
  28 + params = {:controller => 'cms', :action => 'edit', :id => @article.id}
  29 + links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}]
  30 + @block.show_cms_action = false
  31 + assert_equal links, trail(@block, nil, nil, params)
  32 + end
  33 +
  34 + should 'include profile page link on path of links to reach a profile controller page' do
  35 + params = {:controller => 'profile', :action => 'members', :profile => @profile.identifier}
  36 + links = [{:name => 'Profile', :url => {:controller => 'profile', :action => 'index', :profile => @profile.identifier}}, {:name => 'Members', :url => {:controller=>'profile', :action=>'members', :profile=> @profile.identifier}}]
  37 + assert_equal links, trail(@block, nil, nil, params)
  38 + end
  39 +
  40 + should 'include only the profile page link on path links when profile action is index' do
  41 + params = {:controller => 'profile', :action => 'index', :profile => @profile.identifier}
  42 + links = [{:name => 'Profile', :url => {:controller => 'profile', :action => 'index', :profile => @profile.identifier}}]
  43 + assert_equal links, trail(@block, nil, nil, params)
  44 + end
  45 +
  46 + should 'profile page be the ancestor page of event profile page calendar' do
  47 + params = {:controller => 'profile', :action => 'events', :profile => @profile.identifier}
  48 + links = [{:name => 'Profile', :url => {:controller => 'profile', :action => 'index', :profile => @profile.identifier}}, {:name => 'Events', :url => {:controller=>'profile', :action=>'events', :profile=> @profile.identifier}}]
  49 + assert_equal links, trail(@block, nil, nil, params)
  50 + end
  51 +
  52 + should 'include profile link on path of links to reach a page' do
  53 + links = [{:name => @profile.name, :url => @profile.url}, {:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}]
  54 + assert_equal links, trail(@block, @article, @profile)
  55 + end
  56 +
  57 + should 'not include profile link on path of links when show_profile is false' do
  58 + links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}]
  59 + @block.show_profile = false
  60 + assert_equal links, trail(@block, @article, @profile)
  61 + end
  62 +
  63 + should 'not include profile link on path of links when trail is empty' do
  64 + assert_equal [], trail(@block, nil, @profile)
  65 + end
  66 +end
... ...
plugins/breadcrumbs/test/unit/content_breadcrumbs_block_test.rb
... ... @@ -6,14 +6,8 @@ class ContentBreadcrumbsBlockTest &lt; ActiveSupport::TestCase
6 6  
7 7 def setup
8 8 @block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.new
9   - @profile = fast_create(Community)
10   - @folder = fast_create(Folder, :profile_id => @profile.id)
11   - @article = fast_create(Folder, :profile_id => @profile.id, :parent_id => @folder.id)
12   - @params = {}
13 9 end
14 10  
15   - attr_reader :params
16   -
17 11 should 'has a description' do
18 12 assert_not_equal Block.description, BreadcrumbsPlugin::ContentBreadcrumbsBlock.description
19 13 end
... ... @@ -22,60 +16,28 @@ class ContentBreadcrumbsBlockTest &lt; ActiveSupport::TestCase
22 16 assert @block.help
23 17 end
24 18  
25   - should 'return path of links to reach a page' do
26   - links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}]
27   - assert_equal links, @block.page_trail(@article)
28   - end
29   -
30   - should 'return path of links when current page is at cms controller' do
31   - params = {:controller => 'cms', :action => 'edit', :id => @article.id}
32   - links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}, {:url=>{:controller=>"cms", :action=>"edit", :id=>@article.id}, :name=>"Edit"}]
33   - assert_equal links, @block.page_trail(nil, params)
34   - end
35   -
36   - should 'not return cms action link when show_cms_action is false' do
37   - params = {:controller => 'cms', :action => 'edit', :id => @article.id}
38   - links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}]
39   - @block.show_cms_action = false
40   - assert_equal links, @block.page_trail(nil, params)
41   - end
42   -
43   - should 'include profile page link on path of links to reach a profile controller page' do
44   - params = {:controller => 'profile', :action => 'members', :profile => @profile.identifier}
45   - links = [{:name => 'Profile', :url => {:controller => 'profile', :action => 'index', :profile => @profile.identifier}}, {:name => 'Members', :url => {:controller=>'profile', :action=>'members', :profile=> @profile.identifier}}]
46   - assert_equal links, @block.page_trail(nil, params)
47   - end
48 19  
49   - should 'include only the profile page link on path links when profile action is index' do
50   - params = {:controller => 'profile', :action => 'index', :profile => @profile.identifier}
51   - links = [{:name => 'Profile', :url => {:controller => 'profile', :action => 'index', :profile => @profile.identifier}}]
52   - assert_equal links, @block.page_trail(nil, params)
  20 + should 'not be cacheable' do
  21 + refute @block.cacheable?
53 22 end
54 23  
55   - should 'profile page be the ancestor page of event profile page calendar' do
56   - params = {:controller => 'profile', :action => 'events', :profile => @profile.identifier}
57   - links = [{:name => 'Profile', :url => {:controller => 'profile', :action => 'index', :profile => @profile.identifier}}, {:name => 'Events', :url => {:controller=>'profile', :action=>'events', :profile=> @profile.identifier}}]
58   - assert_equal links, @block.page_trail(nil, params)
59   - end
  24 +end
60 25  
61   - should 'include profile link on path of links to reach a page' do
62   - links = [{:name => @profile.name, :url => @profile.url}, {:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}]
63   - assert_equal links, @block.trail(@article, @profile)
64   - end
  26 +require 'boxes_helper'
65 27  
66   - should 'not include profile link on path of links when show_profile is false' do
67   - links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}]
68   - @block.show_profile = false
69   - assert_equal links, @block.trail(@article, @profile)
70   - end
  28 +class ContentBreadcrumbsBlockViewTest < ActionView::TestCase
  29 + include BoxesHelper
71 30  
72   - should 'not include profile link on path of links when trail is empty' do
73   - assert_equal [], @block.trail(nil, @profile)
  31 + def setup
  32 + @block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.new
  33 + @profile = fast_create(Community)
  34 + @folder = fast_create(Folder, :profile_id => @profile.id)
  35 + @article = fast_create(Folder, :profile_id => @profile.id, :parent_id => @folder.id)
74 36 end
75 37  
76 38 should 'render trail if there is links to show' do
77 39 @page = @article
78   - trail = instance_eval(&@block.content)
  40 + trail = render_block_content(@block)
79 41 assert_match /#{@profile.name}/, trail
80 42 assert_match /#{@folder.name}/, trail
81 43 assert_match /#{@page.name}/, trail
... ... @@ -83,11 +45,6 @@ class ContentBreadcrumbsBlockTest &lt; ActiveSupport::TestCase
83 45  
84 46 should 'render nothing if there is no links to show' do
85 47 @page = nil
86   - assert_equal '', instance_eval(&@block.content)
87   - end
88   -
89   - should 'not be cacheable' do
90   - refute @block.cacheable?
  48 + assert_equal "\n", render_block_content(@block)
91 49 end
92   -
93 50 end
... ...