Commit 086869c73898cf1c62b20096bf436ed8f421ab6d

Authored by Rafael Reggiani Manzo
1 parent 7bc3b2b3

Add tests for RecentContentBlock rendering

Those were not covered and were necessary in order to give confidence
about the previous refactor correctness.
plugins/recent_content/test/unit/recent_content_block_test.rb
... ... @@ -73,3 +73,73 @@ class RecentContentBlockTest < ActiveSupport::TestCase
73 73 end
74 74  
75 75 end
  76 +
  77 +require 'boxes_helper'
  78 +
  79 +class RecentContentBlockViewTest < ActionView::TestCase
  80 + include BoxesHelper
  81 +
  82 + should 'show the alert when the block has no root' do
  83 + block = RecentContentBlock.new
  84 +
  85 + block.expects(:root).returns(nil)
  86 +
  87 + content = render_block_content(block)
  88 +
  89 + assert_match /#{_('This is the recent content block. Please edit it to show the content you want.')}/, content
  90 + end
  91 +
  92 + should 'show the title and the child titles when the block has a root and is set to title only mode' do
  93 + profile = create_user('testuser').person
  94 +
  95 + root = fast_create(Blog, :name => 'test-blog', :profile_id => profile.id)
  96 +
  97 + block = RecentContentBlock.new
  98 + block.stubs(:holder).returns(profile)
  99 + block.selected_folder = root.id
  100 + block.presentation_mode = 'title_only'
  101 +
  102 + ActionView::Base.any_instance.expects(:block_title).returns("Block Title")
  103 + ActionView::Base.any_instance.expects(:profile).returns(profile)
  104 +
  105 + content = render_block_content(block)
  106 +
  107 + assert_match /Block Title/, content
  108 + end
  109 +
  110 + should 'show the title and the child titles and abstracts when the block has a root and is set to title and abstract mode' do
  111 + profile = create_user('testuser').person
  112 +
  113 + root = fast_create(Blog, :name => 'test-blog', :profile_id => profile.id)
  114 +
  115 + block = RecentContentBlock.new
  116 + block.stubs(:holder).returns(profile)
  117 + block.selected_folder = root.id
  118 + block.presentation_mode = 'title_and_abstract'
  119 +
  120 + ActionView::Base.any_instance.expects(:block_title).returns("Block Title")
  121 + ActionView::Base.any_instance.expects(:profile).returns(profile)
  122 +
  123 + content = render_block_content(block)
  124 +
  125 + assert_match /Block Title/, content
  126 + end
  127 +
  128 + should 'show the title and the child full content when the block has a root and has no mode set' do
  129 + profile = create_user('testuser').person
  130 +
  131 + root = fast_create(Blog, :name => 'test-blog', :profile_id => profile.id)
  132 +
  133 + block = RecentContentBlock.new
  134 + block.stubs(:holder).returns(profile)
  135 + block.selected_folder = root.id
  136 + block.presentation_mode = ''
  137 +
  138 + ActionView::Base.any_instance.expects(:block_title).returns("Block Title")
  139 + ActionView::Base.any_instance.expects(:profile).returns(profile)
  140 +
  141 + content = render_block_content(block)
  142 +
  143 + assert_match /Block Title/, content
  144 + end
  145 +end
... ...