<commit_before>require File.dirname(__FILE__) + '/../test_helper'

class FavoriteEnterprisesBlockTest < ActiveSupport::TestCase
  
  should 'inherit from ProfileListBlock' do
    assert_kind_of ProfileListBlock, FavoriteEnterprisesBlock.new
  end

  should 'declare its default title' do
    assert_not_equal ProfileListBlock.new.default_title, FavoriteEnterprisesBlock.new.default_title
  end

  should 'describe itself' do
    assert_not_equal ProfileListBlock.description, FavoriteEnterprisesBlock.description
  end

  should 'use its own finder' do
    assert_not_equal FavoriteEnterprisesBlock::Finder, ProfileListBlock::Finder
    assert_kind_of FavoriteEnterprisesBlock::Finder, FavoriteEnterprisesBlock.new.profile_finder
  end

  should 'list owner favorite enterprises' do

    block = FavoriteEnterprisesBlock.new
    block.limit = 2

    owner = mock
    block.expects(:owner).returns(owner)

    member1 = mock; member1.stubs(:id).returns(1)
    member2 = mock; member2.stubs(:id).returns(2)
    member3 = mock; member3.stubs(:id).returns(3)

    owner.expects(:favorite_enterprises).returns([member1, member2, member3])
    
    block.profile_finder.expects(:pick_random).with(3).returns(2)
    block.profile_finder.expects(:pick_random).with(2).returns(0)

    Profile.expects(:find).with(3).returns(member3)
    Profile.expects(:find).with(1).returns(member1)

    assert_equal [member3, member1], block.profiles
  end

  should 'link to all enterprises for person' do
    person = Person.new
    person.expects(:identifier).returns('theprofile')
    block = FavoriteEnterprisesBlock.new
    block.expects(:owner).returns(person)

    expects(:_).with('All favorite enterprises').returns('All enterprises')
    expects(:link_to).with('All enterprises', :controller => 'profile', :profile => 'theprofile', :action => 'favorite_enterprises')

    instance_eval(&block.footer)
  end

  should 'give empty footer for unsupported owner type' do
    block = FavoriteEnterprisesBlock.new
    block.expects(:owner).returns(1)
    assert_equal '', block.footer
  end

end<commit_msg>ActionItem523: mocking the right methods<commit_after>require File.dirname(__FILE__) + '/../test_helper'

class FavoriteEnterprisesBlockTest < ActiveSupport::TestCase
  
  should 'inherit from ProfileListBlock' do
    assert_kind_of ProfileListBlock, FavoriteEnterprisesBlock.new
  end

  should 'declare its default title' do
    assert_not_equal ProfileListBlock.new.default_title, FavoriteEnterprisesBlock.new.default_title
  end

  should 'describe itself' do
    assert_not_equal ProfileListBlock.description, FavoriteEnterprisesBlock.description
  end

  should 'use its own finder' do
    assert_not_equal FavoriteEnterprisesBlock::Finder, ProfileListBlock::Finder
    assert_kind_of FavoriteEnterprisesBlock::Finder, FavoriteEnterprisesBlock.new.profile_finder
  end

  should 'list owner favorite enterprises' do

    block = FavoriteEnterprisesBlock.new
    block.limit = 2

    owner = mock
    block.expects(:owner).returns(owner)

    member1 = mock; member1.stubs(:id).returns(1)
    member2 = mock; member2.stubs(:id).returns(2)
    member3 = mock; member3.stubs(:id).returns(3)

    owner.expects(:favorite_enterprises).returns([member1, member2, member3])
    
    block.profile_finder.expects(:pick_random).with(3).returns(2)
    block.profile_finder.expects(:pick_random).with(2).returns(0)

    Profile.expects(:find).with(3).returns(member3)
    Profile.expects(:find).with(1).returns(member1)

    assert_equal [member3, member1], block.profiles
  end

  should 'link to all enterprises for person' do
    person = Person.new
    person.expects(:identifier).returns('theprofile')
    block = FavoriteEnterprisesBlock.new
    block.expects(:owner).returns(person)

    expects(:__).with('All favorite enterprises').returns('All enterprises')
    expects(:link_to).with('All enterprises', :controller => 'profile', :profile => 'theprofile', :action => 'favorite_enterprises')

    instance_eval(&block.footer)
  end

  should 'give empty footer for unsupported owner type' do
    block = FavoriteEnterprisesBlock.new
    block.expects(:owner).returns(1)
    assert_equal '', block.footer
  end

end
{'fraction_non_alphanumeric': 0.10622623574144487, 'fraction_numerical': 0.01211977186311787, 'mean_word_length': 4.8539638386648125, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3739032', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1229, 'n_words': 251}