Commit 588fa3fc336a9e08a9103f8ea49b8dca1e0dd56d
1 parent
2585996c
Exists in
master
and in
28 other branches
ActionItem114: added some unit tests to cover more code
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@828 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
39 additions
and
5 deletions
Show diff stats
app/controllers/profile_admin/membership_editor_controller.rb
... | ... | @@ -7,7 +7,7 @@ class MembershipEditorController < ProfileAdminController |
7 | 7 | protect [:index, :new_enterprise, :create_enterprise ], 'edit_profile', :profile |
8 | 8 | |
9 | 9 | def index |
10 | - @memberships = current_user.person.enterprises_memberships | |
10 | + @memberships = current_user.person.enterprise_memberships | |
11 | 11 | end |
12 | 12 | |
13 | 13 | def new_enterprise | ... | ... |
app/models/person.rb
test/test_helper.rb
... | ... | @@ -71,6 +71,13 @@ class Test::Unit::TestCase |
71 | 71 | admin_user.login |
72 | 72 | end |
73 | 73 | |
74 | + def create_user(name) | |
75 | + User.create!(:login => name, | |
76 | + :email => name + '@noosfero.org', | |
77 | + :password => name.underscore, | |
78 | + :password_confirmation => name.underscore) | |
79 | + end | |
80 | + | |
74 | 81 | private |
75 | 82 | |
76 | 83 | def uses_host(name) | ... | ... |
test/unit/person_test.rb
... | ... | @@ -30,6 +30,7 @@ class PersonTest < Test::Unit::TestCase |
30 | 30 | member_role = Role.create(:name => 'member') |
31 | 31 | e.affiliate(p, member_role) |
32 | 32 | assert p.memberships.include?(e) |
33 | + assert p.enterprise_memberships.include?(e) | |
33 | 34 | end |
34 | 35 | |
35 | 36 | def test_can_have_user |
... | ... | @@ -97,4 +98,14 @@ class PersonTest < Test::Unit::TestCase |
97 | 98 | assert_nil p.email |
98 | 99 | end |
99 | 100 | |
101 | + should 'be an admin if have permission of environment administration' do | |
102 | + role = Role.create!(:name => 'just_another_admin_role') | |
103 | + env = Environment.create!(:name => 'blah') | |
104 | + person = create_user('just_another_person').person | |
105 | + env.affiliate(person, role) | |
106 | + assert ! person.is_admin? | |
107 | + role.update_attributes(:permissions => ['view_environment_admin_panel']) | |
108 | + person.reload | |
109 | + assert person.is_admin? | |
110 | + end | |
100 | 111 | end | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -40,9 +40,9 @@ class ProfileTest < Test::Unit::TestCase |
40 | 40 | end |
41 | 41 | |
42 | 42 | def test_cannot_rename |
43 | - p1 = profiles(:johndoe) | |
43 | + assert_valid p = Profile.create(:name => 'new_profile', :identifier => 'new_profile') | |
44 | 44 | assert_raise ArgumentError do |
45 | - p1.identifier = 'bli' | |
45 | + p.identifier = 'other_profile' | |
46 | 46 | end |
47 | 47 | end |
48 | 48 | |
... | ... | @@ -151,6 +151,23 @@ class ProfileTest < Test::Unit::TestCase |
151 | 151 | assert_equal 'testprofile@example.com', p.contact_email |
152 | 152 | end |
153 | 153 | |
154 | + should 'affiliate and provide a list of the affiliated users' do | |
155 | + profile = Profile.create!(:name => 'Profile for testing ', :identifier => 'profilefortesting') | |
156 | + person = create_user('test_user').person | |
157 | + role = Role.create!(:name => 'just_another_test_role') | |
158 | + assert profile.affiliate(person, role) | |
159 | + assert profile.members.map(&:id).include?(person.id) | |
160 | + end | |
161 | + | |
162 | + should 'authorize users that have permission on the environment' do | |
163 | + env = Environment.create!(:name => 'test_env') | |
164 | + profile = Profile.create!(:name => 'Profile for testing ', :identifier => 'profilefortesting', :environment => env) | |
165 | + person = create_user('test_user').person | |
166 | + role = Role.create!(:name => 'just_another_test_role', :permissions => ['edit_profile']) | |
167 | + assert env.affiliate(person, role) | |
168 | + assert person.has_permission?('edit_profile', profile) | |
169 | + end | |
170 | + | |
154 | 171 | private |
155 | 172 | |
156 | 173 | def assert_invalid_identifier(id) |
... | ... | @@ -158,5 +175,4 @@ class ProfileTest < Test::Unit::TestCase |
158 | 175 | assert !profile.valid? |
159 | 176 | assert profile.errors.invalid?(:identifier) |
160 | 177 | end |
161 | - | |
162 | 178 | end | ... | ... |