people_block_test.rb
2.47 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
73
74
75
require File.dirname(__FILE__) + '/../test_helper'
class PeopleBlockTest < ActiveSupport::TestCase
should 'inherit from ProfileListBlock' do
assert_kind_of ProfileListBlock, PeopleBlock.new
end
should 'declare its default title' do
assert_not_equal ProfileListBlock.new.default_title, PeopleBlock.new.default_title
end
should 'describe itself' do
assert_not_equal ProfileListBlock.description, PeopleBlock.description
end
should 'give help' do
assert_not_equal ProfileListBlock.new.help, PeopleBlock.new.help
end
should 'use its own finder' do
assert_not_equal ProfileListBlock::Finder, PeopleBlock::Finder
assert_kind_of PeopleBlock::Finder, PeopleBlock.new.profile_finder
end
should 'list people' do
owner = Environment.create!(:name => 'test environment')
block = PeopleBlock.new
block.expects(:owner).returns(owner).at_least_once
person1 = fast_create(Person, :environment_id => owner.id)
person2 = fast_create(Person, :environment_id => owner.id)
expects(:profile_image_link).with(person1).returns(person1.name)
expects(:profile_image_link).with(person2).returns(person2.name)
expects(:block_title).with(anything).returns('')
content = instance_eval(&block.content)
assert_match(/#{person1.name}/, content)
assert_match(/#{person2.name}/, content)
end
should 'link to people directory' do
block = PeopleBlock.new
block.stubs(:owner).returns(Environment.default)
expects(:_).with('View all').returns('View all people')
expects(:link_to).with('View all people', :controller => 'search', :action => 'assets', :asset => 'people')
instance_eval(&block.footer)
end
should 'count number of public and private people' do
env = Environment.create!(:name => 'test environment')
private_p = fast_create(Person, :environment_id => env.id, :public_profile => false)
public_p = fast_create(Person, :environment_id => env.id, :public_profile => true)
env.boxes.first.blocks << block = PeopleBlock.new
assert_equal 2, block.profile_count
end
should 'count number of visible people' do
env = Environment.create!(:name => 'test environment')
invisible_p = fast_create(Person, :environment_id => env.id, :visible => false)
visible_p = fast_create(Person, :environment_id => env.id, :visible => true)
env.boxes.first.blocks << block = PeopleBlock.new
assert_equal 1, block.profile_count
end
protected
def content_tag(tag, text, options = {})
text
end
end