enterprise_editor_controller_test.rb
1.65 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
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
should 'not see index if do not logged in' do
ent = Enterprise.create!(:identifier => 'test_enterprise', :name => 'Test enteprise')
get 'index', :profile => 'test_enterprise'
assert_response :success
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 :success
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
user = create_user('test_user').person
ent = Enterprise.create!(:identifier => 'test_enterprise', :name => 'Test enterprise')
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
get 'index', :profile => 'test_enterprise'
assert_response :success
assert @controller.send(:profile)
assert_template 'index'
end
end