Add better factory for team planner

pull/10320/head
Oliver Günther 3 years ago
parent 6567682d96
commit 1c31ec84ad
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 16
      modules/team_planner/spec/features/onboarding/team_planner_onboarding_tour_spec.rb
  2. 4
      spec/factories/view_factory.rb
  3. 53
      spec/factories/view_team_planner_factory.rb

@ -31,7 +31,6 @@ require_relative './../../support/onboarding/onboarding_steps'
describe 'team planner onboarding tour', js: true do describe 'team planner onboarding tour', js: true do
let(:next_button) { find('.enjoyhint_next_btn') } let(:next_button) { find('.enjoyhint_next_btn') }
let(:user) { create :admin }
let(:demo_project) do let(:demo_project) do
create :project, create :project,
@ -47,6 +46,14 @@ describe 'team planner onboarding tour', js: true do
public: true, public: true,
enabled_module_names: %w[work_package_tracking wiki] enabled_module_names: %w[work_package_tracking wiki]
end end
let(:user) do
create :admin,
member_in_project: demo_project,
member_with_permissions: %w[view_work_packages edit_work_packages add_work_packages
view_team_planner manage_team_planner save_queries manage_public_queries work_package_assigned]
end
let!(:wp_1) do let!(:wp_1) do
create(:work_package, create(:work_package,
project: demo_project, project: demo_project,
@ -57,7 +64,12 @@ describe 'team planner onboarding tour', js: true do
let!(:wp_2) { create(:work_package, project: scrum_project) } let!(:wp_2) { create(:work_package, project: scrum_project) }
let(:query) { create :query, user: user, project: demo_project, public: true, name: 'Team planner' } let(:query) { create :query, user: user, project: demo_project, public: true, name: 'Team planner' }
let(:team_plan) { create :view_team_planner, query: query } let(:team_plan) do
create :view_team_planner,
query: query,
assignees: [user],
projects: [demo_project, scrum_project]
end
before do before do
team_plan team_plan

@ -34,10 +34,6 @@ FactoryBot.define do
factory :view_work_packages_table, parent: :view factory :view_work_packages_table, parent: :view
factory :view_team_planner, parent: :view do
type { 'team_planner' }
end
factory :view_work_packages_calendar, parent: :view do factory :view_work_packages_calendar, parent: :view do
type { 'work_packages_calendar' } type { 'work_packages_calendar' }
end end

@ -0,0 +1,53 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2022 the OpenProject GmbH
#
# 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 COPYRIGHT and LICENSE files for more details.
#++
FactoryBot.define do
factory :view_team_planner, parent: :view do
type { 'team_planner' }
transient do
assignees { [] }
projects { [] }
end
callback(:after_create) do |view, evaluator|
query = view.query
if evaluator.assignees.any?
query.add_filter('assigned_to_id', '=', evaluator.assignees.map(&:id).uniq)
end
if evaluator.projects.any?
query.add_filter('project_id', '=', ([query.project.id] + evaluator.projects.map(&:id)).uniq)
end
User.system.run_given do
query.save!
end
end
end
end
Loading…
Cancel
Save