enterprise_editor_controller_test.rb
3.17 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
require File.dirname(__FILE__) + '/../test_helper'
require 'enterprise_editor_controller'
# Re-raise errors caught by the controller.
class EnterpriseEditorController; def rescue_action(e) raise e end; end
class EnterpriseEditorControllerTest < Test::Unit::TestCase
def setup
@controller = EnterpriseEditorController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_local_files_reference
user = create_user('test_user').person
assert_local_files_reference :get, :index, :profile => user.identifier
end
def test_valid_xhtml
assert_valid_xhtml
end
should 'not see index if do not logged in' do
ent1 = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1')
get 'index', :profile => 'test_enterprise1'
assert_response 403
assert_template 'access_denied.rhtml'
end
should 'not see index if do not have permission to edit profile' do
user = create_user('test_user')
ent = Enterprise.create!(:identifier => 'test_enterprise', :name => 'Test enteprise')
login_as :test_user
get 'index', :profile => 'test_enterprise'
assert_response 403
assert @controller.send(:profile)
assert_equal ent.identifier, @controller.send(:profile).identifier
assert_template 'access_denied.rhtml'
end
should 'see index if have permission' do
ent = Enterprise.create!(:identifier => 'test_enterprise', :name => 'Test enterprise')
user = create_user('test_user').person
role = Role.create!(:name => 'test_role', :permissions => ['edit_profile'])
assert user.add_role(role, ent)
assert user.has_permission?('edit_profile', ent)
login_as :test_user
assert_equal ent, Profile.find_by_identifier('test_enterprise')
get 'index', :profile => 'test_enterprise'
assert_response :success
assert_equal ent, @controller.send(:profile)
assert_equal user, @controller.send(:user)
assert_template 'index'
end
should 'show the edit form' do
ent = Enterprise.create!(:identifier => 'test_enterprise', :name => 'Test enterprise')
user = create_user_with_permission('test_user', 'edit_profile', ent)
login_as :test_user
get 'edit', :profile => 'test_enterprise'
assert_response :success
assert_equal ent, @controller.send(:profile)
assert_template 'edit'
end
should 'update' do
ent = Enterprise.create!(:identifier => 'test_enterprise', :name => 'Test enterprise')
user = create_user_with_permission('test_user', 'edit_profile', ent)
login_as :test_user
post 'update', :profile => 'test_enterprise', :organization_info => {:acronym => 'bla'}
assert_response :redirect
assert_redirected_to :action => 'index'
ent.reload
assert_equal 'bla', ent.organization_info.acronym
end
should 'destroy' do
ent = Enterprise.create!(:identifier => 'test_enterprise', :name => 'Test enterprise')
user = create_user_with_permission('test_user', 'destroy_profile', ent)
login_as :test_user
post 'destroy', :profile => 'test_enterprise'
assert_response :redirect
assert_redirected_to :controller => 'profile_editor', :profile => 'test_user'
end
end