From 0196431d6a0d60ff6464ed523e88910252df7479 Mon Sep 17 00:00:00 2001 From: Peter Lehwess Date: Thu, 24 Sep 2015 16:39:59 +0200 Subject: [PATCH] Port users/deleting.feature cukes to rspec feature specs --- features/users/deleting.feature | 82 ---------------------- spec/features/users/delete_spec.rb | 107 +++++++++++++++++++++++++++++ spec/spec_helper.rb | 5 ++ 3 files changed, 112 insertions(+), 82 deletions(-) delete mode 100644 features/users/deleting.feature create mode 100644 spec/features/users/delete_spec.rb diff --git a/features/users/deleting.feature b/features/users/deleting.feature deleted file mode 100644 index dd4e0bbc03..0000000000 --- a/features/users/deleting.feature +++ /dev/null @@ -1,82 +0,0 @@ -#-- copyright -# OpenProject is a project management system. -# Copyright (C) 2012-2015 the OpenProject Foundation (OPF) -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License version 3. -# -# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: -# Copyright (C) 2006-2013 Jean-Philippe Lang -# Copyright (C) 2010-2013 the ChiliProject Team -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# See doc/COPYRIGHT.rdoc for more details. -#++ - -Feature: User deletion - - @javascript - Scenario: A user can delete himself if the setting permits it - Given the "users_deletable_by_self" setting is set to true - And there is 1 user with the following: - | login | bob | - And I am already logged in as "bob" - And I go to the my account page - And I follow "Delete account" - And I press "Delete" - And I accept the alert dialog - Then I should see "Account successfully deleted" - And I should be on the login page - - Scenario: A user can not delete himself if the setting forbids it - Given the "users_deletable_by_self" setting is set to false - And there is 1 user with the following: - | login | bob | - And I am already logged in as "bob" - And I go to the my account page - Then I should not see "Delete account" within "#main-menu" - - @javascript - Scenario: An admin can delete other users if the setting permitts it - Given the "users_deletable_by_admins" setting is set to true - And there is 1 user with the following: - | login | bob | - And I am already admin - When I go to the edit page of the user "bob" - And I click "Delete" - And I press "Delete" - And I accept the alert dialog - Then I should see "Account successfully deleted" - And I should be on the index page of users - - Scenario: An admin can not delete other users if the setting forbidds it - Given the "users_deletable_by_admins" setting is set to false - And there is 1 user with the following: - | login | bob | - And I am already admin - And I go to the edit page of the user "bob" - Then I should not see "Delete" within ".toolbar" - - Scenario: Deletablilty settings can be set in the users tab of the settings - Given I am already admin - And the "users_deletable_by_admins" setting is set to false - And the "users_deletable_by_self" setting is set to false - And I go to the users tab of the settings page - And I check "settings_users_deletable_by_admins" - And I check "settings_users_deletable_by_self" - And I press "Save" within "#tab-content-users" - Then the "users_deletable_by_admins" setting should be true - Then the "users_deletable_by_self" setting should be true diff --git a/spec/features/users/delete_spec.rb b/spec/features/users/delete_spec.rb new file mode 100644 index 0000000000..ab5783f2e9 --- /dev/null +++ b/spec/features/users/delete_spec.rb @@ -0,0 +1,107 @@ +#-- copyright +# OpenProject is a project management system. +# Copyright (C) 2012-2015 the OpenProject Foundation (OPF) +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License version 3. +# +# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +# Copyright (C) 2006-2013 Jean-Philippe Lang +# Copyright (C) 2010-2013 the ChiliProject Team +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# See doc/COPYRIGHT.rdoc for more details. +#++ + +require 'spec_helper' +require 'features/projects/projects_page' + +describe 'user deletion: ', type: :feature, js: true do + before do + page.set_rack_session(user_id: current_user.id) + end + + context 'regular user' do + let(:current_user) { FactoryGirl.create :user } + + it 'can delete their own account' do + Setting.users_deletable_by_self = 1 + visit delete_my_account_info_path + + fill_in 'login_verification', with: current_user.login + click_on 'Delete' + + page.driver.browser.switch_to.alert.accept + + expect(page).to have_content 'Account successfully deleted' + expect(current_path).to eq '/login' + end + + it 'cannot delete their own account if the settings forbid it' do + Setting.users_deletable_by_self = 0 + visit my_account_path + + within '#main-menu' do + expect(page).to_not have_content 'Delete account' + end + end + end + + context 'admin user' do + let!(:user) { FactoryGirl.create :user } + let(:current_user) { FactoryGirl.create :admin } + + it 'can delete other users if the setting permitts it' do + Setting.users_deletable_by_admins = 1 + visit edit_user_path(user) + + expect(page).to have_content "#{user.firstname} #{user.lastname}" + + click_on 'Delete' + fill_in 'login_verification', with: user.login + click_on 'Delete' + + page.driver.browser.switch_to.alert.accept + + expect(page).to have_content 'Account successfully deleted' + expect(current_path).to eq '/users' + end + + it 'cannot delete other users if the settings forbid it' do + Setting.users_deletable_by_admins = 0 + visit edit_user_path(user) + + expect(page).to_not have_content 'Delete account' + end + + it 'can change the deletablilty settings' do + Setting.users_deletable_by_admins = 0 + Setting.users_deletable_by_self = 0 + + visit settings_path(tab: 'users') + + find(:css, "#settings_users_deletable_by_admins").set(true) + find(:css, "#settings_users_deletable_by_self").set(true) + + within '#tab-content-users' do + click_on 'Save' + end + + expect(Setting.users_deletable_by_admins?).to eq true + expect(Setting.users_deletable_by_self?).to eq true + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ac36aa5351..6176c71f23 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -167,6 +167,11 @@ Rails.application.config.plugins_to_test_paths.each do |dir| end end +require 'rack_session_access/capybara' +Rails.application.config do + config.middleware.use RackSessionAccess::Middleware +end + module OpenProject::RspecCleanup def self.cleanup # Cleanup after specs changing locale explicitly or