From c09474f6d2f95bee7d632357fdaa1edb04195b23 Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Thu, 5 May 2016 09:35:13 -0300 Subject: [PATCH] Fix BreadcrumbsPlugin unit tests --- plugins/breadcrumbs/test/unit/breadcrumbs_plugin_helper_test.rb | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/breadcrumbs/test/unit/content_breadcrumbs_block_test.rb | 69 +++++++++++++-------------------------------------------------------- 2 files changed, 79 insertions(+), 56 deletions(-) create mode 100644 plugins/breadcrumbs/test/unit/breadcrumbs_plugin_helper_test.rb diff --git a/plugins/breadcrumbs/test/unit/breadcrumbs_plugin_helper_test.rb b/plugins/breadcrumbs/test/unit/breadcrumbs_plugin_helper_test.rb new file mode 100644 index 0000000..ff58b72 --- /dev/null +++ b/plugins/breadcrumbs/test/unit/breadcrumbs_plugin_helper_test.rb @@ -0,0 +1,66 @@ +require 'test_helper' + +class BreadcrumbsPluginHelperTest < ActionView::TestCase + include BreadcrumbsPluginHelper + + 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 '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, 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=>params, :name=>"Edit"}] + assert_equal links, trail(@block, nil, 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, trail(@block, nil, nil, params) + end + + should 'include profile page link on path of links to reach a profile controller page' do + params = {:controller => 'profile', :action => 'members', :profile => @profile.identifier} + links = [{:name => 'Profile', :url => {:controller => 'profile', :action => 'index', :profile => @profile.identifier}}, {:name => 'Members', :url => {:controller=>'profile', :action=>'members', :profile=> @profile.identifier}}] + assert_equal links, trail(@block, nil, nil, params) + end + + should 'include only the profile page link on path links when profile action is index' do + params = {:controller => 'profile', :action => 'index', :profile => @profile.identifier} + links = [{:name => 'Profile', :url => {:controller => 'profile', :action => 'index', :profile => @profile.identifier}}] + assert_equal links, trail(@block, nil, nil, params) + end + + should 'profile page be the ancestor page of event profile page calendar' do + params = {:controller => 'profile', :action => 'events', :profile => @profile.identifier} + links = [{:name => 'Profile', :url => {:controller => 'profile', :action => 'index', :profile => @profile.identifier}}, {:name => 'Events', :url => {:controller=>'profile', :action=>'events', :profile=> @profile.identifier}}] + assert_equal links, trail(@block, nil, 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, trail(@block, @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, trail(@block, @article, @profile) + end + + should 'not include profile link on path of links when trail is empty' do + assert_equal [], trail(@block, nil, @profile) + end +end diff --git a/plugins/breadcrumbs/test/unit/content_breadcrumbs_block_test.rb b/plugins/breadcrumbs/test/unit/content_breadcrumbs_block_test.rb index 2c4c88c..411cce7 100644 --- a/plugins/breadcrumbs/test/unit/content_breadcrumbs_block_test.rb +++ b/plugins/breadcrumbs/test/unit/content_breadcrumbs_block_test.rb @@ -6,14 +6,8 @@ class ContentBreadcrumbsBlockTest < ActiveSupport::TestCase 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 @@ -22,60 +16,28 @@ class ContentBreadcrumbsBlockTest < ActiveSupport::TestCase 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 page link on path of links to reach a profile controller page' do - params = {:controller => 'profile', :action => 'members', :profile => @profile.identifier} - links = [{:name => 'Profile', :url => {:controller => 'profile', :action => 'index', :profile => @profile.identifier}}, {:name => 'Members', :url => {:controller=>'profile', :action=>'members', :profile=> @profile.identifier}}] - assert_equal links, @block.page_trail(nil, params) - end - should 'include only the profile page link on path links when profile action is index' do - params = {:controller => 'profile', :action => 'index', :profile => @profile.identifier} - links = [{:name => 'Profile', :url => {:controller => 'profile', :action => 'index', :profile => @profile.identifier}}] - assert_equal links, @block.page_trail(nil, params) + should 'not be cacheable' do + refute @block.cacheable? end - should 'profile page be the ancestor page of event profile page calendar' do - params = {:controller => 'profile', :action => 'events', :profile => @profile.identifier} - links = [{:name => 'Profile', :url => {:controller => 'profile', :action => 'index', :profile => @profile.identifier}}, {:name => 'Events', :url => {:controller=>'profile', :action=>'events', :profile=> @profile.identifier}}] - assert_equal links, @block.page_trail(nil, params) - end +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 +require 'boxes_helper' - 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 +class ContentBreadcrumbsBlockViewTest < ActionView::TestCase + include BoxesHelper - should 'not include profile link on path of links when trail is empty' do - assert_equal [], @block.trail(nil, @profile) + 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) end should 'render trail if there is links to show' do @page = @article - trail = instance_eval(&@block.content) + trail = render_block_content(@block) assert_match /#{@profile.name}/, trail assert_match /#{@folder.name}/, trail assert_match /#{@page.name}/, trail @@ -83,11 +45,6 @@ class ContentBreadcrumbsBlockTest < ActiveSupport::TestCase 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 - refute @block.cacheable? + assert_equal "\n", render_block_content(@block) end - end -- libgit2 0.21.2