communities_block_test.rb
2.07 KB
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
require File.dirname(__FILE__) + '/../test_helper'
class CommunitiesBlockTest < ActiveSupport::TestCase
  should 'inherit from ProfileListBlock' do
    assert_kind_of ProfileListBlock, CommunitiesBlock.new
  end
  should 'declare its default title' do
    CommunitiesBlock.any_instance.stubs(:profile_count).returns(0)
    assert_not_equal ProfileListBlock.new.default_title, CommunitiesBlock.new.default_title
  end
  should 'describe itself' do
    assert_not_equal ProfileListBlock.description, CommunitiesBlock.description
  end
  should 'list owner communities' do
    block = CommunitiesBlock.new
    owner = mock
    block.stubs(:owner).returns(owner)
    list = []
    owner.stubs(:communities).returns(list)
    assert_same list, block.profiles
  end
  should 'link to all communities of profile' do
    profile = Profile.new
    profile.expects(:identifier).returns("theprofile")
    block = CommunitiesBlock.new
    block.expects(:owner).returns(profile)
    expects(:link_to).with('View all', :controller => 'profile', :profile => 'theprofile', :action => 'communities')
    instance_eval(&block.footer)
  end
  should 'support environment as owner' do
    env = Environment.default
    block = CommunitiesBlock.new
    block.expects(:owner).returns(env)
    expects(:link_to).with('View all', :controller => "search", :action => 'communities')
    instance_eval(&block.footer)
  end
  should 'give empty footer on unsupported owner type' do
    block = CommunitiesBlock.new
    block.expects(:owner).returns(1)
    assert_equal '', block.footer
  end
  should 'list non-public communities' do
    user = create_user('testuser').person
    public_community = fast_create(Community, :environment_id => Environment.default.id)
    public_community.add_member(user)
    private_community = fast_create(Community, :environment_id => Environment.default.id, :public_profile => false)
    private_community.add_member(user)
    block = CommunitiesBlock.new
    block.expects(:owner).at_least_once.returns(user)
    assert_equivalent [public_community, private_community], block.profiles
  end
end