Commit f0c1c11aaddc79e2eb1f1fbbd5c7faf36d805f3e

Authored by Parley
Committed by Luciano Prestes
1 parent efb69e98

deactive_and_active_profile: Add functional tests to activate and deactivate profile.

(ActionItem3287)

Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com>
Signed-off-by: Fabio teixeira <fabio1079@gmail.com>
Signed-off-by: Parley Martins <parley@outlook.com>
app/controllers/my_profile/profile_editor_controller.rb
... ... @@ -90,7 +90,7 @@ class ProfileEditorController &lt; MyProfileController
90 90 end
91 91 end
92 92  
93   - redirect_to request.referer
  93 + redirect_to_previous_location
94 94 end
95 95  
96 96 def activate_profile
... ... @@ -104,6 +104,15 @@ class ProfileEditorController &lt; MyProfileController
104 104 end
105 105 end
106 106  
107   - redirect_to request.referer
  107 + redirect_to_previous_location
108 108 end
109   -end
  109 +
  110 + protected
  111 +
  112 + def redirect_to_previous_location
  113 + back = request.referer
  114 + back = "/" if back.nil?
  115 +
  116 + redirect_to back
  117 + end
  118 +end
110 119 \ No newline at end of file
... ...
test/functional/admin_panel_controller_test.rb
... ... @@ -383,4 +383,35 @@ class AdminPanelControllerTest &lt; ActionController::TestCase
383 383 assert !Environment.default.signup_welcome_screen_body.blank?
384 384 end
385 385  
  386 + should 'show list to deactivate organizations' do
  387 + enabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"enabled community")
  388 + disabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"disabled community")
  389 + user = create_user('user')
  390 +
  391 + disabled_community.disable
  392 +
  393 + Environment.default.add_admin user.person
  394 + login_as('user')
  395 +
  396 + get :manage_organizations_status, :filter=>"enabled"
  397 + assert_match(/Organization profiles - enabled/, @response.body)
  398 + assert_match(/enabled community/, @response.body)
  399 + assert_not_match(/disabled community/, @response.body)
  400 + end
  401 +
  402 + should 'show list to activate organizations' do
  403 + enabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"enabled community")
  404 + disabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"disabled community")
  405 + user = create_user('user')
  406 +
  407 + disabled_community.disable
  408 +
  409 + Environment.default.add_admin user.person
  410 + login_as('user')
  411 +
  412 + get :manage_organizations_status, :filter=>"disabled"
  413 + assert_match(/Organization profiles - disabled/, @response.body)
  414 + assert_not_match(/enabled community/, @response.body)
  415 + assert_match(/disabled community/, @response.body)
  416 + end
386 417 end
... ...
test/functional/profile_editor_controller_test.rb
... ... @@ -1091,4 +1091,39 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
1091 1091 get :index, :profile => user.identifier
1092 1092 assert_tag :tag => 'div', :descendant => { :tag => 'a', :content => 'Edit Header and Footer' }
1093 1093 end
  1094 +
  1095 + should 'deactivate organization profile' do
  1096 + @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status'
  1097 + user = create_user('user').person
  1098 + Environment.default.add_admin user
  1099 + login_as('user')
  1100 +
  1101 + community = fast_create(Community)
  1102 + get :index, :profile => community.identifier
  1103 + get :deactivate_profile, {:profile => community.identifier, :id => community.id}
  1104 + assert_equal @request.session[:notice], "The profile '#{community.name}' was disabled."
  1105 + end
  1106 +
  1107 + should 'activate organization profile' do
  1108 + @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status'
  1109 + user = create_user('user').person
  1110 + Environment.default.add_admin user
  1111 + login_as('user')
  1112 +
  1113 + community = fast_create(Community)
  1114 + get :index, :profile => community.identifier
  1115 + get :activate_profile, {:profile => community.identifier, :id => community.id}
  1116 + assert_equal @request.session[:notice], "The profile '#{community.name}' was activated."
  1117 + end
  1118 +
  1119 + should 'not deactivate organization profile if user is not an admin' do
  1120 + @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status'
  1121 + user = create_user('user').person
  1122 + login_as('user')
  1123 +
  1124 + community = fast_create(Community)
  1125 + get :index, :profile => community.identifier
  1126 + get :deactivate_profile, {:profile => community.identifier, :id => community.id}
  1127 + assert_not_equal @request.session[:notice], "The profile '#{community.name}' was disabled."
  1128 + end
1094 1129 end
... ...