ref: master
plugins/profile_members_headlines/test/unit/profile_members_headlines_block_test.rb
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 |
require 'test_helper' require 'boxes_helper' class ProfileMembersHeadlinesBlockTest < ActiveSupport::TestCase include Noosfero::Plugin::HotSpot include BoxesHelper def setup @environment = fast_create(Environment) @environment.enable_plugin(ProfileMembersHeadlinesPlugin) @member1 = fast_create(Person) @member2 = fast_create(Person) @community = fast_create(Community) community.add_member member1 community.add_member member2 end attr_accessor :environment, :community, :member1, :member2 should 'inherit from Block' do assert_kind_of Block, ProfileMembersHeadlinesBlock.new end should 'describe itself' do assert_not_equal Block.description, ProfileMembersHeadlinesBlock.description end should 'provide a default title' do assert_not_equal Block.new.default_title, ProfileMembersHeadlinesBlock.new.default_title end should 'not have authors if they have no blog' do block = ProfileMembersHeadlinesBlock.create block.stubs(:owner).returns(community) self.expects(:render).with(:template => 'blocks/profile_members_headlines', :locals => { :block => block }).returns('file-without-authors-and-headlines') assert_equal 'file-without-authors-and-headlines', render_block_content(block) end should 'display headlines file' do block = ProfileMembersHeadlinesBlock.create block.stubs(:owner).returns(community) blog = fast_create(Blog, :profile_id => member1.id) post = fast_create(TextArticle, :name => 'headlines', :profile_id => member1.id, :parent_id => blog.id) self.expects(:render).with(:template => 'blocks/profile_members_headlines', :locals => { :block => block }).returns('file-with-authors-and-headlines') assert_equal 'file-with-authors-and-headlines', render_block_content(block) end should 'select only authors with articles and selected roles to display' do role = Role.create!(:name => 'role1') community.affiliate(member1, role) block = ProfileMembersHeadlinesBlock.new(:limit => 1, :filtered_roles => [role.id]) block.expects(:owner).returns(community) blog = fast_create(Blog, :profile_id => member1.id) post = fast_create(TextArticle, :name => 'headlines', :profile_id => member1.id, :parent_id => blog.id) assert_equal [member1], block.authors_list end should 'not select private authors to display' do block = ProfileMembersHeadlinesBlock.new(:limit => 1) block.expects(:owner).returns(community) private_author = fast_create(Person, :public_profile => false) blog = fast_create(Blog, :profile_id => private_author.id) post = fast_create(TextArticle, :name => 'headlines', :profile_id => private_author.id, :parent_id => blog.id) assert_equal [], block.authors_list end should 'filter authors by roles to display' do role = Role.create!(:name => 'role1') author = fast_create(Person) community.affiliate(author, role) block = ProfileMembersHeadlinesBlock.new(:limit => 3, :filtered_roles => [role.id]) block.stubs(:owner).returns(community) community.members.each do |member| blog = fast_create(Blog, :profile_id => member.id) post = fast_create(TextArticle, :name => 'headlines', :profile_id => member.id, :parent_id => blog.id) end assert_equal [author], block.authors_list end end |