The cuke was broken due to changes in the members view. Writing and adapting cukes is a pain, hence I removed the cuke and replaced it by a feature spec using page objects.pull/3480/head
parent
4590784a4d
commit
8bbf5da2e4
@ -1,99 +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: Group memberships |
||||
Background: |
||||
Given there is 1 project with the following: |
||||
| name | project1 | |
||||
| identifier | project1 | |
||||
And there is 1 user with the following: |
||||
| login | bob | |
||||
| firstname | Bob | |
||||
| Lastname | Bobbit | |
||||
And there is 1 user with the following: |
||||
| login | alice | |
||||
| firstname | Alice | |
||||
| lastname | Wonderland | |
||||
And there is 1 group with the following: |
||||
| name | group1 | |
||||
And there is a role "alpha" |
||||
And there is a role "beta" |
||||
And the role "alpha" may have the following rights: |
||||
| manage_members | |
||||
And the user "bob" is a "alpha" in the project "project1" |
||||
|
||||
@javascript |
||||
Scenario: Adding a group with members to a project |
||||
Given the group "group1" has the following members: |
||||
| alice | |
||||
And I am already logged in as "bob" |
||||
When I go to the members tab of the settings page of the project "project1" |
||||
And I add the principal "group1" as a member with the roles: |
||||
| beta | |
||||
Then I should see the principal "group1" as a member with the roles: |
||||
| beta | |
||||
And I should see the principal "alice" as a member with the roles: |
||||
| beta | |
||||
|
||||
Scenario: Adding members to a group after the group has been added to the project adds the users to the project |
||||
Given the group "group1" is a "beta" in the project "project1" |
||||
And I am already admin |
||||
When I go to the edit page of the group called "group1" |
||||
And I follow "Users" within ".tabs" |
||||
And I add the user "alice" to the group |
||||
And I go to the members tab of the settings page of the project "project1" |
||||
Then I should see the principal "group1" as a member with the roles: |
||||
| beta | |
||||
And I should see the principal "alice" as a member with the roles: |
||||
| beta | |
||||
|
||||
@javascript |
||||
Scenario: Removing a group from a project removes its members (users) as well if they have no roles of their own |
||||
Given the group "group1" has the following members: |
||||
| alice | |
||||
And the group "group1" is a "beta" in the project "project1" |
||||
And I am already logged in as "bob" |
||||
When I go to the members tab of the settings page of the project "project1" |
||||
And I follow the delete link of the project member "group1" |
||||
Then I should not see the principal "group1" as a member |
||||
And I should not see the principal "alice" as a member |
||||
|
||||
@javascript |
||||
Scenario: Removing a group from a project leaves a member if he has other roles besides those inherited from the group |
||||
Given the group "group1" has the following members: |
||||
| alice | |
||||
And the user "alice" is a "alpha" in the project "project1" |
||||
And the group "group1" is a "beta" in the project "project1" |
||||
And I am already logged in as "bob" |
||||
When I go to the members tab of the settings page of the project "project1" |
||||
And I follow the delete link of the project member "group1" |
||||
Then I should not see the principal "group1" as a member |
||||
And I should see the principal "alice" as a member with the roles: |
||||
| alpha | |
||||
|
||||
|
@ -0,0 +1,126 @@ |
||||
#-- 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' |
||||
|
||||
feature 'group memberships', type: :feature, js: true do |
||||
let(:project) { FactoryGirl.create :project, name: 'Project 1', identifier: 'project1' } |
||||
|
||||
let(:admin) { FactoryGirl.create :admin } |
||||
let(:alice) { FactoryGirl.create :user, firstname: 'Alice', lastname: 'Wonderland' } |
||||
let(:bob) { FactoryGirl.create :user, firstname: 'Bob', lastname: 'Bobbit' } |
||||
let(:group) { FactoryGirl.create :group, lastname: 'group1' } |
||||
|
||||
let!(:alpha) { FactoryGirl.create :role, name: 'alpha', permissions: [:manage_members] } |
||||
let!(:beta) { FactoryGirl.create :role, name: 'beta' } |
||||
|
||||
let(:members_page) { Pages::Project::Members.new project.identifier } |
||||
let(:groups_page) { Pages::Groups.new } |
||||
|
||||
before do |
||||
FactoryGirl.create :member, user: bob, project: project, roles: [alpha] |
||||
end |
||||
|
||||
context 'given a group with members' do |
||||
before do |
||||
allow(User).to receive(:current).and_return bob |
||||
|
||||
group.add_member! alice |
||||
end |
||||
|
||||
scenario 'adding group1 as a member with the beta role' do |
||||
members_page.visit! |
||||
members_page.add_user! 'group1', as: 'beta' |
||||
|
||||
expect(members_page).to have_added_user 'group1' |
||||
expect(members_page).to have_user('Alice Wonderland', group_membership: true) |
||||
end |
||||
|
||||
context 'which has has been added to a project' do |
||||
before do |
||||
project.add_member! group, [beta] |
||||
end |
||||
|
||||
context 'with the members having no roles of their own' do |
||||
scenario 'removing the group removes its members too' do |
||||
members_page.visit! |
||||
expect(members_page).to have_user('Alice Wonderland') |
||||
|
||||
members_page.remove_user! 'group1' |
||||
expect(page).to have_text('Removed user from project') |
||||
|
||||
expect(members_page).not_to have_user('group1') |
||||
expect(members_page).not_to have_user('Alice Wonderland') |
||||
end |
||||
end |
||||
|
||||
context 'with the members having roles of their own' do |
||||
before do |
||||
project.members |
||||
.select { |m| m.user_id == alice.id } |
||||
.each { |m| m.add_and_save_role alpha } |
||||
end |
||||
|
||||
scenario 'removing the group leaves the user without their group roles' do |
||||
members_page.visit! |
||||
expect(members_page).to have_user('Alice Wonderland', roles: ['alpha', 'beta']) |
||||
|
||||
members_page.remove_user! 'group1' |
||||
expect(page).to have_text('Removed user from project') |
||||
|
||||
expect(members_page).not_to have_user('group1') |
||||
|
||||
expect(members_page).to have_user('Alice Wonderland', roles: ['alpha']) |
||||
expect(members_page).not_to have_roles('Alice Wonderland', ['beta']) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
context 'given an empty group in a project' do |
||||
before do |
||||
alice # create alice |
||||
project.add_member! group, [beta] |
||||
|
||||
allow(User).to receive(:current).and_return admin |
||||
end |
||||
|
||||
scenario 'adding members to that group adds them to the project too', js: false do |
||||
members_page.visit! |
||||
|
||||
expect(members_page).not_to have_user('Alice Wonderland') # Alice not in the project yet |
||||
expect(members_page).to have_user('group1') # the group is already there though |
||||
|
||||
groups_page.visit! |
||||
groups_page.add_user_to_group! 'Alice Wonderland', 'group1' |
||||
|
||||
members_page.visit! |
||||
expect(members_page).to have_user('Alice Wonderland', roles: ['beta']) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,44 @@ |
||||
#-- 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. |
||||
#++ |
||||
|
||||
module Pages |
||||
class Groups < Pages::Page |
||||
def path |
||||
'/admin/groups' |
||||
end |
||||
|
||||
def add_user_to_group!(user_name, group_name) |
||||
visit_page unless current_page? |
||||
|
||||
click_on group_name |
||||
click_on 'tab-users' |
||||
check user_name |
||||
click_on 'Add' |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,50 @@ |
||||
#-- 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. |
||||
#++ |
||||
|
||||
module Pages |
||||
class Page |
||||
include Capybara::DSL |
||||
include RSpec::Matchers |
||||
|
||||
def current_page? |
||||
URI.parse(current_url).path == path |
||||
end |
||||
|
||||
def visit! |
||||
raise 'No path defined' unless path |
||||
|
||||
visit path |
||||
|
||||
self |
||||
end |
||||
|
||||
def path |
||||
nil |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,99 @@ |
||||
#-- 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. |
||||
#++ |
||||
|
||||
module Pages |
||||
module Project |
||||
class Members < Pages::Page |
||||
include Capybara::Select2 |
||||
|
||||
attr_reader :project_identifier |
||||
|
||||
def initialize(project_identifier) |
||||
@project_identifier = project_identifier |
||||
end |
||||
|
||||
def path |
||||
"/projects/#{project_identifier}/members" |
||||
end |
||||
|
||||
## |
||||
# Adds the given user to this project. |
||||
# |
||||
# @param user_name [String] The full name of the user. |
||||
# @param as [String] The role as which the user should be added. |
||||
def add_user!(user_name, as:) |
||||
click_on 'Add Member' |
||||
|
||||
select2(user_name, css: '#s2id_member_user_ids') |
||||
select2(as, css: '#s2id_member_role_ids') |
||||
|
||||
click_on 'Add' |
||||
end |
||||
|
||||
def remove_user!(user_name) |
||||
find_user(user_name).find('a[title=Delete]').click |
||||
end |
||||
|
||||
def has_added_user?(name) |
||||
has_text? "Added #{name} to the project" and |
||||
has_css? 'tr', text: name |
||||
end |
||||
|
||||
## |
||||
# Checks if the members page lists the given user. |
||||
# |
||||
# @param name [String] The full name of the user. |
||||
# @param roles [Array] Checks if the user has the given role. |
||||
# @param group_membership [Boolean] True if the member is added through a group. |
||||
# Such members cannot be removed separately which |
||||
# is why there must be only an edit and no delete button. |
||||
def has_user?(name, roles: nil, group_membership: nil) |
||||
has_selector?('tr', text: name) && |
||||
(roles.nil? || has_roles?(name, roles)) && |
||||
(group_membership.nil? || group_membership == has_group_membership?(name)) |
||||
end |
||||
|
||||
def find_user(name) |
||||
find('tr', text: name) |
||||
end |
||||
|
||||
def has_group_membership?(user_name) |
||||
user = find_user(user_name) |
||||
|
||||
user.has_selector?('a[title=Edit]') && |
||||
user.has_no_selector?('a[title=Delete]') |
||||
end |
||||
|
||||
def has_roles?(user_name, roles) |
||||
user = find_user(user_name) |
||||
|
||||
roles.all? { |role| user.has_text? role } |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue