person_api_test.rb
3.49 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
require File.dirname(__FILE__) + '/../../../../test/test_helper'
class StoaPlugin::PersonApiTest < ActiveSupport::TestCase
def setup
@person = create_user('sample-user').person
end
attr_accessor :person
should 'provide nusp' do
person.usp_id = '99999999'
api = StoaPlugin::PersonApi.new(person)
assert_equal person.usp_id, api.nusp
end
should 'provide username' do
api = StoaPlugin::PersonApi.new(person)
assert_equal person.user.login, api.username
end
should 'provide first_name' do
person.name = "Jean-Luc Picard"
api = StoaPlugin::PersonApi.new(person)
assert_equal 'Jean-Luc', api.first_name
end
should 'provide surname' do
person.name = "Jean-Luc Picard"
api = StoaPlugin::PersonApi.new(person)
assert_equal 'Picard', api.surname
end
should 'provide homepage' do
api = StoaPlugin::PersonApi.new(person, self)
homepage = 'picard.me'
self.stubs(:url_for).with(person.url).returns(homepage)
assert_equal homepage, api.homepage
end
should 'provide image on base64' do
person.image_builder = {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}
person.save!
api = StoaPlugin::PersonApi.new(person)
assert_equal Base64.encode64(person.image.current_data), api.image_base64
end
should 'not crash on image_base64 if profile has no image' do
api = StoaPlugin::PersonApi.new(person)
assert_equal nil, api.image_base64
end
should 'provide tags' do
create_article_with_tags(person.id, 'free_software, noosfero, linux')
create_article_with_tags(person.id, 'free_software, linux')
create_article_with_tags(person.id, 'free_software')
api = StoaPlugin::PersonApi.new(person)
assert_equal person.article_tags, api.tags
end
should 'provide tags limited by 10 most relevant' do
13.times {create_article_with_tags(person.id, 'a')}
12.times {create_article_with_tags(person.id, 'b')}
11.times {create_article_with_tags(person.id, 'c')}
10.times {create_article_with_tags(person.id, 'd')}
9.times {create_article_with_tags(person.id, 'e')}
8.times {create_article_with_tags(person.id, 'f')}
7.times {create_article_with_tags(person.id, 'g')}
6.times {create_article_with_tags(person.id, 'h')}
5.times {create_article_with_tags(person.id, 'i')}
4.times {create_article_with_tags(person.id, 'j')}
3.times {create_article_with_tags(person.id, 'l')}
2.times {create_article_with_tags(person.id, 'm')}
1.times {create_article_with_tags(person.id, 'n')}
api = StoaPlugin::PersonApi.new(person)
tags = api.tags
assert_equal 10, tags.size
assert tags['a']
assert tags['b']
assert tags['c']
assert tags['d']
assert tags['e']
assert tags['f']
assert tags['g']
assert tags['h']
assert tags['i']
assert tags['j']
assert_nil tags['l']
assert_nil tags['m']
assert_nil tags['n']
end
should 'not provide information of private articles tags' do
create_article_with_tags(person.id, 'free_software, noosfero, linux', {:published => false})
create_article_with_tags(person.id, 'free_software, linux')
create_article_with_tags(person.id, 'free_software')
api = StoaPlugin::PersonApi.new(person)
assert !api.tags.has_key?('noosfero')
end
private
def create_article_with_tags(profile_id, tags = '', options = {})
article = fast_create(Article, options.merge(:profile_id => profile_id))
article.tag_list = tags
article.save!
article
end
end