external_person_test.rb
3.99 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# encoding: UTF-8
require_relative "../test_helper"
class ExternalPersonTest < ActiveSupport::TestCase
fixtures :environments
def setup
@external_person = ExternalPerson.create!(identifier: 'johnlock',
name: 'John Lock',
source: 'anerenvironment.org',
email: 'john@lock.org',
created_at: Date.yesterday
)
end
should 'have no permissions' do
assert_equivalent [], @external_person.role_assignments
refute @external_person.has_permission?(:manage_friends)
end
should 'have no suggested profiles' do
assert_equivalent [], @external_person.suggested_communities
assert_equivalent [], @external_person.suggested_people
assert_equivalent [], @external_person.suggested_profiles
end
should 'have no friendships' do
refute @external_person.add_friend(fast_create(Person))
assert_equivalent [], @external_person.friendships
end
should 'not be a member of any communities' do
community = fast_create(Community)
refute community.add_member(@external_person)
assert_equivalent [], @external_person.memberships
end
should 'not have any favorite enterprises' do
assert_equivalent [], @external_person.favorite_enterprises
end
should 'be a person' do
assert @external_person.person?
end
should 'not be a community, organization or enterprise' do
refute @external_person.community?
refute @external_person.enterprise?
refute @external_person.organization?
end
should 'never be an admin for environments' do
refute @external_person.is_admin?
env = Environment.default
env.add_admin @external_person
refute @external_person.is_admin?(env)
assert_equivalent [], env.admins
end
should 'redirect after login based on environment settings' do
assert_respond_to ExternalPerson.new, :preferred_login_redirection
environment = fast_create(Environment, :redirection_after_login => 'site_homepage')
profile = fast_create(ExternalPerson, :environment_id => environment.id)
assert_equal 'site_homepage', profile.preferred_login_redirection
end
should 'have an avatar from its original environment' do
assert_match(/http:\/\/#{@external_person.source}\/.*/, @external_person.avatar)
end
should 'generate a custom profile icon based on its avatar' do
skip
end
should 'have an url to its profile on its original environment' do
skip
end
should 'have a public profile url' do
skip
end
should 'have an admin url to its profile on its original environment' do
skip
end
should 'never be a friend of another person' do
skip
end
should 'never send a friend request to another person' do
skip
end
should 'not follow another profile' do
skip
end
should 'have an image' do
skip
end
should 'profile image has public filename and mimetype' do
skip
end
should 'respond to all instance methods in Profile' do
methods = Profile.public_instance_methods(false)
methods.each do |method|
# We test if ExternalPerson responds to same methods as Profile, but we
# skip methods generated by plugins, libs and validations, which are
# usually only used internally
assert_respond_to ExternalPerson.new, method.to_sym unless method =~ /type_name|^autosave_.*|^after_.*|^before_.*|validate_.*|^attribute_.*|.*_?tags?_?.*|^custom_value.*|^custom_context.*|^xss.*|bar/
end
end
should 'respond to all instance methods in Person' do
methods = Person.public_instance_methods(false)
methods.each do |method|
# We test if ExternalPerson responds to same methods as Person, but we
# skip methods generated by plugins, libs and validations, which are
# usually only used internally
assert_respond_to ExternalPerson.new, method.to_sym unless method =~ /^autosave_.*|validate_.*|^before_.*|^after_.*|^assignment_.*|^(city|state)_.*/
end
end
end