From f0c1c11aaddc79e2eb1f1fbbd5c7faf36d805f3e Mon Sep 17 00:00:00 2001 From: ParleyMartins Date: Tue, 2 Sep 2014 15:02:59 +0000 Subject: [PATCH] deactive_and_active_profile: Add functional tests to activate and deactivate profile. --- app/controllers/my_profile/profile_editor_controller.rb | 15 ++++++++++++--- test/functional/admin_panel_controller_test.rb | 31 +++++++++++++++++++++++++++++++ test/functional/profile_editor_controller_test.rb | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/app/controllers/my_profile/profile_editor_controller.rb b/app/controllers/my_profile/profile_editor_controller.rb index cf57ccf..9798ab5 100644 --- a/app/controllers/my_profile/profile_editor_controller.rb +++ b/app/controllers/my_profile/profile_editor_controller.rb @@ -90,7 +90,7 @@ class ProfileEditorController < MyProfileController end end - redirect_to request.referer + redirect_to_previous_location end def activate_profile @@ -104,6 +104,15 @@ class ProfileEditorController < MyProfileController end end - redirect_to request.referer + redirect_to_previous_location end -end + + protected + + def redirect_to_previous_location + back = request.referer + back = "/" if back.nil? + + redirect_to back + end +end \ No newline at end of file diff --git a/test/functional/admin_panel_controller_test.rb b/test/functional/admin_panel_controller_test.rb index 55db96c..2d5d135 100644 --- a/test/functional/admin_panel_controller_test.rb +++ b/test/functional/admin_panel_controller_test.rb @@ -383,4 +383,35 @@ class AdminPanelControllerTest < ActionController::TestCase assert !Environment.default.signup_welcome_screen_body.blank? 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") + user = create_user('user') + + disabled_community.disable + + Environment.default.add_admin user.person + login_as('user') + + get :manage_organizations_status, :filter=>"enabled" + assert_match(/Organization profiles - enabled/, @response.body) + 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") + user = create_user('user') + + disabled_community.disable + + Environment.default.add_admin user.person + login_as('user') + + get :manage_organizations_status, :filter=>"disabled" + assert_match(/Organization profiles - disabled/, @response.body) + assert_not_match(/enabled community/, @response.body) + assert_match(/disabled community/, @response.body) + end end diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index 9ac5aab..c47a900 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -1091,4 +1091,39 @@ class ProfileEditorControllerTest < ActionController::TestCase get :index, :profile => user.identifier assert_tag :tag => 'div', :descendant => { :tag => 'a', :content => 'Edit Header and Footer' } end + + should 'deactivate organization profile' do + @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status' + user = create_user('user').person + Environment.default.add_admin user + login_as('user') + + community = fast_create(Community) + get :index, :profile => community.identifier + get :deactivate_profile, {:profile => community.identifier, :id => community.id} + assert_equal @request.session[:notice], "The profile '#{community.name}' was disabled." + end + + should 'activate organization profile' do + @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status' + user = create_user('user').person + Environment.default.add_admin user + login_as('user') + + community = fast_create(Community) + get :index, :profile => community.identifier + get :activate_profile, {:profile => community.identifier, :id => community.id} + assert_equal @request.session[:notice], "The profile '#{community.name}' was activated." + end + + should 'not deactivate organization profile if user is not an admin' do + @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status' + user = create_user('user').person + login_as('user') + + community = fast_create(Community) + get :index, :profile => community.identifier + get :deactivate_profile, {:profile => community.identifier, :id => community.id} + assert_not_equal @request.session[:notice], "The profile '#{community.name}' was disabled." + end end -- libgit2 0.21.2