organizations_controller_test.rb
3.83 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
require_relative "../test_helper"
require 'organizations_controller'
# Re-raise errors caught by the controller.
class OrganizationsController; def rescue_action(e) raise e end; end
class OrganizationsControllerTest < ActionController::TestCase
def setup
@controller = OrganizationsController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
Environment.destroy_all
@environment = fast_create(Environment, :is_default => true)
admin_user = create_user_with_permission('adminuser', 'manage_environment_organizations', environment)
login_as('adminuser')
end
attr_accessor :environment
should 'not access without right permission' do
create_user('guest')
login_as 'guest'
get :index
assert_response 403 # forbidden
end
should 'grant access with right permission' do
get :index
assert_response :success
end
should 'show list to deactivate organizations' do
enabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"enabled community")
disabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"disabled community")
disabled_community.disable
get :index, :filter => 'enabled'
assert_match(/enabled community/, @response.body)
assert_not_match(/disabled community/, @response.body)
end
should 'show list to activate organizations' do
enabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"enabled community")
disabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"disabled community")
disabled_community.disable
get :index, :filter => 'disabled'
assert_not_match(/enabled community/, @response.body)
assert_match(/disabled community/, @response.body)
end
should 'show list only of enterprises' do
community = fast_create(Community, :environment_id => Environment.default, :name=>"Community Test")
enterprise = fast_create(Enterprise, :environment_id => Environment.default, :name=>"Enterprise Test")
get :index, :type => 'Enterprise'
assert_match(/Enterprise Test/, @response.body)
assert_not_match(/Community Test/, @response.body)
end
should 'show list only of communities' do
community = fast_create(Community, :environment_id => Environment.default, :name=>"Community Test")
enterprise = fast_create(Enterprise, :environment_id => Environment.default, :name=>"Enterprise Test")
get :index, :type => 'Community'
assert_not_match(/Enterprise Test/, @response.body)
assert_match(/Community Test/, @response.body)
end
should 'show list all organizations' do
community = fast_create(Community, :environment_id => Environment.default, :name=>"Community Test")
enterprise = fast_create(Enterprise, :environment_id => Environment.default, :name=>"Enterprise Test")
get :index, :type => 'any'
assert_match(/Enterprise Test/, @response.body)
assert_match(/Community Test/, @response.body)
end
should 'activate organization profile' do
organization = fast_create(Organization, :visible => false, :environment_id => environment.id)
assert !organization.visible?
get :activate, {:id => organization.id}
organization.reload
assert organization.visible
end
should 'deactivate organization profile' do
organization = fast_create(Organization, :visible => true, :environment_id => environment.id)
assert organization.visible
get :deactivate, {:id => organization.id}
organization.reload
assert !organization.visible
end
should 'destroy organization profile' do
organization = fast_create(Organization, :environment_id => environment.id)
post :destroy, {:id => organization.id}
assert_raise ActiveRecord::RecordNotFound do
organization.reload
end
end
end